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


Python xdrlib.Packer类代码示例

本文整理汇总了Python中xdrlib.Packer的典型用法代码示例。如果您正苦于以下问题:Python Packer类的具体用法?Python Packer怎么用?Python Packer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Packer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _bytes_from_length

def _bytes_from_length(len, closing):
    """
    The RPC standard calls for the length of a message to be sent as the least
    significant 31 bits of an XDR encoded unsigned integer.  The most
    significant bit encodes a True/False bit which indicates that this message
    will be the last.
    """
    assert 0 <= len < 2**31
    from xdrlib import Packer
    if closing:
        len += 2**31
    packer = Packer()
    packer.pack_uint(len)
    return packer.get_buffer()
开发者ID:saalweachter,项目名称:fs,代码行数:14,代码来源:tcp.py

示例2: __init__

 def __init__(self, stamp, machinename, uid, gid, gids):
     if len(machinename) > 255:
         raise SecError("machinename %s is too long" % machinename)
     if len(gids) > 16:
         raise SecError("gid array too long: %s" % str(gids))
     try:
         p = Packer()
         p.pack_int(stamp)
         p.pack_string(machinename)
         p.pack_uint(uid)
         p.pack_uint(gid)
         p.pack_array(gids, p.pack_uint)
         self.cred = p.get_buffer()
     except Error, e:
         raise SecError("Packing error: %s", str(e))
开发者ID:chandra2,项目名称:nfs-ganesha,代码行数:15,代码来源:sec_auth_sys.py

示例3: __call__

 def __call__(self, arg):
     msg = rpc_msg(xid=self.xid,
                   body=rpc_msg.body(mtype=msg_type.CALL,
                                     cbody=call_body(rpcvers=2,
                                                     prog=self.prog,
                                                     vers=self.vers,
                                                     proc=self.procedure.procedure_id,
                                                     cred=opaque_auth.NONE(),
                                                     verf=opaque_auth.NONE())))
     from xdrlib import Packer
     packer = Packer()
     msg.pack(packer)
     print("msg: %s" % packer.get_buffer())
     arg.pack(packer)
     print("msg: %s" % packer.get_buffer())
开发者ID:saalweachter,项目名称:fs,代码行数:15,代码来源:rpc.py

示例4: make_reply_verf

 def make_reply_verf(self, cred, stat):
     log_gss.debug("CALL:make_reply_verf(%r, %i)" % (cred, stat))
     cred = cred.body
     if stat:
         # Return trivial verf on error
         # NOTE this relies on GSS_S_COMPLETE == rpc.SUCCESS == 0
         return rpclib.NULL_CRED
     elif cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
         # init requires getMIC(seq_window)
         i = WINDOWSIZE
     else:
         # Else return getMIC(cred.seq_num)
         i = cred.seq_num
     p = Packer()
     p.pack_uint(i)
     # XXX BUG - need to set qop
     token = self._get_context(cred.handle).getMIC(p.get_buffer())
     return opaque_auth(RPCSEC_GSS, token)
开发者ID:kofemann,项目名称:pynfs,代码行数:18,代码来源:security.py

示例5: _mix_counterparties

def _mix_counterparties(cp1, cp2, data):
    assert type(cp1) == type('')
    assert type(cp2) == type('')
    assert type(data) == type('')
    p = Packer()
    p.pack_string(cp1)
    p.pack_string(cp2)
    p.pack_string(data)
    return sha(p.get_buffer()).digest()
开发者ID:zooko,项目名称:egtp,代码行数:9,代码来源:mesgen.py

