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


Python umsgpack.unpackb方法代码示例

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


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

示例1: unpack_message

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def unpack_message(request, event_loop):
    async def _unpack_message(client, box=None, timeout=None):
        timeout = _get_timeout(timeout=timeout, request=request)
        data = await asyncio.wait_for(client.recv(), timeout, loop=event_loop)
        nonce = data[:NONCE_LENGTH]
        (cookie,
         source, destination,
         combined_sequence_number) = struct.unpack(NONCE_FORMATTER, nonce)
        combined_sequence_number, *_ = struct.unpack(
            '!Q', b'\x00\x00' + combined_sequence_number)
        data = data[NONCE_LENGTH:]
        if box is not None:
            data = box.decrypt(data, nonce=nonce)
        else:
            nonce = None
        message = umsgpack.unpackb(data)
        return (
            message,
            nonce,
            cookie,
            source, destination,
            combined_sequence_number
        )
    return _unpack_message 
开发者ID:saltyrtc,项目名称:saltyrtc-server-python,代码行数:26,代码来源:conftest.py

示例2: keybase_verify

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def keybase_verify():
    # A Keybase NaCl signature is a Base64-encoded MessagePack blob containing
    # the payload, the signing KID, and the detatched signature bytes. We
    # decode, unpack, and then verify the signature. If it's valid, we print
    # the payload (which is usually a JSON blob).
    sig_base64 = sys.stdin.read()
    sig_msgpack_bytes = base64.b64decode(sig_base64)
    sig_obj = umsgpack.unpackb(sig_msgpack_bytes)
    keybytes_tagged = sig_obj['body']['key']
    # Keybase KIDs are just NaCl public keys type-tagged with two bytes at the
    # front and one byte in the back. Stripping these gives the key.
    keybytes = keybytes_tagged[2:-1]
    verifykey = nacl.signing.VerifyKey(keybytes)
    detatched_sig_bytes = sig_obj['body']['sig']
    sig_payload = sig_obj['body']['payload']
    attached_sig_bytes = detatched_sig_bytes + sig_payload
    write_to_stdout(verifykey.verify(attached_sig_bytes)) 
开发者ID:oconnor663,项目名称:clinacl,代码行数:19,代码来源:clinacl.py

示例3: test_40_with_rpc

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def test_40_with_rpc(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = 'data:,hello'
        result = umsgpack.unpackb(self.rpc.fetch(request).data)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.text, 'hello') 
开发者ID:binux,项目名称:pyspider,代码行数:10,代码来源:test_fetcher.py

示例4: get_nowait

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def get_nowait(self, ack=False):
        with self.lock:
            method_frame, header_frame, body = self.channel.basic_get(self.name, not ack)
            if method_frame is None:
                raise BaseQueue.Empty
            if ack:
                self.channel.basic_ack(method_frame.delivery_tag)
        return umsgpack.unpackb(body) 
开发者ID:binux,项目名称:pyspider,代码行数:10,代码来源:rabbitmq.py

示例5: get_nowait

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def get_nowait(self):
        ret = self.redis.lpop(self.name)
        if ret is None:
            raise self.Empty
        return umsgpack.unpackb(ret) 
开发者ID:binux,项目名称:pyspider,代码行数:7,代码来源:redis_queue.py

示例6: _unpack_payload

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def _unpack_payload(cls, payload: RawPayload) -> Payload:
        try:
            return cast(Payload, umsgpack.unpackb(payload))
        except (umsgpack.UnpackException, TypeError) as exc:
            raise MessageError('Could not unpack msgpack payload') from exc 
开发者ID:saltyrtc,项目名称:saltyrtc-server-python,代码行数:7,代码来源:message.py

示例7: do_POST

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def do_POST(self):
        length = int(self.headers.get('content-length'))
        data = self.rfile.read(length)

        # FIXME: support both of msgpack and JSON format.
        payload = umsgpack.unpackb(data)

        # FixMe: catch expcetion.
        response = self.dispatch_request(self.path, payload)

        self._send_response_json(response)

        if hasattr(self, 'callback_func'):
            self.callback_func(self.path, payload, response) 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:16,代码来源:reprocess_screenshots.py

示例8: do_POST

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def do_POST(self):
        length = int(self.headers.get('content-length'))
        data = self.rfile.read(length)

        # FIXME: support both of msgpack and JSON format.
        payload = umsgpack.unpackb(data)

        # FixMe: catch expcetion.
        response = self.api_server.process_request(self.path, payload)

        self._send_response_json(response)

        if hasattr(self, 'callback_func'):
            self.callback_func(self.path, payload, response) 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:16,代码来源:server.py

示例9: test_pack2unpack

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def test_pack2unpack(start):
    packed = umsgpack.packb(start)
    print('===>  Packed: {}\n===>  Unpacked: {}\n'.format(
        packed,
        umsgpack.unpackb(packed))) 
开发者ID:christabor,项目名称:MoAL,代码行数:7,代码来源:json_test.py

