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


Python umsgpack.packb方法代码示例

本文整理汇总了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) 
开发者ID:oconnor663,项目名称:clinacl,代码行数:26,代码来源:clinacl.py

示例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() 
开发者ID:binux,项目名称:pyspider,代码行数:36,代码来源:tornado_fetcher.py

示例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)) 
开发者ID:binux,项目名称:pyspider,代码行数:12,代码来源:rabbitmq.py

示例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 
开发者ID:binux,项目名称:pyspider,代码行数:9,代码来源:redis_queue.py

示例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 
开发者ID:saltyrtc,项目名称:saltyrtc-server-python,代码行数:7,代码来源:message.py

示例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 
开发者ID:saltyrtc,项目名称:saltyrtc-server-python,代码行数:15,代码来源:conftest.py

示例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)') 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:29,代码来源:reprocess_screenshot_client.py

示例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)') 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:29,代码来源:client.py

示例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))) 
开发者ID:christabor,项目名称:MoAL,代码行数:7,代码来源:json_test.py

示例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 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:41,代码来源:mqpub.py

示例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)


    #-------------------------------------------------------------------------- 
开发者ID:blackye,项目名称:luscan-devel,代码行数:9,代码来源:msgpack.py

示例12: test_data_serialization

# 需要导入模块: import umsgpack [as 别名]
# 或者: from umsgpack import packb [as 别名]
def test_data_serialization(self, data):
        umsgpack.packb(data) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:4,代码来源:msgpack.py

示例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() 
开发者ID:rdeits,项目名称:meshcat-python,代码行数:10,代码来源:visualizer.py

示例14: encode

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

示例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 
开发者ID:StorjOld,项目名称:pyp2p,代码行数:6,代码来源:dht_msg.py


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