示例6: init_cred

 def init_cred(self, call, target="[email protected]", source=None, oid=None):
     # STUB - need intelligent way to set defaults
     good_major = [gssapi.GSS_S_COMPLETE, gssapi.GSS_S_CONTINUE_NEEDED]
     p = Packer()
     up = GSSUnpacker('')
     # Set target (of form [email protected])
     target = gssapi.Name(target, gssapi.NT_HOSTBASED_SERVICE)
     # Set source (of form USERNAME)
     if source is not None:
         source = gssapi.Name(source, gssapi.NT_USER_NAME)
         gss_cred = gssapi.Credential(gssapi.INITIATE, source.ptr) # XXX
     else:
         # Just use default cred
         gss_cred = None
     context = gssapi.Context()
     token = None
     handle = ''
     proc = RPCSEC_GSS_INIT
     while True:
         # Call initSecContext.  If it returns COMPLETE, we are done.
         # If it returns CONTINUE_NEEDED, we must send d['token']
         # to the target, which will run it through acceptSecContext,
         # and give us back a token we need to send through initSecContext.
         # Repeat as necessary.
         token = context.init(target, token, gss_cred)
         if context.open:
             # XXX if res.major == CONTINUE there is a bug in library code
             # STUB - now what? Just use context?
             # XXX need to use res.seq_window
             # XXX - what if handle still '' ?
             self._add_context(context, handle)
             break
         # Send token to target using protocol of RFC 2203 sect 5.2.2
         credinfo = CredInfo(self, context=handle,
                             gss_proc=proc)
         proc = RPCSEC_GSS_CONTINUE_INIT
         p.reset()
         p.pack_opaque(token)
         header, reply = call(p.get_buffer(), credinfo)
         up.reset(reply)
         res = up.unpack_rpc_gss_init_res()
         up.done()
         # res now holds relevent output from target's acceptSecContext call
         if res.gss_major not in good_major:
             raise gssapi.Error(res.gss_major, res.gss_minor)
         handle = res.handle # Should not change between calls
         token = res.gss_token # This needs to be sent to initSecContext
     return CredInfo(self, context=handle)
开发者ID:kofemann,项目名称:pynfs,代码行数:48,代码来源:security.py

示例7: gmetric_value

def gmetric_value(NAME, VAL):
    packer = Packer()
    packer.pack_int(128+5)  # string
    packer.pack_string('nickg-macbook.local')
    packer.pack_string(NAME)
    packer.pack_bool(False)
    packer.pack_string('%s')
    packer.pack_string(VAL)
    return packer.get_buffer()
开发者ID:HC-ITOPS,项目名称:ganglia_contrib,代码行数:9,代码来源:gmetric.py

示例8: _pack

 def _pack(reply):
     packer = Packer()
     reply.pack(packer)
     return packer.get_buffer()
开发者ID:saalweachter,项目名称:fs,代码行数:4,代码来源:rpc.py

示例9: gmetric_write

def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
    packer = Packer()
    HOSTNAME = 'test'
    if SPOOF == '':
        SPOOFENABLED = 0
    else:
        SPOOFENABLED = 1
    packer.pack_int(128)
    if SPOOFENABLED == 1:
        packer.pack_string(SPOOF)
    else:
        packer.pack_string(HOSTNAME)
    packer.pack_string(NAME)
    packer.pack_int(SPOOFENABLED)
    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE])
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    if GROUP == '':
        packer.pack_int(0)
    else:
        packer.pack_int(1)
        packer.pack_string('GROUP')
        packer.pack_string(GROUP)
    data = Packer()
    data.pack_int(133)
    if SPOOFENABLED == 1:
        data.pack_string(SPOOF)
    else:
        data.pack_string(HOSTNAME)
    data.pack_string(NAME)
    data.pack_int(SPOOFENABLED)
    data.pack_string('%s')
    data.pack_string(str(VAL))
    return (packer.get_buffer(), data.get_buffer())
开发者ID:Pluckyduck,项目名称:eve,代码行数:37,代码来源:gmetric.py

示例10: generate_message

    def generate_message(self, recipient_id, message):
        connect_info = self._session_keeper.get_connect_info(recipient_id)
        symmetric_key = connect_info['symmetric_key']
        p = Packer()
        if connect_info.has_key('session_id_out'):
            p.pack_fstring(4, '\000\000\000\001')
            p.pack_fstring(SIZE_OF_UNIQS, connect_info['session_id_out'])
        else:
            #debugprint('including full header on message to %s\n', args=(recipient_id,), vs='mesgen') # XXX verbose
            p.pack_fstring(4, '\000\000\000\000')
            p.pack_string(connect_info['header'])

        iv = randsource.get(8)
        p.pack_fstring(8, iv)
        pdec = Packer()
        pdec.pack_string(message)

        # debugprint("------ ------ ------ ------ hmachish(key=%s, message=%s)\n" % (`symmetric_key`, `message`))
        mac = cryptutil.hmacish(key=symmetric_key, message=message)

        pdec.pack_fstring(SIZE_OF_UNIQS, mac)
        encrypted = tripledescbc.new(symmetric_key).encrypt(iv, pdec.get_buffer())
        p.pack_string(encrypted)
        return p.get_buffer()
