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


Python cPickle.dumps方法代码示例

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


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

示例1: test_pickle_chunk_V1_read

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_pickle_chunk_V1_read():
    data = {'foo': b'abcdefghijklmnopqrstuvwxyz'}
    version = {'_id': sentinel._id,
               'blob': '__chunked__'}
    coll = Mock()
    arctic_lib = Mock()
    datap = compressHC(cPickle.dumps(data, protocol=cPickle.HIGHEST_PROTOCOL))
    data_1 = datap[0:5]
    data_2 = datap[5:]
    coll.find.return_value = [{'data': Binary(data_1),
                               'symbol': 'sentinel.symbol',
                               'segment': 0},
                              {'data': Binary(data_2),
                               'symbol': 'sentinel.symbol',
                               'segment': 1},
                              ]
    arctic_lib.get_top_level_collection.return_value = coll

    ps = PickleStore()
    assert(data == ps.read(arctic_lib, version, sentinel.symbol)) 
开发者ID:man-group,项目名称:arctic,代码行数:22,代码来源:test_pickle_store.py

示例2: test_pickle_store_future_version

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_pickle_store_future_version():
    data = {'foo': b'abcdefghijklmnopqrstuvwxyz'}
    version = {'_id': sentinel._id,
               'blob': '__chunked__VERSION_ONE_MILLION'}
    coll = Mock()
    arctic_lib = Mock()
    datap = compressHC(cPickle.dumps(data, protocol=cPickle.HIGHEST_PROTOCOL))
    data_1 = datap[0:5]
    data_2 = datap[5:]
    coll.find.return_value = [{'data': Binary(data_1),
                               'symbol': 'sentinel.symbol',
                               'segment': 0},
                              {'data': Binary(data_2),
                               'symbol': 'sentinel.symbol',
                               'segment': 1},
                              ]
    arctic_lib.get_top_level_collection.return_value = coll

    ps = PickleStore()
    with pytest.raises(UnsupportedPickleStoreVersion) as e:
        ps.read(arctic_lib, version, sentinel.symbol)
    assert('unsupported version of pickle store' in str(e.value)) 
开发者ID:man-group,项目名称:arctic,代码行数:24,代码来源:test_pickle_store.py

示例3: verify_tee

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def verify_tee(n, original, seed):
    try:
        state = random.getstate()
        iterators = list(tee(original, n=n))
        results = [[] for _ in range(n)]
        exhausted = [False] * n
        while not all(exhausted):
            # Upper argument of random.randint is inclusive. Argh.
            i = random.randint(0, n - 1)
            if not exhausted[i]:
                if len(results[i]) == len(original):
                    assert_raises(StopIteration, next, iterators[i])
                    assert results[i] == original
                    exhausted[i] = True
                else:
                    if random.randint(0, 1):
                        iterators[i] = cPickle.loads(
                            cPickle.dumps(iterators[i]))
                    elem = next(iterators[i])
                    results[i].append(elem)
    finally:
        random.setstate(state) 
开发者ID:mila-iqia,项目名称:picklable-itertools,代码行数:24,代码来源:__init__.py

示例4: test_xrange

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_xrange():
    yield assert_equal, list(xrange(10)), list(_xrange(10))
    yield assert_equal, list(xrange(10, 15)), list(_xrange(10, 15))
    yield assert_equal, list(xrange(10, 20, 2)), list(_xrange(10, 20, 2))
    yield assert_equal, list(xrange(5, 1, -1)), list(_xrange(5, 1, -1))
    yield (assert_equal, list(xrange(5, 55, 3)),
           list(cPickle.loads(cPickle.dumps(_xrange(5, 55, 3)))))
    yield assert_equal, _xrange(5).index(4), 4
    yield assert_equal, _xrange(5, 9).index(6), 1
    yield assert_equal, _xrange(8, 24, 3).index(11), 1
    yield assert_equal, _xrange(25, 4, -5).index(25), 0
    yield assert_equal, _xrange(28, 7, -7).index(14), 2
    yield assert_raises, ValueError, _xrange(2, 9, 2).index, 3
    yield assert_raises, ValueError, _xrange(2, 20, 2).index, 9
    yield assert_equal, _xrange(5).count(5), 0
    yield assert_equal, _xrange(5).count(4), 1
    yield assert_equal, _xrange(4, 9).count(4), 1
    yield assert_equal, _xrange(3, 9, 2).count(4), 0
    yield assert_equal, _xrange(3, 9, 2).count(5), 1
    yield assert_equal, _xrange(3, 9, 2).count(20), 0
    yield assert_equal, _xrange(9, 3).count(5), 0
    yield assert_equal, _xrange(3, 10, -1).count(5), 0
    yield assert_equal, _xrange(10, 3, -1).count(5), 1
    yield assert_equal, _xrange(10, 0, -2).count(6), 1
    yield assert_equal, _xrange(10, -1, -3).count(7), 1 
