本文整理汇总了Python中umsgpack.packb方法的典型用法代码示例。如果您正苦于以下问题:Python umsgpack.packb方法的具体用法?Python umsgpack.packb怎么用?Python umsgpack.packb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类umsgpack
的用法示例。
在下文中一共展示了umsgpack.packb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keybase_sign
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def keybase_sign(keyhex):
signing_keybytes = from_hex(keyhex)
signingkey = nacl.signing.SigningKey(signing_keybytes)
verify_keybytes = signingkey.verify_key.encode()
plainbytes = read_from_stdin()
attached_sig = signingkey.sign(plainbytes)
detatched_sig = attached_sig[:NACL_SIG_LEN]
# This is the signature format currently used by Keybase's servers. See the
# comments in keybase_verify().
blob = {
'body': {
'payload': plainbytes,
'key': b'\x01\x20' + verify_keybytes + b'\x0a',
'sig': detatched_sig,
'detached': True,
'sig_type': 32,
'hash_type': 10
},
'tag': 514,
'version': 1,
}
sig_msgpack_bytes = umsgpack.packb(blob)
sig_base64 = base64.b64encode(sig_msgpack_bytes)
write_to_stdout(sig_base64)
示例2: xmlrpc_run
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def xmlrpc_run(self, port=24444, bind='127.0.0.1', logRequests=False):
'''Run xmlrpc server'''
import umsgpack
from pyspider.libs.wsgi_xmlrpc import WSGIXMLRPCApplication
try:
from xmlrpc.client import Binary
except ImportError:
from xmlrpclib import Binary
application = WSGIXMLRPCApplication()
application.register_function(self.quit, '_quit')
application.register_function(self.size)
def sync_fetch(task):
result = self.sync_fetch(task)
result = Binary(umsgpack.packb(result))
return result
application.register_function(sync_fetch, 'fetch')
def dump_counter(_time, _type):
return self._cnt[_time].to_dict(_type)
application.register_function(dump_counter, 'counter')
import tornado.wsgi
import tornado.ioloop
import tornado.httpserver
container = tornado.wsgi.WSGIContainer(application)
self.xmlrpc_ioloop = tornado.ioloop.IOLoop()
self.xmlrpc_server = tornado.httpserver.HTTPServer(container, io_loop=self.xmlrpc_ioloop)
self.xmlrpc_server.listen(port=port, address=bind)
logger.info('fetcher.xmlrpc listening on %s:%s', bind, port)
self.xmlrpc_ioloop.start()
示例3: put_nowait
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def put_nowait(self, obj):
if self.lazy_limit and self.qsize_diff < self.qsize_diff_limit:
pass
elif self.full():
raise BaseQueue.Full
else:
self.qsize_diff = 0
with self.lock:
self.qsize_diff += 1
return self.channel.basic_publish("", self.name, umsgpack.packb(obj))
示例4: put_nowait
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def put_nowait(self, obj):
if self.lazy_limit and self.last_qsize < self.maxsize:
pass
elif self.full():
raise self.Full
self.last_qsize = self.redis.rpush(self.name, umsgpack.packb(obj))
return True
示例5: _pack_payload
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def _pack_payload(self) -> RawPayload:
try:
return RawPayload(umsgpack.packb(self.payload))
except umsgpack.PackException as exc:
raise MessageError('Could not pack msgpack payload') from exc
示例6: pack_message
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def pack_message(request, event_loop):
async def _pack_message(client, nonce, message, box=None, timeout=None, pack=True):
if pack:
data = umsgpack.packb(message)
else:
data = message
if box is not None:
_, data = box.encrypt(data, nonce=nonce, pack_nonce=False)
data = b''.join((nonce, data))
timeout = _get_timeout(timeout=timeout, request=request)
await asyncio.wait_for(client.send(data), timeout, loop=event_loop)
return data
return _pack_message
示例7: _http_request_func
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def _http_request_func(self, path, payload):
url_api = '%s%s' % (self.base_uri, path)
http_headers = {
'Content-Type': 'application/x-msgpack',
}
mp_payload = ''.join(map(chr, umsgpack.packb(payload)))
try:
pool = urllib3.PoolManager(timeout=10.0)
req = pool.urlopen(
'POST',
url_api,
headers=http_headers,
body=mp_payload,
)
return json.loads(req.data.decode('utf-8'))
except urllib3.exceptions.MaxRetryError:
fallback = self._fallback # or .... or ...
if fallback:
IkaUtils.dprint(
'%s: Remote API Error. Falling back to local mode' % self)
return self._local_request_func(path, payload)
raise Exception(
'API Error: Failed to connect to API endpoint. (No fallback)')
示例8: _http_request_func
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def _http_request_func(self, path, payload):
url_api = '%s%s' % (self.base_uri, path)
http_headers = {
'Content-Type': 'application/x-msgpack',
}
mp_payload = ''.join(map(chr, umsgpack.packb(payload)))
try:
pool = urllib3.PoolManager(timeout=3.0)
req = pool.urlopen(
'POST',
url_api,
headers=http_headers,
body=mp_payload,
)
return json.loads(req.data.decode('utf-8'))
except urllib3.exceptions.MaxRetryError:
fallback = self._fallback # or .... or ...
if fallback:
IkaUtils.dprint(
'%s: Remote API Error. Falling back to local mode' % self)
return self._local_request_func(path, payload)
raise Exception(
'API Error: Failed to connect to API endpoint. (No fallback)')
示例9: test_pack2unpack
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def test_pack2unpack(start):
packed = umsgpack.packb(start)
print('===> Packed: {}\n===> Unpacked: {}\n'.format(
packed,
umsgpack.unpackb(packed)))
示例10: __init__
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def __init__(self):
"""
This method connects, starts the loop and then publishes
all the messages until complete.
It then prints the current time before stopping the loop and exiting.
"""
super(MQPUB, self).__init__()
# determine current IP address of the local computer
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# use the google dns
try:
s.connect(('8.8.8.8', 1))
self.ip_address = s.getsockname()[0]
except:
self.ip_address = '127.0.0.1'
finally:
s.close()
self.connect(self.ip_address, 1883, 60)
print("MQPUB Connected - Sending 100000 messages")
time.sleep(2)
for x in range(0, 100000):
payload = {'msg': x}
packed = umsgpack.packb(payload)
self.publish("test", packed)
localtime = time.asctime(time.localtime(time.time()))
print('Task completed on: ', localtime)
time.sleep(1)
self.loop_stop()
sys.exit(0)
# instantiate the class
示例11: serialize_report
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def serialize_report(self, output_file, report_data):
raw_data = umsgpack.packb(report_data)
with open(output_file, "wb") as fp:
fp.write(raw_data)
#--------------------------------------------------------------------------
示例12: test_data_serialization
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def test_data_serialization(self, data):
umsgpack.packb(data)
示例13: send
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def send(self, command):
cmd_data = command.lower()
self.zmq_socket.send_multipart([
cmd_data["type"].encode("utf-8"),
cmd_data["path"].encode("utf-8"),
umsgpack.packb(cmd_data)
])
self.zmq_socket.recv()
示例14: encode
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def encode(self, data):
return umsgpack.packb(data)
示例15: serialize_message
# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def serialize_message(self, msg):
msg = umsgpack.packb(msg)
msg = binascii.hexlify(msg)
return msg