• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xdrlib.Unpacker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: decode

 def decode(cls, data):
     '''Deserialize the data and return an object.'''
     with _convert_exceptions():
         xdr = Unpacker(data)
         ret = cls.decode_xdr(xdr)
         xdr.done()
         return ret
开发者ID:cmusatyalab,项目名称:opendiamond,代码行数:7,代码来源:xdr.py


示例2: _parse_raw_sflow_counter_sample

    def _parse_raw_sflow_counter_sample(self, unpacker: Unpacker):
        self.sequence_number = unpacker.unpack_uint()
        self.source_id = unpacker.unpack_uint()
        counters_in_sample = unpacker.unpack_uint()

        for _ in range(counters_in_sample):
            self.counters.append(SFlowCounterRecord(unpacker))
开发者ID:orliin,项目名称:sFlowParser,代码行数:7,代码来源:SFlowSample.py


示例3: __init__

class Trajectory:
	def __init__(self, topology, trajFileName):
		# since we need to be able to do seeks, can't use osOpen
		# which might return an unseekable stream
		self.topology = topology
		from OpenSave import osUncompressedPath
		path = osUncompressedPath(trajFileName)
		import os
		self.trajFileSize = os.stat(path).st_size
		self.traj = open(path, "rb")
		from xdrlib import Unpacker
		self.fileString = FileString(self.traj, 0, self.trajFileSize)
		self.xdr = Unpacker(self.fileString)
		self.crdStarts = []
		while True:
			replyobj.status("Reading frame %d header\n" % (
						len(self.crdStarts) + 1))
			try:
				crdStart, endFrame = self._readHeader()
			except ValueError, e:
				raise ValueError("Frame %d: %s" %
					(len(self.crdStarts) + 1, str(e)))
			if endFrame > self.trajFileSize:
				if not self.crdStarts:
					raise ValueError("Computed size of"
						" first frame (%d) greater than"
						" trajectory file size (%s)" %
						(endFrame, self.trajFileSize))
				replyobj.warning("Truncated trajectory file;"
					" skipping last partial frame.\n")
			else:
				self.crdStarts.append(crdStart)
			if endFrame == self.trajFileSize:
				break
			self.xdr.set_position(endFrame)
开发者ID:davem22101,项目名称:semanticscience,代码行数:35,代码来源:Gromacs.py


示例4: is_tag_full

 def is_tag_full(wrapped_message):
     unpacker = Unpacker(wrapped_message)
     try:
         unpacker.unpack_uint()
         unpacker.unpack_string()
     except EOFError:
         return False
     return True
开发者ID:ilyuha21st,项目名称:ip_communicator,代码行数:8,代码来源:client.py


示例5: get_tlv

 def get_tlv(wrapped_message):
     unpacker = Unpacker(wrapped_message)
     tag = unpacker.unpack_uint()
     message = unpacker.unpack_string()
     pos = unpacker.get_position()
     buff = unpacker.get_buffer()
     rest = buff[pos:]
     return tag, message, rest
开发者ID:ilyuha21st,项目名称:ip_communicator,代码行数:8,代码来源:client.py


示例6: gmetric_read

def gmetric_read(msg):
    unpacker = Unpacker(msg)
    values = dict()
    unpacker.unpack_int()
    values['TYPE'] = unpacker.unpack_string()
    values['NAME'] = unpacker.unpack_string()
    values['VAL'] = unpacker.unpack_string()
    values['UNITS'] = unpacker.unpack_string()
    values['SLOPE'] = slope_int2str[unpacker.unpack_int()]
    values['TMAX'] = unpacker.unpack_uint()
    values['DMAX'] = unpacker.unpack_uint()
    unpacker.done()
    return values
开发者ID:CpuID,项目名称:statsite,代码行数:13,代码来源:gmetric.py


示例7: _length_from_bytes

def _length_from_bytes(four_bytes):
    """
    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.
    """
    from xdrlib import Unpacker
    unpacker = Unpacker(four_bytes)
    val = unpacker.unpack_uint()
    unpacker.done()
    if val < 2**31:
        return (val, False)
    return (val-2**31, True)
开发者ID:saalweachter,项目名称:fs,代码行数:14,代码来源:tcp.py


