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


Python msgpack.loads方法代码示例

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


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

示例1: msgpackext_loads

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def msgpackext_loads(data: bytes) -> Any:
    """Deserializes a msgpack byte representation of known objects into those objects.

    Parameters
    ----------
    data : bytes
        The serialized msgpack byte array.

    Returns
    -------
    Any
        The deserialized Python objects.
    """
    which_import("msgpack", raise_error=True, raise_msg=_msgpack_which_msg)

    return msgpack.loads(data, object_hook=msgpackext_decode, raw=False)


## JSON Ext 
开发者ID:MolSSI,项目名称:QCElemental,代码行数:21,代码来源:serialization.py

示例2: jsonext_loads

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def jsonext_loads(data: Union[str, bytes]) -> Any:
    """Deserializes a json representation of known objects into those objects.

    Parameters
    ----------
    data : str or bytes
        The byte-serialized JSON blob.

    Returns
    -------
    Any
        The deserialized Python objects.
    """

    return json.loads(data, object_hook=jsonext_decode)


## JSON 
开发者ID:MolSSI,项目名称:QCElemental,代码行数:20,代码来源:serialization.py

示例3: json_loads

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def json_loads(data: str) -> Any:
    """Deserializes a json representation of known objects into those objects.

    Parameters
    ----------
    data : str
        The serialized JSON blob.

    Returns
    -------
    Any
        The deserialized Python objects.
    """

    # Doesn't hurt anything to try to load JSONext as well
    return json.loads(data, object_hook=jsonext_decode)


## Helper functions 
开发者ID:MolSSI,项目名称:QCElemental,代码行数:21,代码来源:serialization.py

示例4: do_POST

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def do_POST(self):
		if not self.check_authorization():
			self.respond_unauthorized(request_authentication=True)
			return
		content_length = int(self.headers.get('content-length', 0))
		data = self.rfile.read(content_length)
		self.raw_query_data = data
		content_type = self.headers.get('content-type', '')
		content_type = content_type.split(';', 1)[0]
		self.query_data = {}
		try:
			if not isinstance(data, str):
				data = data.decode(self.get_content_type_charset())
			if content_type.startswith('application/json'):
				data = json.loads(data)
				if isinstance(data, dict):
					self.query_data = dict([(i[0], [i[1]]) for i in data.items()])
			else:
				self.query_data = urllib.parse.parse_qs(data, keep_blank_values=1)
		except Exception:
			self.respond_server_error(400)
		else:
			self.dispatch_handler(self.query_data)
		return 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:26,代码来源:advancedhttpserver.py

示例5: loads

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def loads(self, data):
		"""
		Deserialize the data into it's original python object.

		:param bytes data: The serialized object to load.
		:return: The original python object.
		"""
		if not isinstance(data, bytes):
			raise TypeError("loads() argument 1 must be bytes, not {0}".format(type(data).__name__))
		if self._compression == 'zlib':
			data = zlib.decompress(data)
		if sys.version_info[0] == 3 and self.name.startswith('application/'):
			data = data.decode(self._charset)
		data = g_serializer_drivers[self.name]['loads'](data, (self._charset if sys.version_info[0] == 3 else None))
		if isinstance(data, list):
			data = tuple(data)
		return data 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:19,代码来源:advancedhttpserver.py

示例6: load

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def load(cls, bmessage):
        """
        From a bytestring given by a (distant) call to Message.dump(), retrieve the original message
        :param bmessage: bytestring given by a .dump() call on a message
        :return: the original message
        """
        message_dict = msgpack.loads(bmessage, use_list=False)

        try:
            obj = MessageMeta._registered_messages[message_dict["type"]].__new__(MessageMeta._registered_messages[message_dict["type"]])
            object.__setattr__(obj, "__dict__", message_dict)
        except:
            raise TypeError("Unknown message type") from None

        if not obj._verify():  # pylint: disable=protected-access
            raise TypeError("Invalid message content")

        return obj 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:20,代码来源:message_meta.py