开发者ID:mila-iqia,项目名称:picklable-itertools,代码行数:27,代码来源:__init__.py

示例5: test_pickling

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_pickling(self, backend_config):
        x_data, = self.generate_inputs()

        link = self.create_link(self.generate_params())
        link.to_device(backend_config.device)

        x = chainer.Variable(x_data)
        x.to_device(backend_config.device)

        y = link(x)
        y_data1 = y.data
        del x, y
        pickled = pickle.dumps(link, -1)
        del link
        link = pickle.loads(pickled)
        x = chainer.Variable(x_data)
        x.to_device(backend_config.device)
        y = link(x)
        y_data2 = y.data

        testing.assert_allclose(y_data1, y_data2, atol=0, rtol=0) 
开发者ID:chainer,项目名称:chainer,代码行数:23,代码来源:test_convolution_2d.py

示例6: check_pickling

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def check_pickling(self, x_data):
        x = chainer.Variable(x_data)
        y = self.link(x)
        y_data1 = y.data

        del x, y

        pickled = pickle.dumps(self.link, -1)
        del self.link
        self.link = pickle.loads(pickled)

        x = chainer.Variable(x_data)
        y = self.link(x)
        y_data2 = y.data

        testing.assert_allclose(y_data1, y_data2, atol=0, rtol=0) 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:test_dilated_convolution_2d.py

示例7: test_pickling

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_pickling(self):
        try:
            features = numpy.arange(360, dtype='uint16').reshape((10, 36))
            h5file = h5py.File('file.hdf5', mode='w')
            h5file['features'] = features
            split_dict = {'train': {'features': (0, 10, None, '.')}}
            h5file.attrs['split'] = H5PYDataset.create_split_array(split_dict)
            dataset = cPickle.loads(
                cPickle.dumps(H5PYDataset(h5file, which_sets=('train',))))
            # Make sure _out_of_memory_{open,close} accesses
            # external_file_handle rather than _external_file_handle
            dataset._out_of_memory_open()
            dataset._out_of_memory_close()
            assert dataset.data_sources is None
        finally:
            os.remove('file.hdf5') 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:18,代码来源:test_hdf5.py

示例8: test_causes_pickle

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_causes_pickle(self):
        f = None
        try:
            self._raise_many(["Still still not working",
                              "Still not working", "Not working"])
        except RuntimeError:
            f = failure.Failure()

        self.assertIsNotNone(f)
        p_f = pickle.dumps(f)
        f = pickle.loads(p_f)

        self.assertEqual(2, len(f.causes))
        self.assertEqual("Still not working", f.causes[0].exception_str)
        self.assertEqual("Not working", f.causes[1].exception_str)

        f = f.causes[0]
        self.assertEqual(1, len(f.causes))
        self.assertEqual("Not working", f.causes[0].exception_str)

        f = f.causes[0]
        self.assertEqual(0, len(f.causes)) 
开发者ID:openstack,项目名称:taskflow,代码行数:24,代码来源:test_failure.py

示例9: test_pickle_protein

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_pickle_protein():
    """Pickle proteins"""
    # Proteins
    rec = next(oddt.toolkit.readfile('pdb', xiap_receptor))
    # generate atom_dict
    assert rec.atom_dict is not None

    assert rec._atom_dict is not None
    pickled_rec = loads(dumps(rec))
    assert pickled_rec.protein is False
    assert pickled_rec._atom_dict is not None

    rec.protein = True
    # setting protein property should clean atom_dict cache
    assert rec._atom_dict is None
    # generate atom_dict
    assert rec.atom_dict is not None

    pickled_rec = loads(dumps(rec))
    assert pickled_rec.protein is True
    assert pickled_rec._atom_dict is not None 
开发者ID:oddt,项目名称:oddt,代码行数:23,代码来源:test_toolkit.py

示例10: pickle_invoke

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def pickle_invoke(func, target=None, protocol=None, *args):
    """pickle_invoke(func, *args, target=None, protocol=None)

    Create a byte sequence which when unpickled calls a callable with given
    arguments.

    Note:
        The function has to be importable using the same name on the system
        that unpickles this invocation.

    Arguments:
        func(callable): The function to call or class to instantiate.
        args(tuple): The arguments to call the callable with.
        target: The internals description of the targeted python
            version. If this is ``None`` the specification of the currently
            running python version will be used.
        protocol: The pickle protocol version to use (use None for default).

    Returns:
        bytes: The data that when unpickled calls ``func(*args)``.

    Example:
        >>> from pwny import *
        >>> import pickle
        >>> def hello(arg):
        ...     print('Hello, %s!' % arg)
        ...
        >>> pickle.loads(pickle_invoke(hello, 'world'))
        Hello, world!
    """

    protocol = get_protocol_version(protocol, target)
    return cPickle.dumps(PickleInvoke(func, *args), protocol) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:35,代码来源:pickle.py