示例8: parse

    def parse(self, raw_data):
        packet = SFlowPacket()
        data = Unpacker(raw_data)

        # sFlow version (2|4|5)
        packet.version = data.unpack_uint()
        if packet.version != 5:
            logging.error("Only support version 5.")
            raise RuntimeError("Only support version 5.")
        logging.debug("Get version {0}".format(packet.version))

        # IP version of the Agent/Switch (1=v4|2=v6)
        packet.agent_ip_version = data.unpack_uint()
        if packet.agent_ip_version != 1:
            logging.error("Only support IPv4.")
            raise RuntimeError("Only support IPv4.")

        # Agent IP address (v4=4byte|v6=16byte)
        packet.agent_ip_address = ntohl(data.unpack_uint())

        # sub agent id
        packet.sub_agent_id = data.unpack_uint()

        # datagram sequence number
        packet.datagram_sequence_num = data.unpack_uint()

        # switch uptime in ms
        packet.switch_uptime = data.unpack_uint()

        # how many samples in datagram
        packet.sample_amount = data.unpack_uint()

        self._parse_samples(packet, data)

        return packet
开发者ID:CloudAnalytics,项目名称:zabbix-sflow,代码行数:35,代码来源:sflow_parser.py


示例9: read

 def read(self):
     fext = os.path.splitext(self.file)[-1]
     assert fext == ".trr"
     fp = open(self.file, "rb")
     self.data = data = fp.read()
     self.coords = []
     self.v = {}
     self.f = {}
     self.up = Unpacker(data)
     curpos = self.up.get_position()
     datasize = len(data)
     nframe = 0
     #each frame begins with a header
     while curpos < datasize:
         #print "current position:", curpos
         h = self.readHeader(nframe)
         self.headers.append(h)
         self.readData(nframe)
         nframe = nframe + 1
         curpos = self.up.get_position()
     #print "end of readTraj, cur position : %d, datazize: %d" %(self.up.get_position(), datasize)
     self.nframes = nframe
     if self.nframes:
         return 1
     else:
         return 0
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:26,代码来源:trajParser.py


示例10: __init__

    def __init__(self, unpacker: Unpacker):
        self.sequence_number = None
        self.source_id = None
        self.counters = []

        sample_data = unpacker.unpack_opaque()
        unpacker_sample_data = Unpacker(sample_data)
        self._parse_raw_sflow_counter_sample(unpacker_sample_data)
开发者ID:orliin,项目名称:sFlowParser,代码行数:8,代码来源:SFlowSample.py


示例11: _parse_raw_sflow_datagram

    def _parse_raw_sflow_datagram(self, unpacker: Unpacker):
        self.sflow_version = unpacker.unpack_int()
        if not self.sflow_version == 5:
            logging.debug("Unimplemented sFlow version: {}".format(self.sflow_version))
            # TODO: read remainder if needed
            return

        self.agent_ip_version = unpacker.unpack_int()
        if self.agent_ip_version == 1:
            self.agent_ip_address = ntohl(unpacker.unpack_uint())
        # TODO: implement other versions
        else:
            logging.debug("Unimplemented agent IP version: {}".format(self.agent_ip_version))
            return

        self.sub_agent_id = unpacker.unpack_uint()
        self.sequence_number = unpacker.unpack_uint()
        self.switch_uptime = unpacker.unpack_uint()

        samples_in_datagram = unpacker.unpack_uint()
        for _ in range(samples_in_datagram):
            try:
                self.samples.append(SFlowSample(unpacker))
            except Exception as e:
                logging.warning("Bad sample")
                raise e
开发者ID:orliin,项目名称:sFlowParser,代码行数:26,代码来源:SFlowDatagram.py


示例12: datagramReceived

 def datagramReceived(self, datagram, address):
     values = dict()
     unpacker = Unpacker(datagram)
     packet_type = unpacker.unpack_uint()
     if packet_type == 128:
         self.unpack_meta(unpacker)
         return
     elif packet_type == 136:
         #unpack_metareq function works, but serves no purpose right now
         #commented out unless anyone comes up with a good reason to respond
         #to metadata requests.
         #self.unpack_metareq(unpacker)
         return
     elif 128 < packet_type < 136:
         self.unpack_data(unpacker, packet_type, address)
         return
     else:
         return
开发者ID:drawks,项目名称:graphlia,代码行数:18,代码来源:graphlia.py


示例13: __init__

    def __init__(self, unpacker: Unpacker):
        self.flow_format = None
        self.flow = None

        self.flow_format = unpacker.unpack_uint()
        flow_data = unpacker.unpack_opaque()
        unpacker_flow_data = Unpacker(flow_data)

        if self.flow_format == SFlowFlowRecord.FLOW_DATA_RAW_HEADER:
            self.flow = FlowDataRawHeader(unpacker_flow_data)
        elif self.flow_format == SFlowFlowRecord.FLOW_DATA_ETHERNET_HEADER:
            self.flow = FlowDataEthernetHeader(unpacker_flow_data)
        elif self.flow_format == SFlowFlowRecord.FLOW_DATA_IPV4_HEADER:
            self.flow = FlowDataIPv4Header(unpacker_flow_data)
        elif self.flow_format == SFlowFlowRecord.FLOW_DATA_EXT_SWITCH:
            self.flow = FlowDataExtSwitch(unpacker_flow_data)
        else:
            logging.debug('read_flow_record:Unimplemented data_format (%d)' % self.flow_format)
