Best Python code snippet using playwright-python
core.py
Source:core.py
...343 protocol.send_data(tunnel_request.get_message(), target)344 queue.task_done()345 continue346 dev_desc = struct.unpack('!H', descriptor)[0]347 desc_medium, desc_type, desc_version = knxmap.utils.parse_device_descriptor(dev_desc)348 device_state = None349 if desc_type > 1:350 # Read System 2 and System 7 manufacturer ID object351 manufacturer = yield from protocol.apci_property_value_read(352 target,353 property_id=DEVICE_OBJECTS.get('PID_MANUFACTURER_ID'))354 if isinstance(manufacturer, (str, bytes, bytearray)):355 manufacturer = int.from_bytes(manufacturer, 'big')356 manufacturer = knxmap.utils.get_manufacturer_by_id(manufacturer)357 # Read the device state358 device_state_data = yield from protocol.apci_memory_read(359 target,360 memory_address=0x0060)361 if device_state_data:...
tunnel.py
Source:tunnel.py
...415 try:416 dev_desc = struct.unpack('!H', descriptor)[0]417 except (struct.error, TypeError):418 return False419 _, desc_type, _ = KnxMessage.parse_device_descriptor(dev_desc)420 return desc_type421 async def apci_device_descriptor_read(self, target):422 tunnel_request = self.make_tunnel_request(target)423 tunnel_request.apci_device_descriptor_read(424 sequence=self.tpci_seq_counts.get(target))425 LOGGER.trace_outgoing(tunnel_request)426 value = await self.send_data(tunnel_request.get_message(), target)427 await self.tpci_send_ncd(target)428 if isinstance(value, KnxTunnellingRequest):429 cemi = value.cemi430 if cemi.apci.apci_type == CEMI_APCI_TYPES.get('A_DeviceDescriptor_Response') and \431 cemi.data:432 return value.cemi.data433 else:...
eeprom.py
Source:eeprom.py
...145 # configuration count146 device_bytes += b'\x01'147 assert len(device_bytes) == 16148 return struct.pack('<BB', 2 + len(device_bytes), 1) + device_bytes149def parse_device_descriptor(data):150 if len(data) == 0:151 return []152 assert data[0] == 18153 assert data[1] == 1154 return [155 ('usb_version', struct.unpack_from('<H', data, 2)[0], lambda value: '{0}.{1:02}'.format(value >> 8, value & 0xFF)),156 ('class_code', data[4], str),157 ('subclass_code', data[5], str),158 ('protocol_code', data[6], str),159 ('max_packet_size', data[7], str),160 ('vendor_id', struct.unpack_from('<H', data, 8)[0], '0x{0:04X}'.format),161 ('product_id', struct.unpack_from('<H', data, 10)[0], '0x{0:04X}'.format),162 ('device_release', struct.unpack_from('<H', data, 12)[0], lambda value: '{0}.{1:02}'.format(value >> 8, value & 0xFF)),163 ('manufacturer_index', data[14], str),164 ('product_name_index', data[15], str),165 ('serial_number_index', data[16], str),166 ('configuration_count', data[17], str)167 ]168def parse_config_and_iface_descriptor(data):169 if len(data) == 0:170 return []171 assert data[0] == 9172 assert data[1] == 2173 result = [174 ('total_length', struct.unpack_from('<H', data, 2)[0], str),175 ('interface_count', data[4], str),176 ('configuration_value', data[5], str),177 ('description_index', data[6], str),178 ('attributes', data[7], '0b{0:08b}'.format),179 ('max_power', data[8], lambda value: '{0} mA'.format(value * 2)),180 ]181 offset = 9182 interface_index = 0183 while offset < len(data):184 assert data[offset] == 9185 assert data[offset + 1] == 4186 result.append(('interface_{0}_number'.format(interface_index), data[offset + 2], str))187 result.append(('interface_{0}_alternate_setting'.format(interface_index), data[offset + 3], str))188 result.append(('interface_{0}_endpoint_count'.format(interface_index), data[offset + 4], str))189 result.append(('interface_{0}_class_code'.format(interface_index), data[offset + 5], str))190 result.append(('interface_{0}_subclass_code'.format(interface_index), data[offset + 6], str))191 result.append(('interface_{0}_protocol_code'.format(interface_index), data[offset + 7], str))192 result.append(('interface_{0}_description_index'.format(interface_index), data[offset + 8], str))193 offset += 9194 interface_index += 1195 return result196def format_eth_config(mac_address):197 manufacturer_bytes = format_string_descriptor('Tinkerforge')198 product_name_bytes = format_string_descriptor('LAN7500')199 serial_number_bytes = format_string_descriptor('{0:02X}{1:02X}{2:02X}{3:02X}{4:02X}{5:02X}'.format(*mac_address))200 device_descriptor_bytes = format_device_descriptor()201 # programmed indicator202 config_bytes = b'\xA5'203 # MAC address204 config_bytes += bytes(mac_address)205 # full-speed polling interval for interrupt endpoint206 config_bytes += b'\x01' # 1 ms207 # hi-speed polling interval for interrupt endpoint208 config_bytes += b'\x04' # 4 ms209 # configuration flags 0210 # - no port swap211 # - no PHY boost212 # - automatic duplex detection213 # - automatic speed detection214 # - LED0 and LED1 are used as link/speed/activity LEDs215 # - remote wakeup216 # - self-powered217 config_bytes += b'\x1F' # 0b00011111218 # language ID descriptor219 config_bytes += struct.pack('<H', 0x0409) # English220 # manufacturer string descriptor length (bytes)221 config_bytes += struct.pack('<B', len(manufacturer_bytes))222 # manufacturer string descriptor offset (words)223 config_bytes += struct.pack('<B', 0x22 // 2)224 # product name string descriptor length (bytes)225 config_bytes += struct.pack('<B', len(product_name_bytes))226 # product name string descriptor offset (words)227 config_bytes += struct.pack('<B', (0x22 + len(manufacturer_bytes)) // 2)228 # serial number string descriptor length (bytes)229 config_bytes += struct.pack('<B', len(serial_number_bytes))230 # serial number string descriptor offset (words)231 config_bytes += struct.pack('<B', (0x22 + len(manufacturer_bytes) + len(product_name_bytes)) // 2)232 # configuration string descriptor length (bytes)233 config_bytes += b'\x00'234 # configuration string descriptor offset (words)235 config_bytes += b'\x00'236 # interface string descriptor length (bytes)237 config_bytes += b'\x00'238 # interface string descriptor offset (words)239 config_bytes += b'\x00'240 # hi-speed device descriptor length (bytes)241 config_bytes += struct.pack('<B', len(device_descriptor_bytes))242 # hi-speed device descriptor offset (words)243 config_bytes += struct.pack('<B', (0x22 + len(manufacturer_bytes) + len(product_name_bytes) + len(serial_number_bytes)) // 2)244 # hi-speed configuration and interface descriptor length (bytes)245 config_bytes += b'\x00'246 # hi-speed configuration and interface descriptor offset (words)247 config_bytes += b'\x00'248 # full-speed device descriptor length (bytes)249 config_bytes += struct.pack('<B', len(device_descriptor_bytes))250 # full-speed device descriptor offset (words)251 config_bytes += struct.pack('<B', (0x22 + len(manufacturer_bytes) + len(product_name_bytes) + len(serial_number_bytes)) // 2)252 # full-speed configuration and interface descriptor length (bytes)253 config_bytes += b'\x00'254 # full-speed configuration and interface descriptor offset (words)255 config_bytes += b'\x00'256 # GPIO wakeup enables257 config_bytes += b'\x00\x00'258 # GPIO PME flags259 # - GPIO PME disable260 # - GPIO PME signal via level261 # - GPIO PME pulse length is 1.5 ms262 # - GPIO PME signaling polarity is low263 # - GPIO PME open drain driver264 # - WOL event wakeup supported265 # - Magic Packet event wakeup disabled266 # - Perfect DA event wakeup disabled267 config_bytes += b'\x00' # 0b00000000268 # configuration flags 1269 # - LED2 is used as activity LED270 # - GPIO2 and GPIO3 are used for LEDs271 # - SW_MODE is just asserted for SUSPEND2272 # - SW_MODE is active-low273 config_bytes += b'\xB0' # 0b10110000274 assert len(config_bytes) == 0x22, len(config_bytes)275 config_bytes += manufacturer_bytes276 config_bytes += product_name_bytes277 config_bytes += serial_number_bytes278 config_bytes += device_descriptor_bytes279 assert len(config_bytes) <= ETH_CONFIG_LENGTH, len(config_bytes)280 return config_bytes + b'\x00' * (ETH_CONFIG_LENGTH - len(config_bytes))281def parse_eth_config(config_bytes):282 def get_descriptor(offset, length):283 return config_bytes[offset * 2:offset * 2 + length]284 # programmed indicator285 programmed_indicator = config_bytes[0x00]286 if programmed_indicator != 0xA5:287 print('EEPROM is not programmed')288 return289 print('programmed_indicator: 0x{0:02X}'.format(programmed_indicator))290 # MAC address291 mac_address = config_bytes[0x01:0x07]292 print('mac_address: {0:02X}:{1:02X}:{2:02X}:{3:02X}:{4:02X}:{5:02X}'.format(*mac_address))293 # full-speed polling interval for interrupt endpoint294 full_speed_polling_interval = config_bytes[0x07]295 print('full_speed_polling_interval: {0} ms'.format(full_speed_polling_interval))296 # hi-speed polling interval for interrupt endpoint297 hi_speed_polling_interval = config_bytes[0x08]298 print('hi_speed_polling_interval: {0} ms'.format(hi_speed_polling_interval))299 # configuration flags 0300 configuration_flags_0 = config_bytes[0x09]301 print('configuration_flags_0: 0b{0:08b}'.format(configuration_flags_0))302 print(' port_swap: 0b{0:b}'.format((configuration_flags_0 >> 7) & 0b1))303 print(' pyh_boost: 0b{0:02b}'.format((configuration_flags_0 >> 5) & 0b11))304 print(' duplex_detection: 0b{0:b}'.format((configuration_flags_0 >> 4) & 0b1))305 print(' speed_detection: 0b{0:b}'.format((configuration_flags_0 >> 3) & 0b1))306 print(' speed_led_function: 0b{0:b}'.format((configuration_flags_0 >> 2) & 0b1))307 print(' remote_wakeup_support: 0b{0:b}'.format((configuration_flags_0 >> 1) & 0b1))308 print(' power_method: 0b{0:b}'.format(configuration_flags_0 & 0b1))309 # language ID descriptor310 language_id_descriptor = struct.unpack('<H', config_bytes[0x0A:0x0C])[0]311 print('language_id_descriptor: 0x{0:04X}'.format(language_id_descriptor))312 # manufacturer string descriptor length (bytes)313 manufacturer_string_descriptor_length = config_bytes[0x0C]314 print('manufacturer_string_descriptor_length: 0x{0:04X}'315 .format(manufacturer_string_descriptor_length))316 # manufacturer string descriptor offset (words)317 manufacturer_string_descriptor_offset = config_bytes[0x0D]318 print('manufacturer_string_descriptor_offset: 0x{0:04X} (0x{1:04X})'319 .format(manufacturer_string_descriptor_offset, manufacturer_string_descriptor_offset * 2))320 # manufacturer string descriptor321 manufacturer_string_descriptor = get_descriptor(manufacturer_string_descriptor_offset, manufacturer_string_descriptor_length)322 print('manufacturer_string_descriptor: {0}'.format(manufacturer_string_descriptor))323 for name, value in parse_string_descriptor(manufacturer_string_descriptor):324 print(' {0:45}{1}'.format(name + ':', value))325 # product name string descriptor length (bytes)326 product_name_string_descriptor_length = config_bytes[0x0E]327 print('product_name_string_descriptor_length: 0x{0:04X}'328 .format(product_name_string_descriptor_length))329 # product name string descriptor offset (words)330 product_name_string_descriptor_offset = config_bytes[0x0F]331 print('product_name_string_descriptor_offset: 0x{0:04X} (0x{1:04X})'332 .format(product_name_string_descriptor_offset, product_name_string_descriptor_offset * 2))333 # product name string descriptor334 product_name_string_descriptor = get_descriptor(product_name_string_descriptor_offset, product_name_string_descriptor_length)335 print('product_name_string_descriptor: {0}'.format(product_name_string_descriptor))336 for name, value in parse_string_descriptor(product_name_string_descriptor):337 print(' {0:45}{1}'.format(name + ':', value))338 # serial number string descriptor length (bytes)339 serial_number_string_descriptor_length = config_bytes[0x10]340 print('serial_number_string_descriptor_length: 0x{0:04X}'341 .format(serial_number_string_descriptor_length))342 # serial number string descriptor offset (words)343 serial_number_string_descriptor_offset = config_bytes[0x11]344 print('serial_number_string_descriptor_offset: 0x{0:04X} (0x{1:04X})'345 .format(serial_number_string_descriptor_offset, serial_number_string_descriptor_offset * 2))346 # serial number string descriptor347 serial_number_string_descriptor = get_descriptor(serial_number_string_descriptor_offset, serial_number_string_descriptor_length)348 print('serial_number_string_descriptor: {0}'.format(serial_number_string_descriptor))349 for name, value in parse_string_descriptor(serial_number_string_descriptor):350 print(' {0:45}{1}'.format(name + ':', value))351 # configuration string descriptor length (bytes)352 configuration_string_descriptor_length = config_bytes[0x12]353 print('configuration_string_descriptor_length: 0x{0:04X}'354 .format(configuration_string_descriptor_length))355 # configuration string descriptor offset (words)356 configuration_string_descriptor_offset = config_bytes[0x13]357 print('configuration_string_descriptor_offset: 0x{0:04X} (0x{1:04X})'358 .format(configuration_string_descriptor_offset, configuration_string_descriptor_offset * 2))359 # configuration string descriptor360 configuration_string_descriptor = get_descriptor(configuration_string_descriptor_offset, configuration_string_descriptor_length)361 print('configuration_string_descriptor: {0}'.format(configuration_string_descriptor))362 for name, value in parse_string_descriptor(configuration_string_descriptor):363 print(' {0:45}{1}'.format(name + ':', value))364 # interface string descriptor length (bytes)365 interface_string_descriptor_length = config_bytes[0x14]366 print('interface_string_descriptor_length: 0x{0:04X}'367 .format(interface_string_descriptor_length))368 # interface string descriptor offset (words)369 interface_string_descriptor_offset = config_bytes[0x15]370 print('interface_string_descriptor_offset: 0x{0:04X} (0x{1:04X})'371 .format(interface_string_descriptor_offset, interface_string_descriptor_offset * 2))372 # interface string descriptor373 interface_string_descriptor = get_descriptor(interface_string_descriptor_offset, interface_string_descriptor_length)374 print('interface_string_descriptor: {0}'.format(interface_string_descriptor))375 for name, value in parse_string_descriptor(interface_string_descriptor):376 print(' {0:45}{1}'.format(name + ':', value))377 # hi-speed device descriptor length (bytes)378 hi_speed_device_descriptor_length = config_bytes[0x16]379 print('hi_speed_device_descriptor_length: 0x{0:04X}'380 .format(hi_speed_device_descriptor_length))381 # hi-speed device descriptor offset (words)382 hi_speed_device_descriptor_offset = config_bytes[0x17]383 print('hi_speed_device_descriptor_offset: 0x{0:04X} (0x{1:04X})'384 .format(hi_speed_device_descriptor_offset, hi_speed_device_descriptor_offset * 2))385 # hi-speed device descriptor386 hi_speed_device_descriptor = get_descriptor(hi_speed_device_descriptor_offset, hi_speed_device_descriptor_length)387 print('hi_speed_device_descriptor: {0}'.format(hi_speed_device_descriptor))388 for name, value, value_format in parse_device_descriptor(hi_speed_device_descriptor):389 print(' {0:45}{1}'.format(name + ':', value_format(value)))390 # hi-speed configuration and interface descriptor length (bytes)391 hi_speed_config_and_iface_descriptor_length = config_bytes[0x18]392 print('hi_speed_config_and_iface_descriptor_length: 0x{0:04X}'393 .format(hi_speed_config_and_iface_descriptor_length))394 # hi-speed configuration and interface descriptor offset (words)395 hi_speed_config_and_iface_descriptor_offset = config_bytes[0x19]396 print('hi_speed_config_and_iface_descriptor_offset: 0x{0:04X} (0x{1:04X})'397 .format(hi_speed_config_and_iface_descriptor_offset, hi_speed_config_and_iface_descriptor_offset * 2))398 # hi-speed configuration and interface descriptor399 hi_speed_config_and_iface_descriptor = get_descriptor(hi_speed_config_and_iface_descriptor_offset, hi_speed_config_and_iface_descriptor_length)400 print('hi_speed_config_and_iface_descriptor: {0}'.format(hi_speed_config_and_iface_descriptor))401 for name, value, value_format in parse_config_and_iface_descriptor(hi_speed_config_and_iface_descriptor):402 print(' {0:45}{1}'.format(name + ':', value_format(value)))403 # full-speed device descriptor length (bytes)404 full_speed_device_descriptor_length = config_bytes[0x1A]405 print('full_speed_device_descriptor_length: 0x{0:04X}'406 .format(full_speed_device_descriptor_length))407 # full-speed device descriptor offset (words)408 full_speed_device_descriptor_offset = config_bytes[0x1B]409 print('full_speed_device_descriptor_offset: 0x{0:04X} (0x{1:04X})'410 .format(full_speed_device_descriptor_offset, full_speed_device_descriptor_offset * 2))411 # full-speed device descriptor412 full_speed_device_descriptor = get_descriptor(full_speed_device_descriptor_offset, full_speed_device_descriptor_length)413 print('full_speed_device_descriptor: {0}'.format(full_speed_device_descriptor))414 for name, value, value_format in parse_device_descriptor(full_speed_device_descriptor):415 print(' {0:45}{1}'.format(name + ':', value_format(value)))416 # full-speed configuration and interface descriptor length (bytes)417 full_speed_config_and_iface_descriptor_length = config_bytes[0x1C]418 print('full_speed_config_and_iface_descriptor_length: 0x{0:04X}'419 .format(full_speed_config_and_iface_descriptor_length))420 # full-speed configuration and interface descriptor offset (words)421 full_speed_config_and_iface_descriptor_offset = config_bytes[0x1D]422 print('full_speed_config_and_iface_descriptor_offset: 0x{0:04X} (0x{1:04X})'423 .format(full_speed_config_and_iface_descriptor_offset, full_speed_config_and_iface_descriptor_offset * 2))424 # full-speed configuration and interface descriptor425 full_speed_config_and_iface_descriptor = get_descriptor(full_speed_config_and_iface_descriptor_offset, full_speed_config_and_iface_descriptor_length)426 print('full_speed_config_and_iface_descriptor: {0}'.format(full_speed_config_and_iface_descriptor))427 for name, value, value_format in parse_config_and_iface_descriptor(full_speed_config_and_iface_descriptor):428 print(' {0:45}{1}'.format(name + ':', value_format(value)))...
main.py
Source:main.py
...85 """86 assert isinstance(address, bytes), 'Address should be bytes'87 return '{0:02X}:{1:02X}:{2:02X}:{3:02X}:{4:02X}:{5:02X}'.format(*address)88 @staticmethod89 def parse_device_descriptor(desc):90 """Parse device descriptors to three separate integers.91 parse_device_descriptor(1793)92 (0, 112, 1)93 """94 assert isinstance(desc, int), 'Device descriptor is not an integer'95 desc = format(desc, '04x')96 medium = int(desc[0])97 dev_type = int(desc[1:-1], 16)98 version = int(desc[-1])99 return medium, dev_type, version100 def set_peer(self, peer):101 assert isinstance(peer, tuple), 'Peer is not a tuple'102 self.source, self.port = peer103 def set_source_ip(self, address):104 self.source = address105 def set_source_port(self, port):...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!