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


Python Unpacker.feed方法代码示例

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


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

示例1: test_foobar

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test_foobar():
    unpacker = Unpacker(read_size=3)
    unpacker.feed('foobar')
    assert_equal(unpacker.unpack(), ord('f'))
    assert_equal(unpacker.unpack(), ord('o'))
    assert_equal(unpacker.unpack(), ord('o'))
    assert_equal(unpacker.unpack(), ord('b'))
    assert_equal(unpacker.unpack(), ord('a'))
    assert_equal(unpacker.unpack(), ord('r'))
    try:
        o = unpacker.unpack()
        print "Oops!", o
        assert 0
    except StopIteration:
        assert 1
    else:
        assert 0
    unpacker.feed('foo')
    unpacker.feed('bar')

    k = 0
    for o, e in zip(unpacker, 'foobarbaz'):
        assert o == ord(e)
        k += 1
    assert k == len('foobar')
开发者ID:keisukefukuda,项目名称:msgpack-python-pure,代码行数:27,代码来源:test_sequnpack.py

示例2: MsgpackProtocol

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
class MsgpackProtocol(asyncio.Protocol):

    def __init__(self, routes):
        self.__routes = routes
        self.packer = Unpacker()

    def connection_made(self, transport):
        peername = transport.get_extra_info('peername')
        print('Connection from {}'.format(peername))
        self.transport = transport
        self.transport.write(packb([2, 'peername', peername]))

    def data_received(self, data):
        self.packer.feed(data)
        for msg in self.packer:
            assert_request(msg)
            self.routing(msg)

    def routing(self, cmd):
        assert cmd[2] in self.__routes
        t = asyncio.ensure_future(response(cmd[1], self.transport,
                                           self.__routes[cmd[2]], cmd[3]))

    def eof_received(self):
        return True
开发者ID:athoune,项目名称:aiomsgpack-rpc,代码行数:27,代码来源:__init__.py

示例3: SReader

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
class SReader():
    """ Define an asyncio msgpack stream decoder. """

    def __init__(self, reader, writer):
        """ Pass ina  stream reader to unmarshall msgpack objects from. """
        self.reader = reader
        self.writer = writer
        self.decoder = make_decoder()
        self.unpacker = Unpacker(ext_hook=self.decoder, encoding="utf8")
        self.obj_buf = []


    @asyncio.coroutine
    def get(self):
        """ The co-routine providing objects. """

        while len(self.obj_buf) == 0:
            buf = yield from self.reader.read(1000)

            self.unpacker.feed(buf)
            for o in self.unpacker:
                self.obj_buf.append(o)

        return self.obj_buf.pop(0)


    def put(self, obj):
        """ Write an object to the channel. """
        self.writer.write(encode(obj))
开发者ID:gdanezis,项目名称:petlib,代码行数:31,代码来源:cred_server.py

示例4: anomalies

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def anomalies():
    resp = 'handle_data([])'
    try:
        analyzer_key_node = REDIS_BACKENDS.get_node(settings.ANALYZER_ANOMALY_KEY)
        anomaly_keys = RING.run('smembers', settings.ANALYZER_ANOMALY_KEY)
        anomalies = {}
        if not anomaly_keys:
            logger.info("No anomaly key found!")
            return resp, 200
        for key in list(anomaly_keys):
            raw_anomalies = RING.run('get',key)
            if not raw_anomalies:
                logger.info("Can't get anomalies for key %s, removing it from set" % key)
                RING.run('srem', settings.ANALYZER_ANOMALY_KEY, key)
                continue
            unpacker = Unpacker(use_list = False)
            unpacker.feed(raw_anomalies)
            for item in unpacker:
                anomalies.update(item)
        anomaly_list = []
        for anom, value in anomalies.iteritems():
                anomaly_list.append([value, anom])
        if len(anomaly_list) > 0:
            anomaly_list.sort(key=operator.itemgetter(1))
            resp = 'handle_data(%s)' % anomaly_list
    except Exception as e:
        logger.error("Error getting anomalies: %s" % str(e))
    return resp, 200
开发者ID:nevins-b,项目名称:skyline,代码行数:30,代码来源:webapp.py