开发者ID:orliin,项目名称:sFlowParser,代码行数:18,代码来源:SFlowFlowRecord.py


示例14: read_flow_record

def read_flow_record(up, sample):
    """Reads a 'struct flow_record' (p. 29)"""

    flow_format = up.unpack_uint()
    flow_data = up.unpack_opaque()
    up_flow_data = Unpacker(flow_data)

    if flow_format == FLOW_DATA_RAW_HEADER:
        res = FlowRecord(sample, read_sampled_header(up_flow_data))
    elif flow_format == FLOW_DATA_ETHERNET_HEADER:
        res = FlowRecord(sample, read_sampled_ethernet(up_flow_data))
    elif flow_format == FLOW_DATA_IPV4_HEADER:
        res = FlowRecord(sample, read_sampled_ipv4(up_flow_data))
    else:
        res = 'read_flow_record:Unknown data_format (%d)' % flow_format

    up_flow_data.done()
    return res
开发者ID:bruceSz,项目名称:pyflow,代码行数:18,代码来源:v5.py


示例15: handle

    def handle(self):
        data = self.request[0]

        unpacker = Unpacker(data)
        type = unpacker.unpack_int()
        if type not in GANGLIA_DECODE: return

        host = unpacker.unpack_string()
        name = unpacker.unpack_string()
        unpacker.unpack_int() # spoof boolean
        unpacker.unpack_string() # format string
        value = GANGLIA_DECODE[type](unpacker)
        unpacker.done()

        graphite.record_stat(name, value)
开发者ID:SEJeff,项目名称:graphlia,代码行数:15,代码来源:graphlia.py


示例16: _parse_raw_sflow_flow_sample

    def _parse_raw_sflow_flow_sample(self, unpacker: Unpacker):
        self.sequence_number = unpacker.unpack_uint()
        self.source_id = unpacker.unpack_uint()
        self.sampling_rate = unpacker.unpack_uint()
        self.sample_pool = unpacker.unpack_uint()
        self.drops = unpacker.unpack_uint()
        self.input_if = unpacker.unpack_uint()
        self.output_if = unpacker.unpack_uint()

        flows_in_sample = unpacker.unpack_uint()
        for _ in range(flows_in_sample):
            self.flows.append(SFlowFlowRecord(unpacker))
开发者ID:orliin,项目名称:sFlowParser,代码行数:12,代码来源:SFlowSample.py


示例17: read_sample_record

def read_sample_record(up, sample_datagram):

    # Unpack sample_record structure
    #    data_format sample_type;
    #       Specifies the type of sample data
    #    opaque sample_data<>;
    #       A structure corresponding to the sample_type

    sample_type = up.unpack_uint()

    sample_data = up.unpack_opaque()
    up_sample_data = Unpacker(sample_data)
    
    if sample_type == SAMPLE_DATA_FLOW_RECORD:
        return read_flow_sample(up_sample_data, sample_datagram)
    elif sample_type == SAMPLE_DATA_COUNTER_RECORD:
        return read_counter_sample(up_sample_data, sample_datagram)

    else:
        raise Exception()

    # Check if whole data block was unpacked
    up_sample_data.done()
开发者ID:bruceSz,项目名称:pyflow,代码行数:23,代码来源:v5.py


示例18: getvalue

    def getvalue(self):
        if isinstance(self.var, SequenceType):
            out = []
            mark = self._unpack_uint()
            while mark == 1509949440:
                var = self.var
                # Create a structure with the sequence vars:
                self.var = StructureType(name=self.var.name)
                self.var.update(var)
                out.append(self.getvalue())
                self.var = var
                mark = self._unpack_uint()

        elif isinstance(self.var, StructureType):
            out = []
            for child in self.var.walk():
                var = self.var
                self.var = child
                out.append(self.getvalue())
                self.var = var
            out = tuple(out)

        else:
            # Get data length.
            n = 1
            if getattr(self.var, 'shape', False):
                n = self._unpack_uint()
                if self.var.type not in [Url, String]:
                    self._unpack_uint()
                
            # Bytes are treated differently.
            if self.var.type == Byte:
                out = self._unpack_bytes(n)
                out = numpy.array(out, self.var.type.typecode)
            # As are strings...
            elif self.var.type in [Url, String]:
                out = self._unpack_string(n)
                out = numpy.array(out, self.var.type.typecode)
            else:
                i = self._pos
                self._pos = j = i + (n*self.var.type.size)
                #dtype = ">%s%s" % (self.var.type.typecode, self.var.type.size)
                #out = numpy.fromstring(self._buf[i:j], dtype=dtype)
                if self.var.type.typecode == 'i':
                    un = Unpacker(self._buf[i:j])
                    out = un.unpack_farray( n, un.unpack_int )
                elif (self.var.type.typecode == 'f') and (self.var.type.size == 8):
                    un = Unpacker(self._buf[i:j])
                    out = un.unpack_farray( n, un.unpack_double )
                elif (self.var.type.typecode == 'f') and (self.var.type.size == 4):
                    un = Unpacker(self._buf[i:j])
                    out = un.unpack_farray( n, un.unpack_float )
                else:
                    print "type", self.var.type.typecode
                    pass
            #print out
        return out
