本文整理汇总了Python中msgpack.unpackb方法的典型用法代码示例。如果您正苦于以下问题:Python msgpack.unpackb方法的具体用法?Python msgpack.unpackb怎么用?Python msgpack.unpackb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msgpack
的用法示例。
在下文中一共展示了msgpack.unpackb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __unchunk
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def __unchunk(self, new_message, worker_name):
new = msgpack.unpackb(new_message, encoding='utf-8', use_list=False)
# If we don't have a chunking type, it's probably an old-style message.
if not 'chunk-type' in new:
return new
# Messages smaller then the chunk_size are not split, and can just be returned.
if new['chunk-type'] == "complete-message":
assert 'chunk-type' in new
assert 'data' in new
return new['data']
elif new['chunk-type'] == "chunked-message":
return self.__process_chunk(new, worker_name)
else:
raise RuntimeError("Unknown message type: %s", new['chunk-type'])
示例2: get_available_jobs
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def get_available_jobs(self):
ret = []
for job_netloc, key_dict in self.url_throttler.items():
try:
# Allow unlimited fetching if the site isn't erroring at all
while key_dict['active_fetches'] <= key_dict['status_accumulator']:
# ret.append(item['job_queue'].get(block=False))
item_b = self.redis.lpop(self.__netloc_to_key(job_netloc))
if not item_b: # Nothing in queue
break
item = msgpack.unpackb(item_b, use_list=False, raw=False)
ret.append(item)
key_dict['active_fetches'] += 1
self.total_queued -= 1
except queue.Empty:
pass
self.log.info("Extracted %s jobs from rate-limiting queues.", len(ret))
return ret
示例3: _request
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def _request(self, message):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(self.server_address)
sock.send(msgpack.packb(message, use_bin_type=True))
buff = bytes()
while True:
block = sock.recv(128)
if not block:
break
buff += block
resp = msgpack.unpackb(buff, encoding='utf-8')
sock.close()
if 'type' in resp and resp['type'] == 'redirect':
self.server_address = tuple(resp['leader'])
resp = self._request(message)
return resp
示例4: wait
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def wait(self):
results = []
print
"selecting"
r, w, e = select.select(self.clients, (), ())
for sock_ready in r:
if sock_ready == self.listener:
print
"accepting new client"
c = self.listener.accept()
self.clients.append(c)
else:
try:
msg = sock_ready.recv_bytes()
msg = msgpack.unpackb(msg)
results.append((sock_ready, msg))
# print "received {}".format(msg)
except EOFError:
print
"closing"
sock_ready.close()
self.clients.remove(sock_ready)
return results
示例5: test_pex_manylinux_runtime
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def test_pex_manylinux_runtime():
"""Tests resolver manylinux support and runtime resolution (and --platform=current)."""
test_stub = dedent(
"""
import msgpack
print(msgpack.unpackb(msgpack.packb([1, 2, 3])))
"""
)
with temporary_content({'tester.py': test_stub}) as output_dir:
pex_path = os.path.join(output_dir, 'test.pex')
tester_path = os.path.join(output_dir, 'tester.py')
results = run_pex_command(['--disable-cache',
'--no-build',
'msgpack-python==0.4.7',
'--platform=current',
'-o', pex_path])
results.assert_success()
out = subprocess.check_output([pex_path, tester_path])
assert out.strip() == '[1, 2, 3]'
示例6: test_enqueue_payload_encode_decode
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def test_enqueue_payload_encode_decode(self):
job_id = self._get_job_id()
response = self.queue.enqueue(
payload=self._test_payload_1,
interval=10000, # 10s (10000ms)
job_id=job_id,
queue_id=self._test_queue_id,
queue_type=self._test_queue_type,
)
payload_map_name = '%s:payload' % (self.queue._key_prefix)
payload_map_key = '%s:%s:%s' % (
self._test_queue_type, self._test_queue_id, job_id)
raw_payload = self.queue._r.hget(payload_map_name, payload_map_key)
# decode the payload from msgpack to dictionary
payload = msgpack.unpackb(raw_payload[1:-1])
self.assertEqual(payload, self._test_payload_1)
示例7: downgrade
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def downgrade():
conn = op.get_bind()
temp_log_table = op.create_table(
'temp_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('result_id', sa.Integer(), nullable=True),
sa.Column('data', sa.String(length=1024), nullable=True),
sa.ForeignKeyConstraint(['result_id'], ['result.id'], ),
sa.PrimaryKeyConstraint('id'))
res = conn.execute('SELECT id, result_id, data FROM log')
results = res.fetchall()
if len(results) > 0:
modified_logs = [{
'id': r[0],
'result_id': r[1],
'data': json.dumps(msgpack.unpackb(r[2], raw=False))}
for r in results]
op.bulk_insert(temp_log_table, modified_logs)
op.drop_table('log')
op.rename_table('temp_log', 'log')
示例8: serialize
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def serialize(self):
"""serialize."""
log_dict = {}
data = msgpack.unpackb(self.data, raw=False)
for item in data.items():
value_to_store = (
None
if not isinstance(item[1], numbers.Number)
or isinf(item[1])
or isnan(item[1])
else item[1]
)
log_dict[item[0]] = value_to_store
return {
'id': self.id,
'resultId': self.result_id,
'logDict': log_dict
}
示例9: fetch_by_name
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def fetch_by_name(self, name):
import requests
logger.debug("Requesting info about entry named '%s'", name)
params = {'name': name}
http_args = self._get_http_args(params)
response = requests.get(self.source_url, **http_args)
if response.status_code == 404:
raise KeyError(name)
try:
response.raise_for_status()
except requests.HTTPError as err:
raise RemoteCatalogError(
"Failed to fetch entry {!r}.".format(name)) from err
info = msgpack.unpackb(response.content, **unpack_kwargs)
return RemoteCatalogEntry(
url=self.url,
getenv=self.getenv,
getshell=self.getshell,
auth=self.auth,
http_args=self.http_args,
page_size=self._page_size,
**info['source'])
示例10: search
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def search(self, *args, **kwargs):
import requests
request = {'action': 'search', 'query': (args, kwargs),
'source_id': self._source_id}
response = requests.post(
url=self.source_url, **self._get_http_args({}),
data=msgpack.packb(request, **pack_kwargs))
try:
response.raise_for_status()
except requests.HTTPError as err:
raise RemoteCatalogError("Failed search query.") from err
source = msgpack.unpackb(response.content, **unpack_kwargs)
source_id = source['source_id']
cat = RemoteCatalog(
url=self.url,
http_args=self.http_args,
source_id=source_id,
name="")
cat.cat = self
return cat
示例11: resolve_types
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def resolve_types(self, ret):
if not self.pipeline_mode:
try:
key_with_types = msgpack.unpackb(self.resolve_types_script(ret))
except ResponseError as e:
if "CROSSSLOT" not in repr(e):
raise e
key_with_types = self.resolve_with_pipe(ret)
self.pipeline_mode = True
else:
key_with_types = self.resolve_with_pipe(ret)
for i in range(0, len(ret)):
yield key_with_types[i], ret[i]
ret.clear()
示例12: raw_decode
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def raw_decode(cls, data, content_encoding=None):
content_encoding = ContentEncoding.of(content_encoding)
if content_encoding.is_gzip:
try:
data = gzip.decompress(data)
except (ValueError, TypeError):
raise ActorMessageDecodeError('gzip decompress failed')
try:
if content_encoding.is_json:
data = json.loads(data.decode('utf-8'))
else:
data = msgpack.unpackb(data, raw=False)
except json.JSONDecodeError:
raise ActorMessageDecodeError('json decode failed')
except msgpack.UnpackException:
raise ActorMessageDecodeError('msgpack decode failed')
return data
示例13: proxy_receive
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def proxy_receive(cls, connection):
str_success = connection.recv(1)
if len(str_success) != 1:
raise TensorforceError.unexpected()
success = bool(str_success)
str_num_bytes = connection.recv(8)
if len(str_num_bytes) != 8:
raise TensorforceError.unexpected()
num_bytes = int(str_num_bytes.decode())
str_result = b''
for n in range(num_bytes // cls.MAX_BYTES):
str_result += connection.recv(cls.MAX_BYTES)
if len(str_result) != n * cls.MAX_BYTES:
raise TensorforceError.unexpected()
str_result += connection.recv(num_bytes % cls.MAX_BYTES)
if len(str_result) != num_bytes:
raise TensorforceError.unexpected()
result = msgpack.unpackb(packed=str_result)
decode = (lambda x: x.decode() if isinstance(x, bytes) else x)
result = util.fmap(function=decode, xs=result, map_keys=True)
return success, result
示例14: loads
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def loads(s, **kwargs):
""" An overload of msgpack.loads that works with pyGSTi types """
decoded_msgpack = _msgpack.unpackb(s, **kwargs) # load normal MSGPACK
return decode_obj(decoded_msgpack, msgpack_uses_binary_strs) # makes pygsti objects
示例15: loadsCall
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import unpackb [as 别名]
def loadsCall(self, data):
return msgpack.unpackb(self._convertToBytes(data), raw=False, object_hook=self.object_hook)