开发者ID:zooko,项目名称:egtp,代码行数:24,代码来源:mesgen.py

示例11: send

 def send(self):
     ''' packs the Header vars into a buffer '''
     unp = Packer()
     unp.pack_uint(self.magic)
     unp.pack_uint(self.version)
     unp.pack_uint(self.msgid)
     unp.pack_uint(self.msglen)
     unp.pack_uint(0)  # reply_addr y reply_port
     unp.pack_uint(0)  # reply_addr y reply_port
     unp.pack_fstring(8, self.callsign.encode())
     return unp.get_buffer()
开发者ID:bartacruz,项目名称:fgatc,代码行数:11,代码来源:messages.py

示例12: pack

    def pack(self, values):
        metric = {
            'hostname': '',
            'spoof': 0,
            'units': '',
            'slope': 'both',
            'tmax': 60,
            'dmax': 0
        }
        metric.update(values)

        if metric.get('spoof', False):
            metric['spoof'] = 1
        else:
            metric['spoof'] = 0

        metric['slope'] = SLOPE[metric['slope']]

        for key in ('name', 'value', 'type'):
            if key not in metric:
                raise KeyError("Missing {0}".format(key))

        if metric['type'] not in ('string', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'float', 'double'):
            raise TypeError("Invalid metric type")

        convert = lambda v: v.encode() if isinstance(v, str) else v
        metric = {key: convert(value) for key, value in metric.items()}

        # Metadata
        meta = Packer()
        meta.pack_int(128)
        meta.pack_string(metric['hostname'])
        meta.pack_string(metric['name'])
        meta.pack_int(int(metric['spoof']))
        meta.pack_string(metric['type'])
        meta.pack_string(metric['name'])
        meta.pack_string(metric['units'])
        meta.pack_int(metric['slope'])
        meta.pack_uint(int(metric['tmax']))
        meta.pack_uint(int(metric['dmax']))

        # Group support
        if 'group' in metric:
            meta.pack_int(1)
            meta.pack_string(b"GROUP")
            meta.pack_string(metric['group'])
        else:
            meta.pack_int(0)

        # Data
        data = Packer()
        data.pack_int(128 + 5)
        data.pack_string(metric['hostname'])
        data.pack_string(metric['name'])
        data.pack_int(int(metric['spoof']))
        data.pack_string(b"%s")
        data.pack_string(bytes(metric['value']))

        return meta.get_buffer(), data.get_buffer()
开发者ID:cyberdelia,项目名称:ganglia,代码行数:59,代码来源:ganglia.py

