本文整理汇总了Python中msgpack.packb方法的典型用法代码示例。如果您正苦于以下问题:Python msgpack.packb方法的具体用法?Python msgpack.packb怎么用?Python msgpack.packb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msgpack
的用法示例。
在下文中一共展示了msgpack.packb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_job
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def put_job(self, row_id, job_url, job_netloc):
self.__check_init_nl(job_netloc)
self.log.info("Putting limited job for netloc %s (%s items, score: %s, active: %s)",
job_netloc,
self.redis.llen(self.__netloc_to_key(job_netloc)),
self.url_throttler[job_netloc]['status_accumulator'],
self.url_throttler[job_netloc]['active_fetches'])
# if self.fifo_limit is None or self.url_throttler[job_netloc]['job_queue'].qsize() < self.fifo_limit:
# self.url_throttler[job_netloc]['job_queue'].put((row_id, job_url, job_netloc))
item_b = msgpack.packb((row_id, job_url, job_netloc), use_bin_type=True)
self.redis.rpush(self.__netloc_to_key(job_netloc), item_b)
# self.url_throttler[job_netloc]['job_queue'].put((row_id, job_url, job_netloc))
self.total_queued += 1
示例2: _request
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [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
示例3: upgrade
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def upgrade():
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.LargeBinary(length=2048), 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': msgpack.packb(json.loads(r[2]), use_bin_type=True)}
for r in results]
op.bulk_insert(temp_log_table, modified_logs)
op.drop_table('log')
op.rename_table('temp_log', 'log')
示例4: search
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [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
示例5: encode
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def encode(self, obj, container):
from ..compat import np_pack_kwargs
if container in ['ndarray', 'xarray'] and msgpack_numpy:
return msgpack.packb(obj, **np_pack_kwargs)
elif container == 'dataframe':
# Use pyarrow for serializing DataFrames, rather than
# msgpack: https://github.com/intake/intake/issues/460
pa = check_pyarrow()
context = pa.default_serialization_context()
# This eventually goes to msgpack.packb, which doesn't
# directly accept PyArrow Buffer objects. Need to wrap
# it in a memoryview to avoid a TypeError.
return memoryview(context.serialize(obj).to_buffer())
else:
return msgpack.packb(obj, **pack_kwargs)
示例6: publish_payload
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def publish_payload(self, payload, topic=''):
"""
This method will publish a python_banyan payload and its associated topic
:param payload: Protocol message to be published
:param topic: A string value
"""
# make sure the topic is a string
if not type(topic) is str:
raise TypeError('Publish topic must be python_banyan string', 'topic')
# create python_banyan message pack payload
if self.numpy:
message = msgpack.packb(payload, default=m.encode)
else:
message = msgpack.packb(payload, use_bin_type=True)
pub_envelope = topic.encode()
self.publisher.send_multipart([pub_envelope, message])
示例7: notify
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def notify(cls, channel, event, args):
try:
channel = int(channel)
if channel not in cls.channel_sockets:
logger.info("channel[%s] not in NvimHandler", channel)
return
sock = cls.channel_sockets[channel]['sock']
# notification format:
# - msg[0] type, which is 2
# - msg[1] method
# - msg[2] arguments
content = [2, event, args]
logger.info("notify channel[%s]: %s", channel, content)
packed = msgpack.packb(neovim_rpc_protocol.to_client(content))
sock.send(packed)
except Exception as ex:
logger.exception("notify failed: %s", ex)
示例8: request
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def request(cls, vimsock, channel, reqid, event, args, rspid):
try:
reqid = int(reqid)
channel = int(channel)
chinfo = cls.channel_sockets[channel]
if channel not in cls.channel_sockets:
logger.info("channel[%s] not in NvimHandler", channel)
return
sock = chinfo['sock']
# request format:
# - msg[0] type, which is 0
# - msg[1] request id
# - msg[2] method
# - msg[3] arguments
content = [0, reqid, event, args]
chinfo[reqid] = [rspid, vimsock]
logger.info("request channel[%s]: %s", channel, content)
packed = msgpack.packb(neovim_rpc_protocol.to_client(content))
sock.send(packed)
except Exception as ex:
logger.exception("request failed: %s", ex)
示例9: _to_byte_array
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def _to_byte_array(structure, compressed):
'''Returns an MMTF-encoded byte array with optional gzip compression
Returns
-------
list
MMTF encoded and optionally gzipped structure data
'''
byte_array = bytearray(msgpack.packb(structure.input_data, use_bin_type=True))
#byte_array = bytearray(msgpack.packb(MMTFEncoder.encode_data(structure), use_bin_type = True))
if compressed:
return gzip.compress(byte_array)
else:
return byte_array
示例10: handle_slave_send
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def handle_slave_send(socket, address, req):
message = req['data']
message_id = message.get('message_id', '?')
message['to_slave'] = True
try:
runtime = send_funcs['message_send_enqueue'](message)
response = 'OK'
access_logger.info('Message (ID %s) from master %s queued successfully', message_id, address)
except Exception:
response = 'FAIL'
logger.exception('Queueing message (ID %s) from master %s failed.')
access_logger.error('Failed queueing message (ID %s) from master %s: %s', message_id, address, runtime)
metrics.incr('slave_message_send_fail_cnt')
socket.sendall(msgpack.packb(response))
示例11: dumps
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def dumps(obj, **kwargs):
""" An overload of msgpack.dumps that works with pyGSTi types """
enc = encode_obj(obj, msgpack_uses_binary_strs)
return _msgpack.packb(enc, **kwargs)
示例12: dumpsCall
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def dumpsCall(self, obj, method, vargs, kwargs):
return msgpack.packb((obj, method, vargs, kwargs), use_bin_type=True, default=self.default)
示例13: dumps
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def dumps(self, data):
return msgpack.packb(data, use_bin_type=True, default=self.default)
示例14: _serialize_message
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def _serialize_message(cls, msg):
return msgpack.packb(cls._serialize_internal(msg), use_bin_type=True, encoding='utf-8')
示例15: encode
# 需要导入模块: import msgpack [as 别名]
# 或者: from msgpack import packb [as 别名]
def encode(self, buf):
buf = np.asarray(buf)
items = buf.tolist()
items.append(buf.dtype.str)
items.append(buf.shape)
return msgpack.packb(items, use_bin_type=self.use_bin_type,
use_single_float=self.use_single_float)