示例11: store

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def store(self, thing):
        """
        Simple persistence method
        """
        to_store = {'field1': thing.field1,
                    'date_field': thing.date_field,
                    }
        to_store['stuff'] = Binary(cPickle.dumps(thing.stuff))
        # Respect any soft-quota on write - raises if stats().totals.size > quota 
        self._arctic_lib.check_quota()
        self._collection.insert_one(to_store) 
开发者ID:man-group,项目名称:arctic,代码行数:13,代码来源:how_to_custom_arctic_library.py

示例12: write

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def write(self, arctic_lib, version, symbol, item, _previous_version):
        # Currently we try to bson encode if the data is less than a given size and store it in
        # the version collection, but pickling might be preferable if we have characters that don't
        # play well with the bson encoder or if you always want your data in the data collection.
        if not SKIP_BSON_ENCODE_PICKLE_STORE:
            try:
                # If it's encodeable, then ship it
                b = bson.BSON.encode({'data': item})
                if len(b) < min(MAX_BSON_ENCODE, _HARD_MAX_BSON_ENCODE):
                    version['data'] = item
                    return
            except InvalidDocument:
                pass

        # Pickle, chunk and store the data
        collection = arctic_lib.get_top_level_collection()
        # Try to pickle it. This is best effort
        version['blob'] = _MAGIC_CHUNKEDV2
        pickled = cPickle.dumps(item, protocol=cPickle.HIGHEST_PROTOCOL)

        data = compress_array([pickled[i * _CHUNK_SIZE: (i + 1) * _CHUNK_SIZE] for i in xrange(int(len(pickled) / _CHUNK_SIZE + 1))])

        for seg, d in enumerate(data):
            segment = {'data': Binary(d)}
            segment['segment'] = seg
            seg += 1
            sha = checksum(symbol, segment)
            collection.update_one({'symbol': symbol, 'sha': sha},
                                  {'$set': segment, '$addToSet': {'parent': version['_id']}},
                                  upsert=True) 
开发者ID:man-group,项目名称:arctic,代码行数:32,代码来源:_pickle_store.py

示例13: test_write_object

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_write_object():
    arctic_lib = Mock()
    self = create_autospec(PickleStore)
    version = {'_id': ObjectId()}
    PickleStore.write(self, arctic_lib, version, 'sentinel.symbol', sentinel.item, sentinel.previous_version)
    assert 'data' not in version

    assert version['blob'] == '__chunked__V2'
    coll = arctic_lib.get_top_level_collection.return_value
    assert coll.update_one.call_args_list == [call({'sha': checksum('sentinel.symbol', {'segment': 0, 'data': Binary(compress(cPickle.dumps(sentinel.item, cPickle.HIGHEST_PROTOCOL)))}),
                                                    'symbol': 'sentinel.symbol'},
                                                   {'$set': {'segment': 0, 'data': Binary(compress(cPickle.dumps(sentinel.item, cPickle.HIGHEST_PROTOCOL)), 0)},
                                                    '$addToSet': {'parent': version['_id']}}, upsert=True)] 
开发者ID:man-group,项目名称:arctic,代码行数:15,代码来源:test_pickle_store.py

示例14: test_read_object_backwards_compat

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_read_object_backwards_compat():
    self = create_autospec(PickleStore)
    version = {'blob': Binary(compressHC(cPickle.dumps(object)))}
    assert PickleStore.read(self, sentinel.arctic_lib, version, sentinel.symbol) == object 
开发者ID:man-group,项目名称:arctic,代码行数:6,代码来源:test_pickle_store.py

示例15: test_read_object_2

# 需要导入模块: from six.moves import cPickle [as 别名]
# 或者: from six.moves.cPickle import dumps [as 别名]
def test_read_object_2():
    self = create_autospec(PickleStore)
    version = {'_id': sentinel._id,
               'blob': '__chunked__'}
    coll = Mock()
    arctic_lib = Mock()
    coll.find.return_value = [{'data': Binary(compressHC(cPickle.dumps(object))),
                               'symbol': 'sentinel.symbol',
                               'segment': 1}
                              ]
    arctic_lib.get_top_level_collection.return_value = coll

    assert PickleStore.read(self, arctic_lib, version, sentinel.symbol) == object
    assert coll.find.call_args_list == [call({'symbol': sentinel.symbol, 'parent': sentinel._id})] 
开发者ID:man-group,项目名称:arctic,代码行数:16,代码来源:test_pickle_store.py


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