當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。