How to use the msgpack.loads function in msgpack

To help you get started, we’ve selected a few msgpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enigmampc / catalyst / tests / test_mongods.py View on Github external
coll.insert(mock_raw_event(1, i))
            
            start_date = 20
            end_date = 50
            filter = {'sid' : [1]}
            args = (coll, filter, start_date, end_date)
            
            cursor = create_pymongo_iterator(*args)
            # We filter to only get dt's between 20 and 50
            expected = (mock_raw_event(1, i) for i in xrange(20, 51))
            
            # Assert that our iterator returns the expected values.
            for cursor_event, expected_event in izip_longest(cursor, expected):
                del cursor_event['_id']
                # Easiest way to convert unicode to strings.
                cursor_event = msgpack.loads(msgpack.dumps(cursor_event))
                assert expected_event.keys() == cursor_event.keys()
                assert expected_event.values() == cursor_event.values()
github saltstack / salt / salt / transport / road / raet / stacking.py View on Github external
kind = raeting.PACK_KINDS[kind]
        if kind == raeting.packKinds.json:
            body = json.loads(back, object_pairs_hook=odict)
            if not isinstance(body, Mapping):
                emsg = "Message body not a mapping\n"
                console.terse(emsg)
                self.incStat("invalid_receive_body")
                return  None
        elif kind == raeting.packKinds.pack:
            if not msgpack:
                emsg = "Msgpack not installed\n"
                console.terse(emsg)
                self.incStat("invalid_receive_serialization")
                return None
            body = msgpack.loads(back, object_pairs_hook=odict)
            if not isinstance(body, Mapping):
                emsg = "Message body not a mapping\n"
                console.terse(emsg)
                self.incStat("invalid_receive_body")
                return None

        return body
github saltstack / raet / raet / lane / paging.py View on Github external
pk = self.page.data['pk']

        if pk not in list(PackKind):
            emsg = "Unrecognizable page body."
            raise raeting.PageError(emsg)

        if pk == PackKind.json:
            if self.packed:
                self.data = json.loads(self.packed.decode('utf-8'),
                                       object_pairs_hook=odict)
        elif pk == PackKind.pack:
            if self.packed:
                if not msgpack:
                    emsg = "Msgpack not installed."
                    raise raeting.PacketError(emsg)
                self.data = msgpack.loads(self.packed,
                                          object_pairs_hook=odict,
                                          encoding='utf-8')

        if not isinstance(self.data, Mapping):
            emsg = "Message body not a mapping\n"
            console.terse(emsg)
            raise raeting.PageError(emsg)
github pyacq / pyacq / example / example_with_fake_device / multiple_acq_qt4.py View on Github external
def run(self):
        self.running = True
        while self.running:
            message = self.socket.recv()
            pos = msgpack.loads(message)
            self.newpacket.emit(self.port, pos)
github saltstack / pop / pop / mods / proc / worker.py View on Github external
async def ret(hub, payload):
    '''
    Send a return payload to the spawning process. This return will be tagged
    with the index of the process that returned it
    '''
    payload = {'ind': hub.proc.IND, 'payload': payload}
    mp = msgpack.dumps(payload, use_bin_type=True)
    mp += hub.proc.DELIM
    reader, writer = await asyncio.open_unix_connection(path=hub.proc.RET_SOCK_PATH)
    writer.write(mp)
    await writer.drain()
    ret = await reader.readuntil(hub.proc.DELIM)
    ret = ret[:-len(hub.proc.DELIM)]
    writer.close()
    return msgpack.loads(ret, encoding='utf8')
github bwhite / picarus / server / tables.py View on Github external
def _takeout_input_model_link_from_key(manager, key):
    model_binary, columns = key_to_model(manager, key, 'link')
    model = msgpack.loads(model_binary)
    if not isinstance(model, dict):
        bottle.abort(500)
    return columns['input'], model
github Megvii-CSG / MegReader / data / unpack_msgpack_data.py View on Github external
def convert(self, data):
        obj = msgpack.loads(data, max_str_len=2 ** 31)
        return self.convert_obj(obj)
github EI-CoreBioinformatics / mikado / Mikado / scales / assigner.py View on Github external
use_list=False,
                                                            strict_map_key=False,
                                                            object_hook=msgpack_convert))
                done.add(tmap_row.tid)
                self.print_tmap(tmap_row)

        for gid, gene_match in cursor.execute("SELECT * from gene_matches"):
            gene_match = msgpack.loads(gene_match, raw=False, use_list=False,
                                       strict_map_key=False, object_hook=msgpack_convert)
            for tid in gene_match:
                for match in gene_match[tid]:
                    self.gene_matches[gid][tid].append(match)

        temp_stats = Namespace()
        for attr, stat in cursor.execute("SELECT * from stats"):
            setattr(temp_stats, attr, msgpack.loads(stat, raw=False,
                                                    use_list=False,
                                                    strict_map_key=False,
                                                    object_hook=msgpack_convert))

        self.stat_calculator.merge_into(temp_stats)
        os.remove(dbname)
        self.done += len(done)
github PacificBiosciences / FALCON / falcon_kit / io.py View on Github external
def read_as_msgpack(stream):
    import msgpack
    content = stream.read()
    log('  Read {} as msgpack'.format(eng(len(content))))
    return msgpack.loads(content)
github pyacq / pyacq / example / emotiv_example / simple_emotiv.py View on Github external
def test_recv_loop(port, stop_recv):
    print 'start receiver loop' , port
    context = zmq.Context()
    socket = context.socket(zmq.SUB)
    socket.setsockopt(zmq.SUBSCRIBE,'')
    socket.connect("tcp://localhost:{}".format(port))
    while stop_recv.value==0:
        message = socket.recv()
        pos = msgpack.loads(message)
        print 'On port {} read pos is {}'.format(port, pos)
    print 'stop receiver'