示例7: load

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def load(self):
        try:
            with open(self.store_file, "rb") as fp:
                data = fp.read()
                data = msgpack.loads(data)
                self.plans = {}
                for plan in data.get(b"plans", []):
                    plan = Plan.loads(plan)
                    self.plans[plan.key] = plan

                self.time_plans = defaultdict(dict)
                for key, plans in data.get(b"time_plans", {}).items():
                    self.time_plans[key] = {}
                    for plan_key in (plans or []):
                        if not isinstance(plan_key, unicode_type):
                            plan_key = unicode_type(plan_key, "utf-8")

                        if plan_key in self.plans:
                            self.time_plans[key][plan_key] = self.plans[plan_key]

                current_time = data.get(b"current_time")
                self.current_time = current_time if current_time and current_time > 0 else self.current_time
            logging.info("store mem load session %s", self.store_file)
        except Exception as e:
            logging.error("store mem load session error: %s %s", self.store_file, e) 
开发者ID:snower,项目名称:forsun,代码行数:27,代码来源:mem.py

示例8: test_json

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def test_json(self):
        ts = msprime.simulate(10, random_seed=1)
        tables = ts.dump_tables()
        nodes = tables.nodes
        # For each node, we create some Python metadata that can be JSON encoded.
        metadata = [
            {"one": j, "two": 2 * j, "three": list(range(j))} for j in range(len(nodes))
        ]
        encoded, offset = tskit.pack_strings(map(json.dumps, metadata))
        nodes.set_columns(
            flags=nodes.flags,
            time=nodes.time,
            population=nodes.population,
            metadata_offset=offset,
            metadata=encoded,
        )
        self.assertTrue(np.array_equal(nodes.metadata_offset, offset))
        self.assertTrue(np.array_equal(nodes.metadata, encoded))
        ts1 = tables.tree_sequence()
        for j, node in enumerate(ts1.nodes()):
            decoded_metadata = json.loads(node.metadata.decode())
            self.assertEqual(decoded_metadata, metadata[j])
        ts1.dump(self.temp_file)
        ts2 = tskit.load(self.temp_file)
        self.assertEqual(ts1.tables.nodes, ts2.tables.nodes) 
开发者ID:tskit-dev,项目名称:tskit,代码行数:27,代码来源:test_metadata.py

示例9: test_pickle

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def test_pickle(self):
        ts = msprime.simulate(10, random_seed=1)
        tables = ts.dump_tables()
        # For each node, we create some Python metadata that can be pickled
        metadata = [
            {"one": j, "two": 2 * j, "three": list(range(j))}
            for j in range(ts.num_nodes)
        ]
        encoded, offset = tskit.pack_bytes(list(map(pickle.dumps, metadata)))
        tables.nodes.set_columns(
            flags=tables.nodes.flags,
            time=tables.nodes.time,
            population=tables.nodes.population,
            metadata_offset=offset,
            metadata=encoded,
        )
        self.assertTrue(np.array_equal(tables.nodes.metadata_offset, offset))
        self.assertTrue(np.array_equal(tables.nodes.metadata, encoded))
        ts1 = tables.tree_sequence()
        for j, node in enumerate(ts1.nodes()):
            decoded_metadata = pickle.loads(node.metadata)
            self.assertEqual(decoded_metadata, metadata[j])
        ts1.dump(self.temp_file)
        ts2 = tskit.load(self.temp_file)
        self.assertEqual(ts1.tables.nodes, ts2.tables.nodes) 
开发者ID:tskit-dev,项目名称:tskit,代码行数:27,代码来源:test_metadata.py

