How to use the construct.Container function in construct

To help you get started, we’ve selected a few construct examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ParadoxAlarmInterface / pai / tests / lib / test_utils.py View on Github external
def test_deep_merge():
    cs = [Container(a="a"), Container(c="a", d="b"), Container(e="c")]

    result = deep_merge(*cs)
    assert dict(a="a", c="a", d="b", e="c") == result
github pmrowla / pylivemaker / livemaker / lsb / novel.py View on Github external
def __init__(
        self, decorator=0, unk3=None, link_name=None, link=None, var_name_params=None, var_name=None, **kwargs
    ):
        super().__init__(**kwargs)
        self._keys.update(("decorator", "unk3", "link_name", "link", "var_name_params", "var_name"))
        self.decorator = decorator
        self.unk3 = unk3
        self.link_name = link_name
        self.link = link
        if isinstance(var_name_params, construct.Container):
            var_name_params = LiveParser.from_struct(var_name_params)
        self.var_name_params = var_name_params
        self.var_name = var_name
github hughobrien / py-ble-hci / scripting.py View on Github external
def tx_container(channel=0, payload_len=10, test_pattern='psn9'):
        container = Container(
                pkt_type = 'command',
                cmd_opcode = 'tx_test',
                cmd_params = Container(
                        channel = channel,
                        payload_len = payload_len,
                        test_pattern = test_pattern,
                        ),
                )
        container.param_len = len(container.cmd_params)
        return container
github 5g-empower / empower-runtime / empower / apps / txpbincounter / txpbincounter.py View on Github external
def loop(self):
        """Send out requests"""

        if self.addr not in self.context.lvaps:
            return

        lvap = self.context.lvaps[self.addr]

        msg = Container(length=TXP_BIN_COUNTERS_REQUEST.sizeof(),
                        iface_id=self.iface_id,
                        addr=lvap.addr.to_raw())

        lvap.wtp.connection.send_message(PT_TXP_BIN_COUNTERS_REQUEST,
                                         msg,
                                         self.handle_response)
github Parrot-Developers / sequoia-ptpy / ptpy / ptp.py View on Github external
def get_object_info(self, handle):
        '''Get ObjectInfo dataset for given handle.'''
        ptp = Container(
            OperationCode='GetObjectInfo',
            SessionID=self._session,
            TransactionID=self._transaction,
            Parameter=[handle]
        )
        response = self.recv(ptp)
        return self._parse_if_data(response, self._ObjectInfo)
github Parrot-Developers / sequoia-ptpy / ptpy / extensions / canon / canon.py View on Github external
def eos_keep_device_on(self):
        '''Ping EOS camera so it stays ON'''
        ptp = Container(
            OperationCode='EOSKeepDeviceOn',
            SessionID=self._session,
            TransactionID=self._transaction,
            Parameter=[]
        )
        response = self.mesg(ptp)
        return response
github Parrot-Developers / sequoia-ptpy / ptpy / extensions / parrot.py View on Github external
            decoder=lambda obj, ctx: Container(
                Green=(obj[0], obj[4]),
                Red=(obj[1], obj[5]),
                RedEdge=(obj[2], obj[6]),
                NIR=(obj[3], obj[7]),
            ),
github saucelabs / isign / isign / makesig.py View on Github external
def make_requirements(drs):
    expr = make_expr(
        'And',
        ('Ident', 'ca.michaelhan.NativeIOSTestApp'),
        ('AppleGenericAnchor',),
        # TODO pull this from the X509 cert
        # http://stackoverflow.com/questions/14565597/pyopenssl-reading-certificate-pkey-file
        ('CertField', 'leafCert', 'subject.CN', ['matchEqual', 'iPhone Developer: Steven Hazel (DU2T223MY8)']),
        ('CertGeneric', 1, '*\x86H\x86\xf7cd\x06\x02\x01', ['matchExists']))
    des_req = construct.Container(kind=1, expr=expr)
    des_req_data = macho_cs.Requirement.build(des_req)

    reqs = construct.Container(
        sb_start=0,
        count=1,
        BlobIndex=[construct.Container(type='kSecDesignatedRequirementType',
                                       offset=28,
                                       blob=construct.Container(magic='CSMAGIC_REQUIREMENT',
                                                                length=len(des_req_data) + 8,
                                                                data=des_req,
                                                                bytes=des_req_data))])

    if drs:
        dr_exprs = [dr.blob.data.expr for dr in drs.data.BlobIndex]
        expr = make_expr('Or', *dr_exprs)
        lib_req = construct.Container(kind=1, expr=expr)
        lib_req_data = macho_cs.Requirement.build(lib_req)

        reqs.BlobIndex.append(construct.Container(type='kSecLibraryRequirementType',
github saucelabs / isign / isign / makesig.py View on Github external
def make_expr(op, *args):
    full_op = "op" + op
    data = None
    data_type = macho_cs.expr_args.get(full_op)
    if isinstance(data_type, macho_cs.Sequence):
        if len(data_type.subcons) == len(args):
            data = [make_arg(dt, arg) for dt, arg in zip(data_type.subcons, args)]
        else:
            # automatically nest binary operations to accept >2 args
            data = [make_arg(data_type.subcons[0], args[0]),
                    make_expr(op, *args[1:])]
    elif data_type:
        data = make_arg(data_type, args[0])
    return construct.Container(op=full_op,
                               data=data)
github lukleh / TwistedBot / twistedbot / packets.py View on Github external
def _encode(self, obj, context):
        c = Container(data=[], terminator=None)
        for k, v in obj.iteritems():
            t, value = v
            d = Container(
                id=Container(data_type=metadata_types.index(t), identifier=k),
                value=value,
                peeked=None)
            c.data.append(d)
        c.data[-1].peeked = 127
        return c