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


Python cbor.dumps方法代码示例

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


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

示例1: send

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def send(self):
        name = uuid4().hex[:20]
        txns = [
            self._factory.create_transaction(
                cbor.dumps({
                    'Name': name,
                    'Verb': 'set',
                    'Value': 1000
                }),
                inputs=[
                    self._namespace + self._factory.sha512(name.encode())[-64:]
                ],
                outputs=[
                    self._namespace + self._factory.sha512(name.encode())[-64:]
                ],
                deps=[])
        ]
        self._rest.send_batches(self._factory.create_batch(txns)) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:20,代码来源:test_network_permissioning.py

示例2: serialize_to_bytes

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def serialize_to_bytes(self):
        """Serialized the consensus state object to a byte string suitable
        for storage

        Returns:
            bytes: serialized version of the consensus state object
        """
        # For serialization, the easiest thing to do is to convert ourself to
        # a dictionary and convert to CBOR.  The deque object cannot be
        # automatically serialized, so convert it to a list first.  We will
        # reconstitute it to a deque upon parsing.
        self_dict = {
            '_aggregate_local_mean': self._aggregate_local_mean,
            '_population_samples': list(self._population_samples),
            '_total_block_claim_count': self._total_block_claim_count,
            '_validators': self._validators
        }
        return cbor.dumps(self_dict) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:20,代码来源:consensus_state.py

示例3: test_receipt_stored

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def test_receipt_stored(self):
        """Tests that receipts are stored successfully when a block is
        committed."""
        self._subscribe()
        n = self.batch_submitter.submit_next_batch()
        response = self._get_receipt(n)
        receipts = self.assert_receipt_get_response(response)
        state_change = receipts[0].state_changes[0]
        self.assertEqual(
            state_change.type,
            transaction_receipt_pb2.StateChange.SET)
        self.assertEqual(
            state_change.value,
            cbor.dumps({str(n): 0}))
        self.assertEqual(
            state_change.address,
            make_intkey_address(str(n)))
        self._unsubscribe() 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:20,代码来源:test_events_and_receipts.py

示例4: build_test_data

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def build_test_data(destdir):
    l = get_test_data_list()
    for i in range(len(l)):
        # packer = msgpack.Packer()
        serialized = msgpack.dumps(l[i])
        f = open(os.path.join(destdir, str(i) + '.msgpack.golden'), 'wb')
        f.write(serialized)
        f.close()
        serialized = cbor.dumps(l[i])
        f = open(os.path.join(destdir, str(i) + '.cbor.golden'), 'wb')
        f.write(serialized)
        f.close() 
开发者ID:planetlabs,项目名称:klondike,代码行数:14,代码来源:test.py

示例5: to_cbor_bytes

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def to_cbor_bytes(self):
        return cbor.dumps(self.to_map(), sort_keys=True) 
开发者ID:mediachain,项目名称:oldchain-client,代码行数:4,代码来源:data_objects.py

示例6: bytes_for_object

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def bytes_for_object(obj):
    try:
        return obj.to_cbor_bytes()
    except AttributeError:
        pass

    if isinstance(obj, dict):
        try:
            return cbor.dumps(obj)
        except ValueError:
            pass
    return obj 
开发者ID:mediachain,项目名称:oldchain-client,代码行数:14,代码来源:utils.py

示例7: insert_canonical

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def insert_canonical(self, record, timeout=TIMEOUT_SECS):
        try:
            cbor_bytes = record.to_cbor_bytes()
        except AttributeError:
            cbor_bytes = cbor.dumps(record)

        req = Transactor_pb2.InsertRequest(canonicalCbor=cbor_bytes)
        ref = with_retry(self.client.InsertCanonical, req, timeout)
        return MultihashReference.from_base58(ref.reference) 
开发者ID:mediachain,项目名称:oldchain-client,代码行数:11,代码来源:client.py

示例8: update_chain

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def update_chain(self, cell, timeout=TIMEOUT_SECS):
        try:
            cbor_bytes = cell.to_cbor_bytes()
        except AttributeError:
            cbor_bytes = cbor.dumps(cell)

        req = Transactor_pb2.UpdateRequest(chainCellCbor=cbor_bytes)
        ref = with_retry(self.client.UpdateChain, req, timeout)
        return MultihashReference.from_base58(ref.reference) 
开发者ID:mediachain,项目名称:oldchain-client,代码行数:11,代码来源:client.py

示例9: _init_drsocks

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def _init_drsocks(i):
    """Internal use only"""
