当前位置: 首页>>代码示例>>Python>>正文


Python construct.Container方法代码示例

本文整理汇总了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) 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:19,代码来源:paradox.py

示例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 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:18,代码来源:panel.py

示例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') 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:27,代码来源:panel.py

示例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)) 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:22,代码来源:async_message_manager.py

示例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 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:26,代码来源:test_async_message_manager.py

示例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 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:24,代码来源:test_async_message_manager.py

示例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'
        ) 
开发者ID:beardypig,项目名称:pymp4,代码行数:23,代码来源:test_box.py

示例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 
开发者ID:randovania,项目名称:randovania,代码行数:20,代码来源:binary_data.py

示例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]) 
开发者ID:5g-empower,项目名称:empower-runtime,代码行数:19,代码来源:vbspconnection.py

示例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) 
开发者ID:5g-empower,项目名称:empower-runtime,代码行数:22,代码来源:wifichannelqualitymap.py

示例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) 
开发者ID:5g-empower,项目名称:empower-runtime,代码行数:18,代码来源:wifichannelstats.py

示例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) 
开发者ID:5g-empower,项目名称:empower-runtime,代码行数:26,代码来源:uemeasurements.py

示例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") 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:4,代码来源:panel.py

示例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 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:12,代码来源:panel.py

示例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 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:30,代码来源:panel.py


注:本文中的construct.Container方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。