示例10: test_mutations

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def test_mutations(self):
        tables = tskit.TableCollection(sequence_length=1)
        metadata = ExampleMetadata(one="node1", two="node2")
        pickled = pickle.dumps(metadata)
        tables.nodes.add_row(time=0)
        tables.sites.add_row(position=0.1, ancestral_state="A")
        tables.mutations.add_row(site=0, node=0, derived_state="T", metadata=pickled)
        ts = tables.tree_sequence()
        mutation = ts.site(0).mutations[0]
        self.assertEqual(mutation.site, 0)
        self.assertEqual(mutation.node, 0)
        self.assertEqual(mutation.derived_state, "T")
        self.assertEqual(mutation.metadata, pickled)
        unpickled = pickle.loads(mutation.metadata)
        self.assertEqual(unpickled.one, metadata.one)
        self.assertEqual(unpickled.two, metadata.two) 
开发者ID:tskit-dev,项目名称:tskit,代码行数:18,代码来源:test_metadata.py

示例11: send

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def send(hub, worker, payload):
    '''
    Send the given payload to the given worker, yield iterations based on the
    returns from the remote.
    '''
    mp = msgpack.dumps(payload, use_bin_type=True)
    mp += hub.proc.DELIM
    reader, writer = await asyncio.open_unix_connection(path=worker['path'])
    writer.write(mp)
    await writer.drain()
    final_ret = True
    while True:
        ret = await reader.readuntil(hub.proc.DELIM)
        p_ret = ret[:-len(hub.proc.DELIM)]
        i_flag = p_ret[-1:]
        ret = msgpack.loads(p_ret[:-1], raw=False)
        if i_flag == hub.proc.D_FLAG:
            # break for the end of the sequence
            break
        yield ret
        final_ret = False
    if final_ret:
        yield ret 
开发者ID:saltstack,项目名称:pop,代码行数:25,代码来源:run.py

示例12: un

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def un(byts):
    '''
    Use msgpack to de-serialize a python object.

    Args:
        byts (bytes): The bytes to de-serialize

    Notes:
        String objects are decoded using utf8 encoding.  In order to handle
        potentially malformed input, ``unicode_errors='surrogatepass'`` is set
        to allow decoding bad input strings.

    Returns:
        obj: The de-serialized object
    '''
    # This uses a subset of unpacker_kwargs
    return msgpack.loads(byts, use_list=False, raw=False, unicode_errors='surrogatepass') 
开发者ID:vertexproject,项目名称:synapse,代码行数:19,代码来源:msgpack.py

示例13: add_to_refmap

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def add_to_refmap(self, result: ResultStorer) -> None:
        """
        :param result: the result of the compare function

        This method verifies whether the comparison in input is the best available for the
        candidate reference gene, and loads it into the refmap dictionary if such is the case.

        """

        if result is not None and result.ccode != ("u",):
            gid, tid = result.ref_gene[0], result.ref_id[0]
            if gid not in self.gene_matches:
                self.gene_matches[gid] = dict()
            if tid not in self.gene_matches[gid]:
                self.gene_matches[gid][tid] = list()
            self.gene_matches[gid][tid].append(result)
        return 
开发者ID:EI-CoreBioinformatics,项目名称:mikado,代码行数:19,代码来源:assigner.py

示例14: loads

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def loads(buf):
        """
        Args:
            buf: the output of `dumps`.
        """
        # Since 0.6, the default max size was set to 1MB.
        # We change it to approximately 1G.
        return msgpack.loads(buf, raw=False,
                             max_bin_len=MAX_MSGPACK_LEN,
                             max_array_len=MAX_MSGPACK_LEN,
                             max_map_len=MAX_MSGPACK_LEN,
                             max_str_len=MAX_MSGPACK_LEN) 
开发者ID:tensorpack,项目名称:dataflow,代码行数:14,代码来源:serialize.py

示例15: load

# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import loads [as 别名]
def load(cls, file_h, *args, **kwargs):
		"""
		Load encoded data from the specified file.

		:param file file_h: The file to read and load encoded data from.
		:param bool strict: Do not try remove trailing commas from the JSON data.
		:return: The Python object represented by the encoded data.
		"""
		return cls.loads(file_h.read(), *args, **kwargs) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:11,代码来源:serializers.py


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