本文整理匯總了Python中construct.Container方法的典型用法代碼示例。如果您正苦於以下問題:Python construct.Container方法的具體用法?Python construct.Container怎麽用?Python construct.Container使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類construct
的用法示例。
在下文中一共展示了construct.Container方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _process_status
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def _process_status(raw_status: Container) -> None:
status = convert_raw_status(raw_status)
for limit_key, limit_arr in cfg.LIMITS.items():
if limit_key not in status:
continue
status[limit_key].filter(limit_arr)
# # TODO: throttle power update messages
# if time.time() - self.last_power_update >= cfg.POWER_UPDATE_INTERVAL:
# force = PublishPropertyChange.YES if cfg.PUSH_POWER_UPDATE_WITHOUT_CHANGE else PublishPropertyChange.NO
if cfg.LOGGING_DUMP_STATUS:
logger.debug("properties: %s", status)
ps.sendMessage('status_update', status=status)
示例2: parse_message
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def parse_message(self, message, direction='topanel') -> typing.Optional[Container]:
if message is None or len(message) == 0:
return None
if direction == 'topanel':
if message[0] == 0x72 and message[1] == 0:
return parsers.InitiateCommunication.parse(message)
elif message[0] == 0x5F:
return parsers.StartCommunication.parse(message)
else:
if message[0] == 0x72 and message[1] == 0xFF:
return parsers.InitiateCommunicationResponse.parse(message)
elif message[0] == 0x00 and message[4] > 0:
return parsers.StartCommunicationResponse.parse(message)
else:
return None
示例3: initialize_communication
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def initialize_communication(self, reply: Container, password):
encoded_password = self.encode_password(password)
args = dict(product_id=reply.fields.value.product_id,
firmware=reply.fields.value.firmware,
panel_id=reply.fields.value.panel_id,
pc_password=encoded_password,
user_code=0x000000,
_not_used1=0x19,
source_id=0x02
)
logger.info("Initializing communication")
reply = await self.core.send_wait(parsers.InitializeCommunication, args=args, reply_expected=[0x10, 0x70, 0x00])
if reply is None:
logger.error("Initialization Failed")
return False
if reply.fields.value.po.command == 0x10:
logger.info("Authentication Success")
return True
elif reply.fields.value.po.command == 0x70 or reply.fields.value.po.command == 0x00:
logger.error("Authentication Failed. Wrong Password?")
raise AuthenticationFailed('Wrong PASSWORD')
示例4: _handle_message
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def _handle_message(self, message: Container):
handler = None
self.handlers = self._cleanup_handlers(self.handlers)
for h in self.handlers:
try:
if h.can_handle(message):
handler = h
break
except Exception as e:
logger.exception("Exception caught during message handling")
if handler:
if not handler.persistent:
self.handlers = list(filter(lambda x: x != handler, self.handlers))
return await self._handle(handler, message)
else:
logger.error("No handler for message {}\nDetail: {}".format(message.fields.value.po.command, message))
示例5: test_persistent_raw_handler
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def test_persistent_raw_handler(mocker):
cb = mocker.MagicMock()
msg1 = Container()
msg2 = Container()
handler = RAWMessageHandler(cb)
mm = AsyncMessageManager()
mm.register_handler(handler)
assert len(mm.raw_handlers) == 1
task1 = mm.schedule_raw_message_handling(msg1)
await task1
task2 = mm.schedule_raw_message_handling(msg2)
await task2
assert task1.done()
assert task2.done()
assert cb.call_count == 2
cb.assert_has_calls([mocker.call(msg1), mocker.call(msg2)])
assert len(mm.raw_handlers) == 1
示例6: test_handler_exception
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def test_handler_exception(mocker):
loop = asyncio.get_event_loop()
msg = Container(
fields=Container(
value=Container(
po=Container(
command=0xe
),
event_source=0xff
)
)
)
mm = AsyncMessageManager()
eh = EventMessageHandler(callback=mocker.MagicMock(side_effect=Exception('screw it')))
mm.register_handler(eh)
with pytest.raises(Exception):
await mm.schedule_message_handling(msg)
assert len(mm.raw_handlers) == 0
assert len(mm.handlers) == 1
示例7: test_moov_build
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def test_moov_build(self):
moov = \
Container(type=b"moov")(children=[ # 96 bytes
Container(type=b"mvex")(children=[ # 88 bytes
Container(type=b"mehd")(version=0)(flags=0)(fragment_duration=0), # 16 bytes
Container(type=b"trex")(track_ID=1), # 32 bytes
Container(type=b"trex")(track_ID=2), # 32 bytes
])
])
moov_data = Box.build(moov)
self.assertEqual(len(moov_data), 96)
self.assertEqual(
moov_data,
b'\x00\x00\x00\x60moov'
b'\x00\x00\x00\x58mvex'
b'\x00\x00\x00\x10mehd\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x20trex\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x00\x20trex\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
)
示例8: _convert_to_raw_python
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def _convert_to_raw_python(value) -> Any:
if isinstance(value, construct.ListContainer):
return [
_convert_to_raw_python(item)
for item in value
]
if isinstance(value, construct.Container):
return {
key: _convert_to_raw_python(item)
for key, item in value.items()
if not key.startswith("_")
}
if isinstance(value, construct.EnumIntegerString):
return str(value)
return value
示例9: send_hello_response
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def send_hello_response(self, period):
"""Send an HELLO response message."""
hello_tlv = Container()
hello_tlv.period = period
value = HELLO_SERVICE_PERIOD.build(hello_tlv)
tlv = Container()
tlv.type = PT_HELLO_SERVICE_PERIOD
tlv.length = 4 + len(value)
tlv.value = value
return self.send_message(action=self.proto.PT_HELLO_SERVICE,
msg_type=self.proto.MSG_TYPE_RESPONSE,
crud_result=self.proto.RESULT_SUCCESS,
tlvs=[tlv])
示例10: loop
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def loop(self):
"""Send out requests"""
for wtp in self.wtps.values():
if not wtp.connection:
continue
for block in wtp.blocks.values():
msg = Container(length=CQM_REQUEST.sizeof(),
iface_id=block.block_id)
wtp.connection.send_message(PT_UCQM_REQUEST,
msg,
self.handle_ucqm_response)
wtp.connection.send_message(PT_NCQM_REQUEST,
msg,
self.handle_ncqm_response)
示例11: loop
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def loop(self):
"""Send out requests"""
for wtp in self.wtps.values():
if not wtp.connection:
continue
for block in wtp.blocks.values():
msg = Container(length=WCS_REQUEST.sizeof(),
iface_id=block.block_id)
wtp.connection.send_message(PT_WCS_REQUEST,
msg,
self.handle_response)
示例12: handle_ue_join
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def handle_ue_join(self, user):
"""Called when a UE joins the network."""
interval = RRCReportInterval[self.interval].value
amount = RRCReportAmount[self.amount].value
rrc_measurement_tlv = \
Container(rnti=user.rnti,
meas_id=self.meas_id,
interval=interval,
amount=amount)
value = UE_MEASUREMENTS_SERVICE_CONFIG.build(rrc_measurement_tlv)
tlv = Container()
tlv.type = TLV_MEASUREMENTS_SERVICE_CONFIG
tlv.length = 4 + len(value)
tlv.value = value
user.vbs.connection.send_message(action=PT_UE_MEASUREMENTS_SERVICE,
msg_type=vbsp.MSG_TYPE_REQUEST,
crud_result=vbsp.OP_CREATE,
tlvs=[tlv],
callback=self.handle_add_response)
示例13: request_status
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def request_status(self, nr) -> typing.Optional[Container]:
raise NotImplementedError("override request_status in a subclass")
示例14: _request_status_reply_check
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def _request_status_reply_check(message: Container, address: int):
mvars = message.fields.value
if (
mvars.po.command == 0x05
and mvars.address == address
):
return True
return False
示例15: initialize_communication
# 需要導入模塊: import construct [as 別名]
# 或者: from construct import Container [as 別名]
def initialize_communication(self, reply: Container, password) -> bool:
encoded_password = self.encode_password(password)
raw_data = reply.fields.data + reply.checksum
parsed = parsers.InitializeCommunication.parse(raw_data)
parsed.fields.value.pc_password = encoded_password
payload = parsers.InitializeCommunication.build(
dict(fields=dict(value=parsed.fields.value)))
logger.info("Initializing communication")
reply = await self.core.send_wait(message=payload, reply_expected=[0x1, 0x0])
if reply is None:
logger.error("Initialization Failed")
return False
if reply.fields.value.po.command == 0x0:
logger.error("Authentication Failed. Wrong PASSWORD. Make sure you use correct PC Password. In Babyware: "
"Right click on your panel -> Properties -> PC Communication (Babyware) -> PC Communication "
"(Babyware) Tab.")
raise AuthenticationFailed('Wrong PASSWORD')
else: # command == 0x1
if reply.fields.value.po.status.Winload_connected:
logger.info("Authentication Success")
return True
else:
logger.error("Authentication Failed")
return False