當前位置: 首頁>>代碼示例>>Python>>正文


Python Unpacker.unpack_int方法代碼示例

本文整理匯總了Python中xdrlib.Unpacker.unpack_int方法的典型用法代碼示例。如果您正苦於以下問題:Python Unpacker.unpack_int方法的具體用法?Python Unpacker.unpack_int怎麽用?Python Unpacker.unpack_int使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xdrlib.Unpacker的用法示例。


在下文中一共展示了Unpacker.unpack_int方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_datagram

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
def read_datagram(addr, data):
    """Yield all record (flow and counter records) from the sFlow v5
    datagram given by up, which is expected to be an xdrlib.Unpacker
    object."""

    up = Unpacker(data)

    version = up.unpack_int()
    if not version == 5:
        hexdump_bytes(data)
        raise Exception()

    af = up.unpack_int()
    if af == 1:                 # IPv4
        agent_address = ntohl(up.unpack_uint())
    else:
        raise Exception()

    sf = Datagram(addr, agent_address)

    sub_agent_id = up.unpack_uint()
    sequence_number = up.unpack_uint()
    uptime = up.unpack_uint()
    nb_sample_records = up.unpack_uint()

    # Iterating over sample records
    for i in range(nb_sample_records):
        try:
            return read_sample_record(up, sf)
        except EOFError:
            stderr.write("read_sample_datagram: EOFError reading sample_record,", \
                      "Premature end of data stream, Skipping record\n")
            up.set_position(len(up.get_buffer()))
            break
開發者ID:bruceSz,項目名稱:pyflow,代碼行數:36,代碼來源:v5.py

示例2: _parse_raw_sflow_datagram

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
    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,代碼行數:28,代碼來源:SFlowDatagram.py

示例3: run

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
 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,代碼行數:61,代碼來源:trackpad_server.py

示例4: gmetric_read

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
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,代碼行數:15,代碼來源:gmetric.py

示例5: handle

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
    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,代碼行數:17,代碼來源:graphlia.py

示例6: decode_data

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
    def decode_data(self, data):
        ''' Decodes 1 UDP Ganglia packet, returns a dict of the decoded data '''
        ret = {}
        xdr = Unpacker(data)

        message_type = xdr.unpack_int()

        if message_type == GANGLIA_METADATA_MESSAGE:
            ret = {
                'METRIC':       'METADATA',
                'hostname':     xdr.unpack_string(),
                'name':         xdr.unpack_string(),
                'spoof':        bool(xdr.unpack_int()),
                'metric_type':  xdr.unpack_string(),
                'metric_name':  xdr.unpack_string(),
                'units':        xdr.unpack_string(),
                'slope':        xdr.unpack_int(),
                'time_max':     xdr.unpack_int(),
                'data_max':     xdr.unpack_int()
            }

            assert xdr.unpack_int() == 1
            assert xdr.unpack_string() == 'GROUP'
            ret['group'] = xdr.unpack_string()

        elif message_type == GANGLIA_METRIC_MESSAGE:
            ret = {
                'type':      'METRIC',
                'hostname':  xdr.unpack_string(),
                'metric':    xdr.unpack_string(),
                'spoof':     bool(xdr.unpack_int()),
                'format':    xdr.unpack_string(),
                'value':     xdr.unpack_string()
            }

        xdr.done()

        return ret
開發者ID:GregBowyer,項目名稱:random-junk,代碼行數:40,代碼來源:GanglaDecoder.py

示例7: Unpacker

# 需要導入模塊: from xdrlib import Unpacker [as 別名]
# 或者: from xdrlib.Unpacker import unpack_int [as 別名]
import socket
from xdrlib import Unpacker
host = 'localhost'
port = 8000
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((host,port))
s.listen(5)
conn, addr = s.accept()
print 'conectado por', addr
while 1:
    data = conn.recv(1024)
    un = Unpacker(data)
    if not data: break
    data = un.unpack_int()
    conn.send(str(data))
conn.close()
開發者ID:awhawks,項目名稱:stiq,代碼行數:18,代碼來源:server.py


注:本文中的xdrlib.Unpacker.unpack_int方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。