开发者ID:msaunby,项目名称:weather,代码行数:57,代码来源:minxdr.py


示例19: __init__

    def __init__(self, unpacker: Unpacker):
        self.counter_format = None
        self.counter = None

        self.counter_format = unpacker.unpack_uint()
        counter_data = unpacker.unpack_opaque()
        unpacker_counter_data = Unpacker(counter_data)

        if self.counter_format == SFlowCounterRecord.COUNTER_DATA_GENERIC_INTERFACE:
            self.counter = GenericInterfaceCounters(unpacker_counter_data)
        elif self.counter_format == SFlowCounterRecord.COUNTER_DATA_ETHERNET_INTERFACE:
            self.counter = EthernetInterfaceCounters(unpacker_counter_data)
        elif self.counter_format == SFlowCounterRecord.COUNTER_DATA_TOKEN_RING:
            pass
            self.counter = TokenRingCounters(unpacker_counter_data)
        elif self.counter_format == SFlowCounterRecord.COUNTER_DATA_VG_INTERFACE:
            pass
            self.counter = VgInterfaceCounters(unpacker_counter_data)
        elif self.counter_format == SFlowCounterRecord.COUNTER_DATA_VLAN:
            self.counter = VlanCounters(unpacker_counter_data)
        elif self.counter_format == SFlowCounterRecord.COUNTER_DATA_PROCESSOR:
            self.counter = ProcessorCounters(unpacker_counter_data)
        else:
            logging.debug('read_flow_record:Unimplemented data_format (%d)' % self.flow_format)
开发者ID:orliin,项目名称:sFlowParser,代码行数:24,代码来源:SFlowCounterRecord.py


示例20: run

 def run(self):
     while self.server_running:
         potential_read = [self.server_socket]
         if self.client is not None:
             potential_read.append(self.client)
         try:
             ready_to_read, ready_to_write, in_erro = select.select(
                 potential_read, [], [])
             if self.server_socket in ready_to_read:
                 conn, addr = self.server_socket.accept()
                 self.client = conn
                 print('New connection from ', addr)
             elif self.client in ready_to_read:
                 # self.client.recv_into(self.buffer, 512)
                 recv = self.client.recv(128)
                 self.buffer += recv
                 if len(recv) == 0:
                     print('Disconnection from client')
                     self.client.close()
                     self.client = None
                     self.buffer = ''
                     continue
                 unpack = Unpacker(self.buffer)
                 if len(self.buffer) >= unpack.unpack_int():
                     unpack.set_position(0)
                     size = unpack.unpack_int()
                     cmd = unpack.unpack_int()
                     if cmd == ServerMouseController.PACKET_MOVE:
                         # Mouse move control
                         x = unpack.unpack_float()
                         y = unpack.unpack_float()
                         print(size, cmd, x, y)
                         self.mouse_controller.move(
                             self.mouse_controller.position()[0] - x,
                             self.mouse_controller.position()[1] - y)
                     elif cmd == ServerMouseController.PACKET_CLICK:
                         # Mouse click control
                         button = unpack.unpack_int()
                         nb_click = unpack.unpack_int()
                         print(size, cmd, button, nb_click)
                         self.mouse_controller.click(
                             self.mouse_controller.position()[0],
                             self.mouse_controller.position()[1],
                             button,
                             nb_click)
                     elif cmd == ServerMouseController.PACKET_SCROLL:
                         # Mouse scrolling
                         x = unpack.unpack_float()
                         y = unpack.unpack_float()
                         print(size, cmd, x, y)
                         self.mouse_controller.scroll(
                             vertical=int(y), horizontal=int(x))
                     self.buffer = self.buffer[unpack.get_position():]
         except select.error as e:
             print(e)
     if self.client is not None:
         self.client.close()
     self.server_socket.close()
     print('Server stop')
开发者ID:ccreusot,项目名称:atrackpad,代码行数:59,代码来源:trackpad_server.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gettextutils._函数代码示例发布时间:2022-05-26
下一篇:
Python xdrlib.Packer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap