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


Python msgpack.loads函数代码示例

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


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

示例1: get_event_sensors

def get_event_sensors(rows, row_columns, start_time, stop_time, max_samples=None):
    """
    Returns:
        (event_sensors, sensor_names)
        event_sensors: Dict of type with value as a list of sensors
        sensor_names: Dict of type with value as name
    """
    event_sensors = {}  # [type] = values
    sensor_types = {}  # [name] = type
    for row in rows:
        print(row_columns[row].keys())
        try:
            sensor_types.update(msgpack.loads(row_columns[row]['meta:sensor_types']))
        except KeyError:
            continue
        for sensor_name, samples in msgpack.loads(row_columns[row]['meta:sensor_samples']).items():
            sensor_type = sensor_types[sensor_name]
            for s in samples:
                if not (start_time <= s[1] <= stop_time):
                    continue
                event_sensors.setdefault(sensor_type, []).append(s)
    sensor_names = {v: k for k, v in sensor_types.items()}  # [type] = name
    for t in event_sensors:
        event_sensors[t].sort(key=lambda x: x[1])
    if max_samples is not None:
        for t in event_sensors:
            if len(event_sensors[t]) < max_samples:
                continue
            skip = len(event_sensors[t]) / (max_samples - 1)
            event_sensors[t] = event_sensors[t][:-1:skip] + [event_sensors[t][-1]]
    return event_sensors, sensor_names
开发者ID:Kadajett,项目名称:wearscript,代码行数:31,代码来源:events.py

示例2: get

    def get(self, _type, key, key_path=None):
        k = self._key(_type, key)
        with self.index_lock:
            if not k in self.index:
                return None

        with self.locks[k]:
            if not key_path:
                # TODO: Should we do an extra copy?
                return msgpack.loads(self.caches[k])
            else:
                path = key_path.split('/')
                # Hard limit to avoid nasty lengthy requests
                if len(path) > 7 or len(path) < 1:
                    return None
                else:
                    cached = msgpack.loads(self.caches[k])
                    data = dict()
                    data['type'] = cached['type'] + '/' + key_path
                    data['key'] = cached['key']
                    data['timestamp'] = cached['data'].get('timestamp', None)

                    d = cached['data']
                    try:
                        d = reduce(lambda di, key: di.get(key, None), path, d)
                    except AttributeError:
                        d = None

                    if d:
                        data['data'] = d
                        return copy(data)
                    else:
                        return None
开发者ID:drums-project,项目名称:drums-daemon,代码行数:33,代码来源:drumsd.py

示例3: my_loads

def my_loads(header, frames):
    obj = MyObject(**msgpack.loads(frames[0], raw=False))

    # to provide something to test against, lets just attach the context to
    # the object itself
    obj.context = msgpack.loads(frames[1], raw=False)
    return obj
开发者ID:tomMoral,项目名称:distributed,代码行数:7,代码来源:test_serialize.py

示例4: load

    def load(data):
        r = Request()
        try:
            r.__dict__ = msgpack.loads(data, encoding="utf-8")
        except (UnicodeDecodeError):
            r.__dict__ = msgpack.loads(data, encoding="ISO-8859-1")

        return r
开发者ID:tarot,项目名称:requestbin,代码行数:8,代码来源:models.py

示例5: assert_packed_msg_equal

def assert_packed_msg_equal(b1, b2):
    """Assert that two packed msgpack messages are equal."""
    msg1 = msgpack.loads(b1, encoding='utf8')
    msg2 = msgpack.loads(b2, encoding='utf8')
    assert sorted(msg1.keys()) == sorted(msg2.keys())
    for (k1, v1), (k2, v2) in zip(sorted(msg1.items()), sorted(msg2.items())):
        assert k1 == k2
        assert v1 == v2
开发者ID:AvinashGupta,项目名称:spaCy,代码行数:8,代码来源:util.py

示例6: yield_api

def yield_api():
    try:
        chunk = yield s.enqueue('chunkMe', num)
        msgpack.loads(chunk)
        while True:
            ch = yield
            msgpack.loads(ch)
    except ChokeEvent:
        IOLoop.current().stop()
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:9,代码来源:speed.py

示例7: get_notify_data

 def get_notify_data(self, notify_id):
     try:
         ret = self.redis.hget(self.__hash_name__, notify_id)
         if ret is not None:
             _tmp = loads(ret) 
             log.debug('ct=%d|difftm=%d', _tmp['ct'], int(time.time()*1000)-_tmp['ct'])
             return loads(ret)['data']
     except Exception, e:
         log.warn(traceback.format_exc())
开发者ID:zs-2014,项目名称:util,代码行数:9,代码来源:notify_handler.py

示例8: _unpack_msgpack_snappy

def _unpack_msgpack_snappy(str):
    if str.startswith(b'S'):
        tmp = snappy.uncompress(str[1:])
        # print "SNAPPY: ", len(str), len(tmp)
        obj = msgpack.loads(tmp, encoding='utf-8')
    elif str.startswith(b'\0'):
        obj = msgpack.loads(str[1:], encoding='utf-8')
    else:
        return None
    
    return obj
开发者ID:raycool,项目名称:vnpy,代码行数:11,代码来源:jrpc_py.py

示例9: loads

 def loads(self, msg):
     '''
     Run the correct loads serialization format
     '''
     if self.serial == 'msgpack':
         return msgpack.loads(msg, use_list=True)
     elif self.serial == 'pickle':
         try:
             return pickle.loads(msg)
         except Exception:
             return msgpack.loads(msg, use_list=True)
开发者ID:DamianZaremba,项目名称:salt,代码行数:11,代码来源:payload.py

示例10: load_market_data

def load_market_data():
    try:
        fp_bm = get_datafile('benchmark.msgpack', "rb")
    except IOError:
        print """
data msgpacks aren't distribute with source.
Fetching data from Yahoo Finance.
""".strip()
        dump_benchmarks()
        fp_bm = get_datafile('benchmark.msgpack', "rb")

    bm_list = msgpack.loads(fp_bm.read())
    bm_returns = []
    for packed_date, returns in bm_list:
        event_dt = tuple_to_date(packed_date)
        #event_dt = event_dt.replace(
        #    hour=0,
        #    minute=0,
        #    second=0,
        #    tzinfo=pytz.utc
        #)

        daily_return = risk.DailyReturn(date=event_dt, returns=returns)
        bm_returns.append(daily_return)

    fp_bm.close()

    bm_returns = sorted(bm_returns, key=attrgetter('date'))

    try:
        fp_tr = get_datafile('treasury_curves.msgpack', "rb")
    except IOError:
        print """
data msgpacks aren't distribute with source.
Fetching data from data.treasury.gov
""".strip()
        dump_treasury_curves()
        fp_tr = get_datafile('treasury_curves.msgpack', "rb")

    tr_list = msgpack.loads(fp_tr.read())
    tr_curves = {}
    for packed_date, curve in tr_list:
        tr_dt = tuple_to_date(packed_date)
        #tr_dt = tr_dt.replace(hour=0, minute=0, second=0, tzinfo=pytz.utc)
        tr_curves[tr_dt] = curve

    fp_tr.close()

    tr_curves = OrderedDict(sorted(
                            ((dt, c) for dt, c in tr_curves.iteritems()),
                            key=lambda t: t[0]))

    return bm_returns, tr_curves
开发者ID:aichi,项目名称:zipline,代码行数:53,代码来源:factory.py

示例11: from_token

 def from_token(cls, token):
     if PY3:
         # The argument raw=False is only available on new versions of
         # msgpack, and only really needed on Python 3. Gate it behind
         # a PY3 check to avoid causing issues on Debian-packaged versions.
         decoded = msgpack.loads(decode_base64(token), raw=False)
     else:
         decoded = msgpack.loads(decode_base64(token))
     return RoomListNextBatch(**{
         cls.REVERSE_KEY_DICT[key]: val
         for key, val in decoded.items()
     })
开发者ID:matrix-org,项目名称:synapse,代码行数:12,代码来源:room_list.py

示例12: loads

    def loads(cls, data_str, msg_pack=False):
        if msg_pack:
            if isinstance(data_str, bytes):
                data = msgpack.loads(data_str, encoding='utf-8')
            else:
                data = msgpack.loads(data_str)
        else:
            data = json.loads(data_str)

        if isinstance(data, (list, tuple,)):
            return [cls.restore(d) for d in data]
        return cls.restore(data)
开发者ID:PushAMP,项目名称:strictdict3,代码行数:12,代码来源:strictdict.py

示例13: test_compare

 def test_compare(self):
     for x in glob.glob("picarus_takeout_models/test_models/picarus-*.msgpack.gz"):
         print(x)
         m0 = PicarusModel(x)
         m1 = PicarusCommandModel(x)
         for y in glob.glob("picarus_takeout_models/test_images/*"):
             outm0 = m0.process_binary(y)
             outm1 = m1.process_binary(y)
             if outm0 != outm1:
                 print(msgpack.loads(outm0))
                 print(msgpack.loads(outm1))
             self.assertEqual(outm0, outm1)
开发者ID:bwhite,项目名称:picarus_takeout,代码行数:12,代码来源:test_models.py

示例14: _unpack

def _unpack(str) :

    if str[0] == 'S':
        tmp = snappy.uncompress(str[1:])
        obj = msgpack.loads(tmp)
    elif str[0] == '\0':
        obj = msgpack.loads(str[1:])
    else:
        return None

    #print "UNPACK", obj
    return obj
开发者ID:GenesisOrg,项目名称:vnpy,代码行数:12,代码来源:jrpc_server.py

示例15: fetchAll

 def fetchAll():
     chunk = yield service.enqueue('chunkMe', str(sys.argv[1]))
     chunk = msgpack.loads(chunk)
     size = len(chunk)
     counter = 0
     while True:
         ch = yield
         chunk = msgpack.loads(ch)
         size += len(chunk)
         counter += 1
         print(counter, len(chunk), size)
         if chunk == 'Done':
             break
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:13,代码来源:check.py


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