####################################
# Initialise TCP sockets to receive#
# unicast Discovery responses      # 
####################################

    # Can't use a comprehension because we need the actual
    # list index in order select the correct socket.
    _msg_bytes = cbor.dumps([M_NOOP]) #No-op message
    for _ in range(10):
        try:
            _mcssocks[i][1].sendto(_msg_bytes,0,(str(ALL_GRASP_NEIGHBORS_6), GRASP_LISTEN_PORT))
            _port = _mcssocks[i][1].getsockname()[1]
            _s =socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
            _s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            try:
                #ttprint("Binding",_port)
                _s.bind(('',_port))
            except:
                # Can't get the same port number, try again
                #ttprint("Couldn't bind")
                _s.close()              
                _mcssocks[i][1].close()
                ifi = _mcssocks[i][0]
                _mcssocks[i][1] = _try_mcsock(ifi)
                continue
            _drlt = _drlisten(_s, _ll_zone_ids[i][0])
            tprint("Starting a discovery TCP listener for interface", _s.getsockname(), _ll_zone_ids[i][0])
            _drlt.start()
            return
        except OSError as ex:
            ttprint(ex)
            #Network down, most likely, wait and retry
            tprint("Retrying to start discovery listener")
            time.sleep(10)
    # If we're here, something is deeply suspect and we have to give up.
    raise RuntimeError("Cannot get free port for discovery TCP listener") 
开发者ID:becarpenter,项目名称:graspy,代码行数:40,代码来源:grasp.py

示例10: flush_block

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def flush_block(self, block):
        block_data = b''
        if block.data is not None:
            block_data = self.codec.encode_block(block.id, block.data)
        assert isinstance(block_data, bytes)
        data = cbor.dumps([block_data, block.refcnt, block.type])
        with self.env.begin(db=self.block_db, write=True) as t:
            if t.get(block.id) == data:
                return 0
            t.put(block.id, data)
            return 1 
开发者ID:fingon,项目名称:tfhfs,代码行数:13,代码来源:storage_lmdb.py

示例11: dumps

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def dumps(self, o):
        return cbor.dumps(self.get_external_dict(o)) 
开发者ID:fingon,项目名称:tfhfs,代码行数:4,代码来源:util.py

示例12: _dumps

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def _dumps(obj):
    return json.dumps(obj,
                      separators=(',', ':'),
                      ensure_ascii=False,
                      sort_keys=False,
                      cls=_WAMPJsonEncoder) 
开发者ID:openstack,项目名称:deb-python-autobahn,代码行数:8,代码来源:serializer.py

示例13: serialize

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def serialize(self, obj):
            """
            Implements :func:`autobahn.wamp.interfaces.IObjectSerializer.serialize`
            """
            data = cbor.dumps(obj)
            if self._batched:
                return struct.pack("!L", len(data)) + data
            else:
                return data 
开发者ID:openstack,项目名称:deb-python-autobahn,代码行数:11,代码来源:serializer.py

示例14: main

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def main():
    p = argparse.ArgumentParser('simple debugging tool for watching the linker and OpenQuery')
    p.add_argument('action', help='either `run` or `cache` or `delete`')
    p.add_argument('folder', help='folder name')
    p.add_argument('subfolder', help='subfolder name')
    args = yakonfig.parse_args(p, [kvlayer, yakonfig])

    config = yakonfig.get_global_config()

    key = cbor.dumps((args.folder.replace(' ', '_'), args.subfolder.replace(' ', '_')))

    if args.action == 'run':
        web_conf = Config()
        with yakonfig.defaulted_config([kvlayer, dblogger, web_conf], config=config):
            traverse_extract_fetch(web_conf, key, stop_after_extraction=True)

    elif args.action == 'delete':
        kvlclient = kvlayer.client()
        kvlclient.setup_namespace({'openquery': (str,)})
        kvlclient.delete('openquery', (key,))
        print('deleted %r' % key)

    elif args.action == 'cache':

        kvlclient = kvlayer.client()
        kvlclient.setup_namespace({'openquery': (str,)})
        count = 0
        for rec in kvlclient.scan('openquery'):
            count += 1
            if rec[0][0] == key:
                print rec
        print('%d cached queries' % count) 
开发者ID:dossier,项目名称:memex-dossier-open,代码行数:34,代码来源:run.py

示例15: to_kvlayer

# 需要导入模块: import cbor [as 别名]
# 或者: from cbor import dumps [as 别名]
def to_kvlayer(item):
        data = cbor.dumps({
            'is_folder': item.is_folder(),
            'meta_data': item.meta_data,
            'user_data': item.data,
        })
        return ((utf8(item.namespace), utf8(item.owner), item.inode), data) 
开发者ID:dossier,项目名称:memex-dossier-open,代码行数:9,代码来源:folder.py


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