示例13: handle_message

    def handle_message(self, opaque_bytes, client_id):
        """
        Handles a message, start to finish.
        Takes the opaque bytes representing the XDR encoded RPC message.
        Produces an RPC reply, also encoded as opaque bytes.
        """
        from xdrlib import Unpacker, Packer
        unpacker = Unpacker(opaque_bytes)
        msg = rpc_msg.unpack(unpacker)
        print(msg.body.mtype.value)
        if msg.body.mtype != msg_type.CALL:
            print("No reply!")
            return None # do not reply to such a bad message.
        #response = self.handle_message(msg,
        #                               opaque_bytes[unpacker.get_position():])
        print("Well-formed message!")
        print("rpc version: %d" % msg.body.cbody.rpcvers)
        print("program id: %d" % msg.body.cbody.prog)
        print("version id: %d" % msg.body.cbody.vers)
        print("procedure id: %d" % msg.body.cbody.proc)
        print("cred flavor: %d" % msg.body.cbody.cred.flavor)
        print("verf flavor: %d" % msg.body.cbody.verf.flavor)
        print("remaining bytes: %s" % opaque_bytes[unpacker.get_position():])

        if msg.body.cbody.cred.flavor == auth_flavor.AUTH_SYS:
            print("using system auth")
            unpacker2 = Unpacker(msg.body.cbody.cred.body.bytes)
            params = authsys_parms.unpack(unpacker2)
            print(params)
            id = self.next_short_id
            self.next_short_id += 1
            self.system_auth[id] = params
            packer = Packer()
            packer.pack_uint(id)
            verf = opaque_auth(flavor=auth_flavor.AUTH_SHORT,
                               body=packer.get_buffer())
        else:
            verf = opaque_auth.NONE()

        def _pack(reply):
            packer = Packer()
            reply.pack(packer)
            return packer.get_buffer()
        _body = rpc_msg.body
        _rbody = reply_body
        _rreply = rejected_reply
        _areply = accepted_reply
        _rdata = accepted_reply.reply_data
        
        if msg.body.cbody.rpcvers != 2:
            reply = rpc_msg(xid=msg.xid,
                            body=_body(mtype=msg_type.REPLY,
                                       rbody=_rbody(stat=reply_stat.MSG_DENIED,
                                                    rreply=_rreply(stat=reject_stat.RPC_MISMATCH,
                                                                   mismatch_info=mismatch_info(low=2, high=2)))))
            return _pack(reply)

        if msg.body.cbody.prog not in self.programs:
            print("no such program!")
            reply = rpc_msg(xid=msg.xid,
                            body=_body(mtype=msg_type.REPLY,
                                       rbody=_rbody(stat=reply_stat.MSG_ACCEPTED,
                                                    areply=_areply(verf=verf,
                                                                   reply_data=_rdata(stat=accept_stat.PROG_UNAVAIL)))))
            return _pack(reply)

        program = self.programs[msg.body.cbody.prog]
        print("program: %s" % str(program))
        version = program.get_version_impl(msg.body.cbody.vers)
        print("version: %s" % str(version))
        procedure = version.get_procedure_by_id(msg.body.cbody.proc)
        print("procedure: %s" % str(procedure))
        print("procedure.arg_type: %s" % str(procedure.argument_type))
        args = procedure.argument_type.unpack(unpacker)
        print("args: %s" % str(args))
        response = procedure(version, msg, args)
        print("response: %s" % str(response))
        reply = rpc_msg(xid=msg.xid,
                        body=_body(mtype=msg_type.REPLY,
                                   rbody=_rbody(stat=reply_stat.MSG_ACCEPTED,
                                                areply=_areply(verf=verf,
                                                               reply_data=_rdata(stat=accept_stat.SUCCESS)))))
        print("reply: %s" % str(reply))
        packer = Packer()
        reply.pack(packer)
        response.pack(packer)
        print("bytes: %s" % str(packer.get_buffer()))
        return packer.get_buffer()
开发者ID:saalweachter,项目名称:fs,代码行数:88,代码来源:rpc.py

示例14: secure_data

 def secure_data(self, cred, data):
     log_gss.debug("secure_data(%r)" % cred)
     cred = cred.body
     if cred.service ==  rpc_gss_svc_none or \
        cred.gss_proc in (RPCSEC_GSS_INIT, RPCSEC_GSS_CONTINUE_INIT):
         return data
     p = Packer()
     context = self._get_context(cred.handle)
     try:
         if cred.service == rpc_gss_svc_integrity:
             # data = opaque[gss_seq_num+data] + opaque[checksum]
             p.pack_uint(cred.seq_num)
             data = p.get_buffer() + data
             token = context.getMIC(data) # XXX BUG set qop
             p.reset()
             p.pack_opaque(data)
             p.pack_opaque(token)
             data = p.get_buffer()
         elif cred.service == rpc_gss_svc_privacy:
             # data = opaque[wrap([gss_seq_num+data])]
             p.pack_uint(cred.seq_num)
             data = p.get_buffer() + data
             token = context.wrap(data) # XXX BUG set qop
             p.reset()
             p.pack_opaque(token)
             data = p.get_buffer()
         else:
             # Can't get here, but doesn't hurt
             log_gss.error("Unknown service %i for RPCSEC_GSS" % cred.service)
     except gssapi.Error as e:
         # XXX What now?
         log_gss.warn("secure_data: gssapi call returned %s" % e.name)
         raise
     return data
开发者ID:kofemann,项目名称:pynfs,代码行数:34,代码来源:security.py

示例15: encode

 def encode(self):
     '''Return the serialized bytes for the object.'''
     with _convert_exceptions():
         xdr = Packer()
         self.encode_xdr(xdr)
         return xdr.get_buffer()
开发者ID:cmusatyalab,项目名称:opendiamond,代码行数:6,代码来源:xdr.py


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