示例5: ClientProtocol

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
class ClientProtocol(asyncio.Protocol):

    def __init__(self):
        self._cpt = -1
        self.packer = Unpacker()
        self._responses = dict()

    def connection_made(self, transport):
        print("connected")
        self.transport = transport

    def request(self, name, args, f):
        print("send request")
        self._cpt += 1
        self._responses[self._cpt] = f
        self.transport.write(packb([0, self._cpt, name, args]))


    def data_received(self, data):
        self.packer.feed(data)
        for msg in self.packer:
            if msg[0] == 1:
                self._responses[msg[1]].set_result(msg)

    def connection_lost(self, exc):
        pass
开发者ID:athoune,项目名称:aiomsgpack-rpc,代码行数:28,代码来源:async.py

示例6: test_foobar

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test_foobar():
    unpacker = Unpacker(read_size=3)
    unpacker.feed("foobar")
    assert unpacker.unpack() == ord(b"f")
    assert unpacker.unpack() == ord(b"o")
    assert unpacker.unpack() == ord(b"o")
    assert unpacker.unpack() == ord(b"b")
    assert unpacker.unpack() == ord(b"a")
    assert unpacker.unpack() == ord(b"r")
    try:
        o = unpacker.unpack()
        print "Oops!", o
        assert 0
    except StopIteration:
        assert 1
    else:
        assert 0
    unpacker.feed(b"foo")
    unpacker.feed(b"bar")

    k = 0
    for o, e in zip(unpacker, b"foobarbaz"):
        assert o == ord(e)
        k += 1
    assert k == len(b"foobar")
开发者ID:TSnake41,项目名称:msgpack,代码行数:27,代码来源:test_sequnpack.py

示例7: test3

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test3():
    start = 0
    end = 10

    metric = "marion.channel-0"

    raw_series = REDIS_CONN.get(settings.FULL_NAMESPACE + metric)
    if not raw_series:
        resp = json.dumps({'results': 'Error: No metric by that name'})
        return resp, 404
    else:
        unpacker = Unpacker(use_list = False)
        unpacker.feed(raw_series)
        timeseries = []

        point = {'x':datapoint[0],'y':datapoint[1]}

        if (start is None) and (end is not None):
            for datapoint in unpacker:
                if datapoint[0] < int(end):
                    timeseries.append(point)
        elif (start is not None) and (end is None):
            for datapoint in unpacker:
                if datapoint[0] > int(start):
                    timeseries.append(point)
        elif (start is not None) and (end is not None):
            for datapoint in unpacker:
                if (datapoint[0] > int(start)) and (datapoint[0] < int(end)):
                    timeseries.append(point)
        elif (start is None) and (end is None):
            timeseries = [{'x':datapoint[0],'y':datapoint[1]} for datapoint in unpacker]

        resp = json.dumps({'results': timeseries})
        return resp, 200
开发者ID:harlequinetcie,项目名称:cloudbrain,代码行数:36,代码来源:sandbox.py

示例8: test_foobar

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test_foobar():
    unpacker = Unpacker(read_size=3)
    unpacker.feed(b'foobar')
    assert unpacker.unpack() == ord(b'f')
    assert unpacker.unpack() == ord(b'o')
    assert unpacker.unpack() == ord(b'o')
    assert unpacker.unpack() == ord(b'b')
    assert unpacker.unpack() == ord(b'a')
    assert unpacker.unpack() == ord(b'r')
    try:
        o = unpacker.unpack()
        print(("Oops!", o))
        assert 0
    except StopIteration:
        assert 1
    else:
        assert 0
    unpacker.feed(b'foo')
    unpacker.feed(b'bar')

    k = 0
    for o, e in zip(unpacker, b'foobarbaz'):
        assert o == e
        k += 1
    assert k == len(b'foobar')
开发者ID:Keith-Redding,项目名称:msgpack,代码行数:27,代码来源:test_sequnpack.py

示例9: data

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def data():
    metric = request.args.get('metric', None)
    start = request.args.get('start', None)
    end = request.args.get('end', None)

    if metric is None:
        metrics = ['channel-0', 'channel-1', 'channel-2', 'channel-3', 'channel-4', 'channel-5', 'channel-6', 'channel-7']
    else:
        metrics = [metric]

    try:
        all_channels_data = []
        for metric in metrics:

            single_channel_data = {}

            raw_series = REDIS_CONN.get(settings.FULL_NAMESPACE + metric)
            if not raw_series:
                resp = json.dumps({'results': 'Error: No metric by that name'})
                return resp, 404
            else:
                unpacker = Unpacker(use_list = False)
                unpacker.feed(raw_series)
                timeseries = []

                if (start is None) and (end is not None):
                    for datapoint in unpacker:
                        if datapoint[0] < int(end):
                            point = {'x' : datapoint[0], 'y':datapoint[1]}
                            timeseries.append(point)
                elif (start is not None) and (end is None):
                    for datapoint in unpacker:
                        if datapoint[0] > int(start):
                            point = {'x' : datapoint[0], 'y':datapoint[1]}
                            timeseries.append(point)
                elif (start is not None) and (end is not None):
                    for datapoint in unpacker:
                        if (datapoint[0] > int(start)) and (datapoint[0] < int(end)):
                            point = {'x' : datapoint[0], 'y':datapoint[1]}
                            timeseries.append(point)
                elif (start is None) and (end is None):
                    timeseries = [{'x' : datapoint[0], 'y':datapoint[1]} for datapoint in unpacker]

                single_channel_data['key'] = metric
                single_channel_data['values'] = timeseries
                all_channels_data.append(single_channel_data)

        resp = json.dumps({'results': all_channels_data})
        return resp, 200

    except Exception as e:
        error = "Error: " + e
        resp = json.dumps({'results': error})
        return resp, 500

    except Exception as e:
        error = "Error: " + e
        resp = json.dumps({'results': error})
        return resp, 500
开发者ID:harlequinetcie,项目名称:cloudbrain,代码行数:61,代码来源:webapp.py

示例10: test_incorrect_type_nested_map

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test_incorrect_type_nested_map():
    unpacker = Unpacker()
    unpacker.feed(packb([{'a': 'b'}]))
    try:
        unpacker.read_map_header()
        assert 0, 'should raise exception'
    except UnexpectedTypeException:
        assert 1, 'okay'
开发者ID:Crazy4Tech,项目名称:msgpack-python,代码行数:10,代码来源:test_read_size.py

示例11: test_incorrect_type_array

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test_incorrect_type_array():
    unpacker = Unpacker()
    unpacker.feed(packb(1))
    try:
        unpacker.read_array_header()
        assert 0, 'should raise exception'
    except UnexpectedTypeException:
        assert 1, 'okay'
开发者ID:Crazy4Tech,项目名称:msgpack-python,代码行数:10,代码来源:test_read_size.py

示例12: test_correct_type_nested_array

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def test_correct_type_nested_array():
    unpacker = Unpacker()
    unpacker.feed(packb({"a": ["b", "c", "d"]}))
    try:
        unpacker.read_array_header()
        assert 0, "should raise exception"
    except UnexpectedTypeException:
        assert 1, "okay"
开发者ID:seliopou,项目名称:msgpack-python,代码行数:10,代码来源:test_read_size.py

示例13: mpdecode

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def mpdecode(iterable):
    unpacker = Unpacker(encoding='utf8')
    for chunk in iterable:
        unpacker.feed(chunk)
        # Each chunk can have none or many objects,
        # so here we dispatch any object ready
        for obj in unpacker:
            yield obj
开发者ID:scrapinghub,项目名称:python-hubstorage,代码行数:10,代码来源:serialization.py

示例14: setUp

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
    def setUp(self):
        address = 0xfa1afe1
        device = "LivewareProblem"

        raw_packet = encode_erase_flash_page(address, device)

        unpacker = Unpacker()
        unpacker.feed(raw_packet)
        self.command = list(unpacker)[1:]
开发者ID:antoinealb,项目名称:can-bootloader,代码行数:11,代码来源:test_commands.py

示例15: unpack_gen

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import feed [as 别名]
def unpack_gen(file, size):
   u = Unpacker()
   while True:
      data = file.read(size)
      if not data:
         break
      u.feed(data)
      for o in u:
         yield o
开发者ID:Aerobota,项目名称:PenguPilot,代码行数:11,代码来源:compare_msgpack.py


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