示例10: get_message

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def get_message(self):
        """
        This method is called from the tkevent loop "after" call. It will poll for new zeromq messages
        :return:
        """
        try:
            data = self.subscriber.recv_multipart(zmq.NOBLOCK)
            self.incoming_message_processing(data[0].decode(), umsgpack.unpackb(data[1]))
            self.root.after(1, self.get_message)

        except zmq.error.Again:
            try:
                time.sleep(.0001)
                self.root.after(1, self.get_message)

            except KeyboardInterrupt:
                self.root.destroy()
                self.publisher.close()
                self.subscriber.close()
                self.my_context.term()
                sys.exit(0)
        except KeyboardInterrupt:
            self.root.destroy()
            self.publisher.close()
            self.subscriber.close()
            self.my_context.term()
            sys.exit(0) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:29,代码来源:tk_echo_client.py

示例11: on_message

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def on_message(self, mqttc, obj, msg):
        """

        :param mqttc: the client
        :param obj: unused
        :param msg: the message containing the payload
        :return:
        """
        # unpack the messagepack message
        if msg.topic == 'test':
            mg = umsgpack.unpackb(msg.payload)
            data = mg['msg']

            # update the count of messages received and start the
            # elapsed time timer
            self.message_count += 1
            if data == 0:
                self.start = time.time()

            # wait for the last message, then print out the current time
            # and an elapsed time message.
            # finally stop the loop and exit.
            if data == 99999:
                self.end = time.time()
                localtime = time.asctime(time.localtime(time.time()))

                print('Task completed on: ', localtime)
                print('{} Total messages received in {} seconds.'.format(self.message_count,
                                                                         self.end - self.start))
                time.sleep(1)
                self.loop_stop()
                sys.exit(0)
        else:
            print('unknown topic' + msg.topic) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:36,代码来源:mqsub.py

示例12: decode

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def decode(self, data):
        data = umsgpack.unpackb(data)
        return data 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:5,代码来源:msgpack_coder.py

示例13: build_dht_response

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def build_dht_response(self, msg):
        msg = binascii.unhexlify(msg)
        msg = umsgpack.unpackb(msg)
        try:
            str_types = [type(u""), type(b"")]
            if type(msg) in str_types:
                msg = literal_eval(msg)
        except:
            msg = str(msg)

        return msg 
开发者ID:StorjOld,项目名称:pyp2p,代码行数:13,代码来源:dht_msg.py

示例14: decode_msgpack

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def decode_msgpack(input_data, ordered):
    try:
        return umsgpack.unpackb(input_data, use_ordered_dict=ordered)
    except umsgpack.UnpackException as e:
        raise ValueError('Cannot parse as MessagePack ({0})'.format(e)) 
开发者ID:dbohdan,项目名称:remarshal,代码行数:7,代码来源:remarshal.py

示例15: webui

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import unpackb [as 别名]
def webui(ctx, host, port, cdn, scheduler_rpc, fetcher_rpc, max_rate, max_burst,
          username, password, need_auth, webui_instance, process_time_limit, get_object=False):
    """
    Run WebUI
    """
    app = load_cls(None, None, webui_instance)

    g = ctx.obj
    app.config['taskdb'] = g.taskdb
    app.config['projectdb'] = g.projectdb
    app.config['resultdb'] = g.resultdb
    app.config['cdn'] = cdn

    if max_rate:
        app.config['max_rate'] = max_rate
    if max_burst:
        app.config['max_burst'] = max_burst
    if username:
        app.config['webui_username'] = username
    if password:
        app.config['webui_password'] = password
    app.config['need_auth'] = need_auth
    app.config['process_time_limit'] = process_time_limit

    # inject queues for webui
    for name in ('newtask_queue', 'status_queue', 'scheduler2fetcher',
                 'fetcher2processor', 'processor2result'):
        app.config['queues'][name] = getattr(g, name, None)

    # fetcher rpc
    if isinstance(fetcher_rpc, six.string_types):
        import umsgpack
        fetcher_rpc = connect_rpc(ctx, None, fetcher_rpc)
        app.config['fetch'] = lambda x: umsgpack.unpackb(fetcher_rpc.fetch(x).data)
    else:
        # get fetcher instance for webui
        fetcher_config = g.config.get('fetcher', {})
        webui_fetcher = ctx.invoke(fetcher, async_mode=False, get_object=True, no_input=True, **fetcher_config)

        app.config['fetch'] = lambda x: webui_fetcher.fetch(x)

    # scheduler rpc
    if isinstance(scheduler_rpc, six.string_types):
        scheduler_rpc = connect_rpc(ctx, None, scheduler_rpc)
    if scheduler_rpc is None and os.environ.get('SCHEDULER_PORT_23333_TCP_ADDR'):
        app.config['scheduler_rpc'] = connect_rpc(ctx, None,
                                                  'http://{}:{}/'.format(os.environ.get('SCHEDULER_PORT_23333_TCP_ADDR'),
                                                                         os.environ.get('SCHEDULER_PORT_23333_TCP_PORT') or 23333))
    elif scheduler_rpc is None:
        app.config['scheduler_rpc'] = connect_rpc(ctx, None, 'http://127.0.0.1:23333/')
    else:
        app.config['scheduler_rpc'] = scheduler_rpc


    app.debug = g.debug
    g.instances.append(app)
    if g.get('testing_mode') or get_object:
        return app

    app.run(host=host, port=port) 
开发者ID:binux,项目名称:pyspider,代码行数:62,代码来源:run.py


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