本文整理汇总了Python中msgpack.unpackb函数的典型用法代码示例。如果您正苦于以下问题:Python unpackb函数的具体用法?Python unpackb怎么用?Python unpackb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unpackb函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: recv
def recv(sock, **kwargs):
msg = sock.recv()
print "recv: ", msg, kwargs
try:
msgpack.unpackb(msg)
except Exception:
"Error: invalid msgpack"
开发者ID:pombredanne,项目名称:zmq-datomic,代码行数:7,代码来源:client.py
示例2: process_request
def process_request():
frames = socket.recv_multipart()
# killed by gsd
i = frames.index('')
command = frames[i + 2]
if command == '\x02':
global interrupted
interrupted = True
return
i = frames.index('', 1)
sequence, timestamp, expiry = msgpack.unpackb(frames[i+1])
method = frames[i+2]
params = msgpack.unpackb(frames[i+3])
try:
global converter
ret = getattr(converter, method)(*params)
except:
ret = ''
frames = frames[:i+1]
now = int(round(time.time() * 1000))
frames.append(msgpack.packb([sequence, now, 200]))
frames.append(msgpack.packb(ret))
socket.send_multipart(frames)
开发者ID:yaobiqing0424,项目名称:pinyin4py,代码行数:29,代码来源:pinyin-demowrk.py
示例3: show_raw_results
def show_raw_results(campaign_id):
campaign = CampaignController.get(campaign_id)
if 'lastUpdate' in request.args:
time = datetime.datetime.utcfromtimestamp(float(request.args['lastUpdate']))
results = ResultsController.get_all_since_time(campaign_id, time)
else:
results = ResultsController.get_all(campaign_id)
if len(results) > 0:
first_result = results[0]
timestamp = (first_result.date_added - datetime.datetime(1970, 1, 1)).total_seconds()
else:
timestamp = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds()
results_arr = []
for result in results:
result_obj = msgpack.unpackb(result.data)
dataset_obj = msgpack.unpackb(result.dataset.data)
results_arr.append({'dataset': dataset_obj, 'result': result_obj})
data = msgpack.packb({'timestamp' : timestamp, 'results' : results_arr})
res = current_app.make_response(data)
filename = safe_filename(campaign.title) + '_results_' + str(math.floor(timestamp)) + '.msgpack'
res.headers.add('Content-Disposition', 'attachment;filename=' + filename)
res.mimetype = 'application/octet-stream'
return res
开发者ID:Distribute-js,项目名称:Distribute.js,代码行数:30,代码来源:campaign_routes.py
示例4: run_once
def run_once(self):
self._feed_buffer()
channel_idx, buf, fin = self._unpack_buffer()
if channel_idx is None:
return
elif channel_idx == -1:
raise FluxUSBError("USB protocol broken")
elif channel_idx < 0x80:
channel = self.channels.get(channel_idx)
if channel is None:
raise FluxUSBError("Recv bad channel idx 0x%02x" % channel_idx)
if fin == 0xfe:
channel.on_object(msgpack.unpackb(buf))
elif fin == 0xff:
self._send_binary_ack(channel_idx)
channel.on_binary(buf)
elif fin == 0x80:
channel.on_binary_ack()
else:
raise FluxUSBError("Recv bad fin 0x%02x" % fin)
elif channel_idx == 0xf0:
if fin != 0xfe:
raise FluxUSBError("Recv bad fin 0x%02x" % fin)
self._on_channel_ctrl_response(msgpack.unpackb(buf))
else:
raise FluxUSBError("Recv bad control channel 0x%02x" % channel_idx)
开发者ID:blesscat,项目名称:flux_line_bot,代码行数:26,代码来源:usb2.py
示例5: query
def query(client, i):
t = time.time()
v = {'dd_%s'%(i):'abc12333:'+ str(t)}
print v
client.send( packb(v))
while True:
y = client.recv(10240)
if not y:
break
print unpackb(y)
print time.time() - t
#print dir(client)
#client.send('0')
#y = client.recv(10240)
#print "[%s]"%(y)
gevent.sleep(0)
开发者ID:mabotech,项目名称:maboss.py,代码行数:32,代码来源:gevent_client2.py
示例6: recv
def recv(self, s):
m = s.recv_multipart()
if len(m) == 6:
id, client_id, null, token, mtype, data = m
mtype = msgpack.unpackb(mtype)
mtype = MAP[mtype]
return id, client_id, token.decode('utf-8'), mtype, data.decode('utf-8')
elif len(m) == 5:
id, null, token, mtype, data = m
mtype = msgpack.unpackb(mtype)
mtype = MAP[mtype]
return id, token.decode('utf-8'), mtype, data.decode('utf-8')
elif len(m) == 4:
id, token, mtype, data = m
mtype = msgpack.unpackb(mtype)
mtype = MAP[mtype]
return id, token.decode('utf-8'), mtype, data.decode('utf-8')
elif len(m) == 3:
id, mtype, data = m
try:
mtype = msgpack.unpackb(mtype)
mtype = MAP[mtype]
except msgpack.exceptions.ExtraData:
pass
return id, mtype, data.decode('utf-8')
else:
mtype, data = m
return mtype, data.decode("utf-8")
开发者ID:csirtgadgets,项目名称:bearded-avenger-sdk-py,代码行数:33,代码来源:msg.py
示例7: unserialize
def unserialize(self, payload):
"""
Implements :func:`autobahn.wamp.interfaces.IObjectSerializer.unserialize`
"""
if self._batched:
msgs = []
N = len(payload)
i = 0
while i < N:
## read message length prefix
if i + 4 > N:
raise Exception("batch format error [1]")
l = struct.unpack("!L", payload[i:i+4])[0]
## read message data
if i + 4 + l > N:
raise Exception("batch format error [2]")
data = payload[i+4:i+4+l]
## append parsed raw message
msgs.append(msgpack.unpackb(data, encoding = 'utf-8'))
## advance until everything consumed
i = i+4+l
if i != N:
raise Exception("batch format error [3]")
return msgs
else:
return [msgpack.unpackb(payload, encoding = 'utf-8')]
开发者ID:BanzaiMan,项目名称:AutobahnPython,代码行数:31,代码来源:serializer.py
示例8: run_once
def run_once(self):
self._feed_buffer()
channel_idx, buf, fin = self._unpack_buffer()
if channel_idx is None:
return
elif channel_idx == -1:
raise FluxUSBError("USB protocol broken, got zero data length.")
elif channel_idx < 0x80:
channel = self.channels.get(channel_idx)
if channel is None:
raise FluxUSBError("Recv bad channel idx 0x%02x" % channel_idx)
if fin == 0xf0:
channel.on_object(msgpack.unpackb(buf, encoding="utf8",
unicode_errors="ignore"))
elif fin == 0xff:
self._send_binary_ack(channel_idx)
channel.on_binary(buf)
elif fin == 0xc0:
channel.on_binary_ack()
else:
raise FluxUSBError("Recv bad fin 0x%02x" % fin)
elif channel_idx == 0xa0 and fin == 0xff:
logger.debug("Recv padding")
elif channel_idx == 0xf1:
if fin != 0xf0:
raise FluxUSBError("Recv bad fin 0x%02x" % fin)
self._on_channel_ctrl_response(msgpack.unpackb(buf))
elif channel_idx == 0xfb:
self._on_pong(buf)
else:
self.stop()
self.close()
raise FluxUSBError("Recv bad control channel 0x%02x" % channel_idx)
开发者ID:flux3dp,项目名称:fluxclient,代码行数:33,代码来源:host2host_usb.py
示例9: decode
def decode(obj):
if isinstance(obj, ExtType):
if obj.code == TYPE_PSET:
unpacked_data = unpackb(obj.data,
use_list=False,
encoding='utf-8')
return pset(decode(item) for item in unpacked_data)
if obj.code == TYPE_PLIST:
unpacked_data = unpackb(obj.data,
use_list=False,
encoding='utf-8')
return plist(decode(item) for item in unpacked_data)
if obj.code == TYPE_PBAG:
unpacked_data = unpackb(obj.data,
use_list=False,
encoding='utf-8')
return pbag(decode(item) for item in unpacked_data)
module_name, class_name, *data = unpackb(obj.data,
use_list=False,
encoding='utf-8')
cls = getattr(sys.modules[module_name],
class_name)
return cls(*(decode(item) for item in data))
if isinstance(obj, tuple):
return pvector(decode(item) for item in obj)
if isinstance(obj, dict):
new_dict = dict()
for key in obj.keys():
new_dict[decode(key)] = decode(obj[key])
return pmap(new_dict)
return obj
开发者ID:tlvu,项目名称:mochi,代码行数:31,代码来源:actor.py
示例10: test_call_with_multi_args
def test_call_with_multi_args(self):
addr = get_random_ipc_socket()
with utils.TestingServer(methods=self.get_methods(), addresses=addr):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(addr)
socket.send(msgpack.packb({
'm': 'method3',
'k': {'name': 'WORLD'},
}, encoding='utf-8'))
response = msgpack.unpackb(socket.recv(), encoding='utf-8')
assert response == {'r': 'Hello, WORLD!'}
socket.send(msgpack.packb({
'm': 'method3',
'k': {'greeting': 'HOWDY'},
}, encoding='utf-8'))
response = msgpack.unpackb(socket.recv(), encoding='utf-8')
assert response == {'r': 'HOWDY, world!'}
socket.send(msgpack.packb({
'm': 'method3',
'k': {'greeting': 'HOWDY', 'name': 'MAN'},
}, encoding='utf-8'))
response = msgpack.unpackb(socket.recv(), encoding='utf-8')
assert response == {'r': 'HOWDY, MAN!'}
socket.send(msgpack.packb({
'm': 'method3',
'a': ('hey', 'man'),
}, encoding='utf-8'))
response = msgpack.unpackb(socket.recv(), encoding='utf-8')
assert response == {'r': 'hey, man!'}
开发者ID:xk0,项目名称:SmartRPyC,代码行数:34,代码来源:test_smartrpc.py
示例11: test_odict
def test_odict():
seq = [(b'one', 1), (b'two', 2), (b'three', 3), (b'four', 4)]
od = OrderedDict(seq)
assert unpackb(packb(od), use_list=1) == dict(seq)
def pair_hook(seq):
return list(seq)
assert unpackb(packb(od), object_pairs_hook=pair_hook, use_list=1) == seq
开发者ID:methane,项目名称:msgpack-python,代码行数:7,代码来源:test_pack.py
示例12: _unserializer
def _unserializer(code, data):
if code == 0:
return uuid.UUID(hex=six.text_type(data, encoding='ascii'))
if code == 1:
return _deserialize_datetime(data)
if code == 2:
value = msgpack.unpackb(data)
if not _PY26:
return itertools.count(value[0], value[1])
else:
return itertools.count(value[0])
if netaddr and code == 3:
value = msgpack.unpackb(data)
return netaddr.IPAddress(value)
if code in (4, 5):
value = loads(data)
if code == 4:
return set(value)
else:
return frozenset(value)
if code == 6:
dt = _deserialize_datetime(data)
return xmlrpclib.DateTime(dt.timetuple())
if code == 7:
return _deserialize_date(data)
return msgpack.ExtType(code, data)
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:26,代码来源:msgpackutils.py
示例13: flash_binary
def flash_binary(fdesc, binary, base_address, device_class, destinations,
page_size=2048):
"""
Writes a full binary to the flash using the given file descriptor.
It also takes the binary image, the base address and the device class as
parameters.
"""
print("Erasing pages...")
pbar = progressbar.ProgressBar(maxval=len(binary)).start()
# First erase all pages
for offset in range(0, len(binary), page_size):
erase_command = commands.encode_erase_flash_page(base_address + offset,
device_class)
res = utils.write_command_retry(fdesc, erase_command, destinations)
failed_boards = [str(id) for id, success in res.items()
if not msgpack.unpackb(success)]
if failed_boards:
msg = ", ".join(failed_boards)
msg = "Boards {} failed during page erase, aborting...".format(msg)
logging.critical(msg)
sys.exit(2)
pbar.update(offset)
pbar.finish()
print("Writing pages...")
pbar = progressbar.ProgressBar(maxval=len(binary)).start()
# Then write all pages in chunks
for offset, chunk in enumerate(page.slice_into_pages(binary, page_size)):
offset *= page_size
command = commands.encode_write_flash(chunk,
base_address + offset,
device_class)
res = utils.write_command_retry(fdesc, command, destinations)
failed_boards = [str(id) for id, success in res.items()
if not msgpack.unpackb(success)]
if failed_boards:
msg = ", ".join(failed_boards)
msg = "Boards {} failed during page write, aborting...".format(msg)
logging.critical(msg)
sys.exit(2)
pbar.update(offset)
pbar.finish()
# Finally update application CRC and size in config
config = dict()
config['application_size'] = len(binary)
config['application_crc'] = crc32(binary)
utils.config_update_and_save(fdesc, config, destinations)
开发者ID:cvra,项目名称:can-bootloader,代码行数:59,代码来源:bootloader_flash.py
示例14: send_request_message
def send_request_message(self, request):
# for deep copy of Request object
obj = msgpack.unpackb(msgpack.packb(request.packed_object()))
rcv_request = Request.create_from_packed(obj)
response = self.dispatcher.dispatch_request(rcv_request)
# for deep copy of Response object
obj = msgpack.unpackb(msgpack.packb(response.packed_object()))
return Response.create_from_packed(obj)
开发者ID:NaokiMiyata,项目名称:odenos,代码行数:8,代码来源:local_message_transport.py
示例15: decode
def decode(obj, silent=False):
"""Decode msgpack binary data to python object.
"""
if obj is None:
return
if silent:
return msgpack.unpackb(obj, object_hook=msgpack_decode_silent, encoding='utf8')
return msgpack.unpackb(obj, object_hook=msgpack_decode, encoding='utf8')
开发者ID:liwushuo,项目名称:Flask-CacheOBJ,代码行数:8,代码来源:msgpackable.py
示例16: msgpack_unpack
def msgpack_unpack(code, data):
if code == 21:
data = msgpack.unpackb(data, encoding='utf-8', ext_hook=msgpack_unpack)
return Folder(data['name'], data['files'], data['folders'])
elif code == 81:
data = msgpack.unpackb(data, encoding='utf-8', ext_hook=msgpack_unpack)
return File(data['name'], data['size'])
raise RuntimeError('unknown msgpack extension type %i', code)
开发者ID:JanHammerschmidt,项目名称:dropbox-crawler,代码行数:8,代码来源:dropbox-crawler.py
示例17: from_dict
def from_dict(cls, data, hash_children=False):
"""
"""
instance = cls()
for attribute in instance._attributes:
value = data[attribute.name]
# Dictionary
if attribute.type is dict:
if attribute.children_type and hasattr(attribute.children_type, 'to_dict'):
attribute_value = attribute.type()
for key in value.keys():
object = value[key]
d = msgpack.unpackb(object) if hash_children else object
attribute_value[key] = attribute.children_type.from_dict(d)
setattr(instance, attribute.internal_name, attribute_value)
else:
setattr(instance, attribute.internal_name, msgpack.unpackb(value) if hash_children else value)
# List
elif attribute.type is list:
if attribute.children_type and hasattr(attribute.children_type, 'to_dict'):
attribute_value = attribute.type()
for object in value:
d = msgpack.unpackb(object) if hash_children else object
attribute_value.append(attribute.children_type.from_dict(d))
setattr(instance, attribute.internal_name, attribute_value)
else:
setattr(instance, attribute.internal_name, msgpack.unpackb(value) if hash_children else value)
elif value is not None:
# Objects
if hasattr(attribute.type, 'to_dict'):
object = attribute.type() # Note: Allows to use NURESTObject as well
d = msgpack.unpackb(value) if hash_children else value
value = object.from_dict(d)
setattr(instance, attribute.internal_name, value if value else object)
# Datetime
elif attribute.type is datetime:
setattr(instance, attribute.internal_name, datetime.strptime(value, cls.DATE_FORMAT))
# Boolean
elif attribute.type is bool:
setattr(instance, attribute.internal_name, True if value == "True" else False)
# Others
else:
setattr(instance, attribute.internal_name, value)
# None
else:
setattr(instance, attribute.internal_name, None)
return instance
开发者ID:Dogild,项目名称:garuda,代码行数:58,代码来源:serializable.py
示例18: test_odict
def test_odict():
seq = [(b"one", 1), (b"two", 2), (b"three", 3), (b"four", 4)]
od = odict(seq)
assert_equal(unpackb(packb(od), use_list=1), dict(seq))
def pair_hook(seq):
return seq
assert_equal(unpackb(packb(od), object_pairs_hook=pair_hook, use_list=1), seq)
开发者ID:seliopou,项目名称:msgpack-python,代码行数:9,代码来源:test_pack.py
示例19: test_put_of_valid_key
def test_put_of_valid_key(self):
message = self.request_message('PUT', ['a', '1'])
header, content = self.handler.command(message)
plain_header = msgpack.unpackb(header)
plain_content = msgpack.unpackb(content)
self.assertEqual(plain_header['status'], SUCCESS_STATUS)
self.assertEqual(plain_content['datas'], None)
开发者ID:oleiade,项目名称:Elevator,代码行数:9,代码来源:api_tests.py
示例20: test_delete
def test_delete(self):
message = self.request_message('DELETE', ['9'])
header, content = self.handler.command(message)
plain_header = msgpack.unpackb(header)
plain_content = msgpack.unpackb(content)
self.assertEqual(plain_header['status'], SUCCESS_STATUS)
self.assertEqual(plain_content['datas'], None)
开发者ID:oleiade,项目名称:Elevator,代码行数:9,代码来源:api_tests.py
注:本文中的msgpack.unpackb函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论