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


Python Packer.pack_uint方法代码示例

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


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

示例1: secure_data

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
 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,代码行数:36,代码来源:security.py

示例2: pack

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
    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,代码行数:61,代码来源:ganglia.py

示例3: send

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
 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,代码行数:13,代码来源:messages.py

示例4: _bytes_from_length

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
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,代码行数:16,代码来源:tcp.py

示例5: __init__

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
 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,代码行数:17,代码来源:sec_auth_sys.py

示例6: gmetric_write

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP, SPOOF):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    HOSTNAME="test"
    if SPOOF == "":
        SPOOFENABLED=0
    else :
        SPOOFENABLED=1
    # Meta data about a metric
    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]) # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    # Magic number. Indicates number of entries to follow. Put in 1 for GROUP
    if GROUP == "":
        packer.pack_int(0)
    else:
        packer.pack_int(1)
        packer.pack_string("GROUP")
        packer.pack_string(GROUP)

    # Actual data sent in a separate packet
    data = Packer()
    data.pack_int(128+5)
    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:CpuID,项目名称:statsite,代码行数:47,代码来源:gmetric.py

示例7: make_reply_verf

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
 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,代码行数:20,代码来源:security.py

示例8: __init__

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
 def __init__(self, stamp=0, machinename='', uid=0, gid=0, 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)
         try:    # for python2
             p.pack_string(machinename)
         except: # for python3
             p.pack_string(bytes(machinename, 'utf-8'))
         p.pack_uint(uid)
         p.pack_uint(gid)
         p.pack_array(gids, p.pack_uint)
         self.cred = p.get_buffer()
     except Error as e:
         raise SecError("Packing error: %s", str(e))
     self.uid = uid
     self.gid = gid
开发者ID:kofemann,项目名称:pynfs,代码行数:22,代码来源:sec_auth_sys.py

示例9: gmetric_meta

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None):
    """
    Arguments are in all upper-case to match XML
    """
    packer = Packer()
    packer.pack_int(128)  # "gmetadata_full"
    packer.pack_string('nickg-macbook.local')
    packer.pack_string(NAME)
    packer.pack_bool(False)

    packer.pack_string(TYPE)
    packer.pack_string(NAME)
    packer.pack_string(UNITS)
    packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
    packer.pack_uint(int(TMAX))
    packer.pack_uint(int(DMAX))
    if EXTRAS is None:
        packer.pack_uint(0)
    else:
        packer.pack_uint(len(EXTRAS))
        for k,v in EXTRAS.iteritems():
            packer.pack_string(k)
            packer.pack_string(v)

    return packer.get_buffer()
开发者ID:HC-ITOPS,项目名称:ganglia_contrib,代码行数:27,代码来源:gmetric.py

示例10: gmetric_write

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
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,代码行数:39,代码来源:gmetric.py

示例11: _gmetric

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
    def _gmetric(self, name, val, metric_type, units, slope, tmax, dmax, group, title, description, spoof):

        meta = Packer()
        HOSTNAME = socket.gethostname()
        if spoof:
            SPOOF_ENABLED = 1
        else:
            SPOOF_ENABLED = 0

        # Meta data about a metric
        packet_type = 128
        meta.pack_int(packet_type)
        if SPOOF_ENABLED == 1:
            meta.pack_string(spoof)
        else:
            meta.pack_string(HOSTNAME)
        meta.pack_string(name)
        meta.pack_int(SPOOF_ENABLED)
        meta.pack_string(metric_type)
        meta.pack_string(name)
        meta.pack_string(units)
        meta.pack_int(METRIC_SLOPES[slope])  # map slope string to int
        meta.pack_uint(int(tmax))
        meta.pack_uint(int(dmax))

        extra_data = 0
        if group:
            extra_data += 1
        if title:
            extra_data += 1
        if description:
            extra_data += 1

        meta.pack_int(extra_data)
        if group:
            for g in group.split(','):
                meta.pack_string("GROUP")
                meta.pack_string(g)
        if title:
            meta.pack_string("TITLE")
            meta.pack_string(title)
        if description:
            meta.pack_string("DESC")
            meta.pack_string(description)

        # Actual data sent in a separate packet
        data = Packer()
        packet_type = METRIC_TYPES[metric_type]
        data.pack_int(packet_type)
        if SPOOF_ENABLED == 1:
            data.pack_string(spoof)
        else:
            data.pack_string(HOSTNAME)
        data.pack_string(name)
        data.pack_int(SPOOF_ENABLED)

        if metric_type in ['int8', 'uint8', 'int16', 'uint16', 'int32']:
            data.pack_string("%d")
            data.pack_int(int(val))
        if metric_type == 'uint32':
            data.pack_string("%u")
            data.pack_uint(long(val))
        if metric_type == 'string':
            data.pack_string("%s")
            data.pack_string(str(val))
        if metric_type == 'float':
            data.pack_string("%f")
            data.pack_float(float(val))
        if metric_type == 'double':
            data.pack_string("%f")
            data.pack_double(float(val))  # XXX - double or float?

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

示例12: compute_tlv

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
 def compute_tlv(tag, message):
     packer = Packer()
     packer.pack_uint(tag)
     packer.pack_string(message)
     return packer.get_buffer()
开发者ID:ilyuha21st,项目名称:ip_communicator,代码行数:7,代码来源:client.py

示例13: _gmetric

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
    def _gmetric(self, name, val, type, units, slope, tmax, dmax, group, title, description, spoof):
        """
        Arguments are in all upper-case to match XML
        """

        meta = Packer()
        HOSTNAME=socket.gethostname()
        if spoof == "":
            SPOOFENABLED=0
        else :
            SPOOFENABLED=1

        # Meta data about a metric
        packet_type = 128
        meta.pack_int(packet_type)
        if SPOOFENABLED == 1:
            meta.pack_string(spoof)
        else:
            meta.pack_string(HOSTNAME)
        meta.pack_string(name)
        meta.pack_int(SPOOFENABLED)
        meta.pack_string(type)
        meta.pack_string(name)
        meta.pack_string(units)
        meta.pack_int(SLOPES[slope]) # map slope string to int
        meta.pack_uint(int(tmax))
        meta.pack_uint(int(dmax))

        extra_data = 0
        if group != "":
            extra_data += 1
        if title != "":
            extra_data += 1
        if description != "":
            extra_data += 1

        meta.pack_int(extra_data)
        if group != "":
            meta.pack_string("GROUP")
            meta.pack_string(group)
        if title != "":
            meta.pack_string("TITLE")
            meta.pack_string(title)
        if description != "":
            meta.pack_string("DESC")
            meta.pack_string(description)

        # Actual data sent in a separate packet
        data = Packer()
        packet_type = TYPES[type]
        data.pack_int(packet_type)
        if SPOOFENABLED == 1:
            data.pack_string(spoof)
        else:
            data.pack_string(HOSTNAME)
        data.pack_string(name)
        data.pack_int(SPOOFENABLED)

        if type in ['int8','uint8','int16','uint16','int32']:
            data.pack_string("%d")
            data.pack_int(int(val))
        if type == 'uint32':
            data.pack_string("%u")
            data.pack_uint(long(val))
        if type == 'string':
            data.pack_string("%s")
            data.pack_string(str(val))
        if type == 'float':
            data.pack_string("%f")
            data.pack_float(float(val))
        if type == 'double':
            data.pack_string("%f")
            data.pack_double(float(val))  # XXX - double or float?

        return (meta.get_buffer(), data.get_buffer())
开发者ID:satterly,项目名称:ganglia_contrib,代码行数:77,代码来源:gmetric.py

示例14: _rpcPacket

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
def _rpcPacket():			#Build RPC portmap call
        
    data = Packer()
    data.pack_uint(int(random() * 0xffffffff))       # Transaction Identifier (xid)
    data.pack_enum(CALL)                                    # Message Type
    data.pack_uint(2)                                       # RPC version
    data.pack_enum(PORTMAP)                                 # Program 
    data.pack_uint(2)                                       # Program Version
    data.pack_enum(GETPORT)                                 # Process
    data.pack_enum(AUTH_NULL)                               # Credentials
    data.pack_uint(0)                                       # Credentials length
    data.pack_enum(AUTH_NULL)                               # Verifier 
    data.pack_uint(0)                                       # Verifier Length
    data.pack_enum(VXI11_CORE)                              # Called Program
    data.pack_uint(1)                                       # Program Version
    data.pack_enum(TCP)                                     # Program Protocol
    data.pack_uint(0)                                       # Port
    
    return data.get_buffer()
开发者ID:WhirleyDragon,项目名称:SorensenGUI,代码行数:21,代码来源:vxiUtils.py

示例15: handle_message

# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_uint [as 别名]
    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,代码行数:90,代码来源:rpc.py


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