• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python cPickle.loads函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中six.moves.cPickle.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_pickling

 def test_pickling(self):
     """intbitset - pickling"""
     from six.moves import cPickle
     for set1 in self.sets + [[]]:
         self.assertEqual(self.intbitset(set1), cPickle.loads(cPickle.dumps(self.intbitset(set1), -1)))
     for set1 in self.sets + [[]]:
         self.assertEqual(self.intbitset(set1, trailing_bits=True), cPickle.loads(cPickle.dumps(self.intbitset(set1, trailing_bits=True), -1)))
开发者ID:inveniosoftware,项目名称:intbitset,代码行数:7,代码来源:test_intbitset.py


示例2: test_none_Constant

def test_none_Constant():
    """ Tests equals

    We had an error in the past with unpickling
    """
    o1 = Constant(NoneTypeT(), None, name='NoneConst')
    o2 = Constant(NoneTypeT(), None, name='NoneConst')
    assert o1.equals(o2)
    assert NoneConst.equals(o1)
    assert o1.equals(NoneConst)
    assert NoneConst.equals(o2)
    assert o2.equals(NoneConst)

    # This trigger equals that returned the wrong answer in the past.
    import six.moves.cPickle as pickle
    import theano
    from theano import tensor

    x = tensor.vector('x')
    y = tensor.argmax(x)
    kwargs = {}
    # We can't pickle DebugMode
    if theano.config.mode in ["DebugMode", "DEBUG_MODE"]:
        kwargs = {'mode': 'FAST_RUN'}
    f = theano.function([x], [y], **kwargs)
    pickle.loads(pickle.dumps(f))
开发者ID:ALISCIFP,项目名称:Segmentation,代码行数:26,代码来源:test_type_other.py


示例3: test_polar

def test_polar():
    ax = plt.subplot(111, polar=True)
    fig = plt.gcf()
    result = BytesIO()
    pf = pickle.dumps(fig)
    pickle.loads(pf)
    plt.draw()
开发者ID:7924102,项目名称:matplotlib,代码行数:7,代码来源:test_pickle.py


示例4: test_rrulewrapper

def test_rrulewrapper():
    r = rrulewrapper(2)
    try:
        pickle.loads(pickle.dumps(r))
    except RecursionError:
        print('rrulewrapper pickling test failed')
        raise
开发者ID:AlexandreAbraham,项目名称:matplotlib,代码行数:7,代码来源:test_pickle.py


示例5: test_store_update_context

def test_store_update_context():
    src.val.nested = 'nested{{src.ccdid}}'
    src.val['ccdid'] = 2
    src['srcdir'] = 'obs{{ src.obsid }}/{{src.nested}}'
    files['srcdir'] = '{{ src.srcdir }}'
    src['obsid'] = 123
    src.val['ccdid'] = 2
    src['ra'] = 1.4343256789
    src['ra'].format = '%.4f'
    files['evt2'] = 'obs{{ src.obsid }}/{{src.nested}}/acis_evt2'
    src.val.nested = 'nested{{src.ccdid}}'

    tmp = pickle.dumps(src)
    tmp2 = pickle.dumps(files)

    src.clear()
    files.clear()

    assert src['ra'].val is None
    assert files['evt2'].val is None

    src.update(pickle.loads(tmp))
    files.update(pickle.loads(tmp2))

    assert str(src['ra']) == '1.4343'
    assert str(src['srcdir']) == 'obs123/nested2'
    assert files['srcdir'].rel == 'data/obs123/nested2'
    assert files.rel.srcdir == 'data/obs123/nested2'
    assert str(files['evt2.fits']) == 'data/obs123/nested2/acis_evt2.fits'
开发者ID:sot,项目名称:pyyaks,代码行数:29,代码来源:test_context.py


示例6: test_run_in_runclassmethod

def test_run_in_runclassmethod():
    class C(object):
        @classmethod
        def fn(cls, *args, **kwargs):
            return cls, args, kwargs
    C.__name__ = 'C_' + str(uuid4()).replace('-', '_')
    C.__module__ = 'pytest_shutil.run'
    with patch('pytest_shutil.run.execnet') as execnet:
        gw = execnet.makegateway.return_value
        chan = gw.remote_exec.return_value
        chan.receive.return_value = cPickle.dumps(sentinel.ret)
        c = C()
        with patch.object(run, C.__name__, C, create=True):
            run.run_in_subprocess(c.fn, python='sentinel.python')(ARG, kw=KW)
            ((s,), _) = chan.send.call_args
            if sys.version_info < (3, 0, 0):
                # Class methods are not pickleable in Python 2.
                assert cPickle.loads(s) == (run._invoke_method, (C, 'fn', ARG), {'kw': KW})
            else:
                # Class methods are pickleable in Python 3.
                assert cPickle.loads(s) == (c.fn, (ARG,), {'kw': KW})
            ((remote_fn,), _) = gw.remote_exec.call_args
            ((chan.receive.return_value,), _) = chan.send.call_args
            remote_fn(chan)
            chan.send.assert_called_with(cPickle.dumps((C, (ARG,), {'kw': KW}), protocol=0))
开发者ID:manahl,项目名称:pytest-plugins,代码行数:25,代码来源:test_run.py


示例7: test_pickle

    def test_pickle(self):
        a = T.scalar()  # the a is for 'anonymous' (un-named).
        x, s = T.scalars('xs')

        f = function([x, In(a, value=1.0, name='a'), In(s, value=0.0, update=s+a*x, mutable=True)], s+a*x)

        try:
            # Note that here we also test protocol 0 on purpose, since it
            # should work (even though one should not use it).
            g = pickle.loads(pickle.dumps(f, protocol=0))
            g = pickle.loads(pickle.dumps(f, protocol=-1))
        except NotImplementedError as e:
            if e[0].startswith('DebugMode is not picklable'):
                return
            else:
                raise
        # if they both return, assume  that they return equivalent things.
        # print [(k,id(k)) for k in f.finder.keys()]
        # print [(k,id(k)) for k in g.finder.keys()]

        self.assertFalse(g.container[0].storage is f.container[0].storage)
        self.assertFalse(g.container[1].storage is f.container[1].storage)
        self.assertFalse(g.container[2].storage is f.container[2].storage)
        self.assertFalse(x in g.container)
        self.assertFalse(x in g.value)

        self.assertFalse(g.value[1] is f.value[1])  # should not have been copied
        self.assertFalse(g.value[2] is f.value[2])  # should have been copied because it is mutable.
        self.assertFalse((g.value[2] != f.value[2]).any())  # its contents should be identical

        self.assertTrue(f(2, 1) == g(2))  # they should be in sync, default value should be copied.
        self.assertTrue(f(2, 1) == g(2))  # they should be in sync, default value should be copied.
        f(1, 2)  # put them out of sync
        self.assertFalse(f(1, 2) == g(1, 2))  # they should not be equal anymore.
开发者ID:ChienliMa,项目名称:Theano,代码行数:34,代码来源:test_function_module.py


示例8: test_unpickle_wrongname

 def test_unpickle_wrongname(self, universe_n, pickle_str_n):
     # we change the universe's anchor_name
     universe_n.anchor_name = "test2"
     # shouldn't unpickle if no name matches, even if there's a compatible
     # universe in the unnamed anchor list.
     with pytest.raises(RuntimeError):
         cPickle.loads(pickle_str_n)
开发者ID:MDAnalysis,项目名称:mdanalysis,代码行数:7,代码来源:test_persistence.py


示例9: _load_flann_model

    def _load_flann_model(self):
        if not self._descr_cache and not self._descr_cache_elem.is_empty():
            # Load descriptor cache
            # - is copied on fork, so only need to load here.
            self._log.debug("Loading cached descriptors")
            self._descr_cache = \
                cPickle.loads(self._descr_cache_elem.get_bytes())

        # Params pickle include the build params + our local state params
        if self._index_param_elem and not self._index_param_elem.is_empty():
            state = cPickle.loads(self._index_param_elem.get_bytes())
            self._build_autotune = state['b_autotune']
            self._build_target_precision = state['b_target_precision']
            self._build_sample_frac = state['b_sample_frac']
            self._distance_method = state['distance_method']
            self._flann_build_params = state['flann_build_params']

        # Load the binary index
        if self._index_elem and not self._index_elem.is_empty():
            # make numpy matrix of descriptor vectors for FLANN
            pts_array = [d.vector() for d in self._descr_cache]
            pts_array = numpy.array(pts_array, dtype=pts_array[0].dtype)
            pyflann.set_distance_type(self._distance_method)
            self._flann = pyflann.FLANN()
            tmp_fp = self._index_elem.write_temp()
            self._flann.load_index(tmp_fp, pts_array)
            self._index_elem.clean_temp()
            del pts_array, tmp_fp

        # Set current PID to the current
        self._pid = multiprocessing.current_process().pid
开发者ID:Kitware,项目名称:SMQTK,代码行数:31,代码来源:flann.py


示例10: test_added_descriptor_table_caching

    def test_added_descriptor_table_caching(self):
        cache_elem = DataMemoryElement(readonly=False)
        descrs = [random_descriptor() for _ in range(3)]
        expected_table = dict((r.uuid(), r) for r in descrs)

        i = MemoryDescriptorIndex(cache_elem)
        self.assertTrue(cache_elem.is_empty())

        # Should add descriptors to table, caching to writable element.
        i.add_many_descriptors(descrs)
        self.assertFalse(cache_elem.is_empty())
        self.assertEqual(pickle.loads(i.cache_element.get_bytes()),
                         expected_table)

        # Changing the internal table (remove, add) it should reflect in
        # cache
        new_d = random_descriptor()
        expected_table[new_d.uuid()] = new_d
        i.add_descriptor(new_d)
        self.assertEqual(pickle.loads(i.cache_element.get_bytes()),
                         expected_table)

        rm_d = list(expected_table.values())[0]
        del expected_table[rm_d.uuid()]
        i.remove_descriptor(rm_d.uuid())
        self.assertEqual(pickle.loads(i.cache_element.get_bytes()),
                         expected_table)
开发者ID:Kitware,项目名称:SMQTK,代码行数:27,代码来源:test_DI_memory.py


示例11: set_user_definitions

 def set_user_definitions(self, definitions):
     if definitions:
         if six.PY2:
             self.user = pickle.loads(base64.decodestring(definitions.encode('ascii')))
         else:
             self.user = pickle.loads(base64.decodebytes(definitions.encode('ascii')))
     else:
         self.user = {}
开发者ID:Averroes,项目名称:Mathics,代码行数:8,代码来源:definitions.py


示例12: test_unpickle_noanchor

 def test_unpickle_noanchor(self, universe, pickle_str):
     # Shouldn't unpickle if the universe is removed from the anchors
     universe.remove_anchor()
     # In the complex (parallel) testing environment there's the risk of
     # other compatible Universes being available for anchoring even after
     # this one is expressly removed.
     # assert_raises(RuntimeError, cPickle.loads, pickle_str)
     with pytest.raises(RuntimeError):
         cPickle.loads(pickle_str)
开发者ID:MDAnalysis,项目名称:mdanalysis,代码行数:9,代码来源:test_persistence.py


示例13: test_serialization

    def test_serialization(self):
        e = smqtk.representation.classification_element.memory\
            .MemoryClassificationElement('test', 0)

        e2 = cPickle.loads(cPickle.dumps(e))
        self.assertEqual(e, e2)

        e.set_classification(a=0, b=1)
        e2 = cPickle.loads(cPickle.dumps(e))
        self.assertEqual(e, e2)
开发者ID:Kitware,项目名称:SMQTK,代码行数:10,代码来源:test_CE_memory.py


示例14: assert_pickle_idempotent

def assert_pickle_idempotent(obj):
    '''Assert that obj does not change (w.r.t. ==) under repeated picklings
    '''
    from six.moves.cPickle import dumps, loads
    obj1 = loads(dumps(obj))
    obj2 = loads(dumps(obj1))
    obj3 = loads(dumps(obj2))
    assert_equivalent(obj, obj1)
    assert_equivalent(obj, obj2)
    assert_equivalent(obj, obj3)
    assert type(obj) is type(obj3)
开发者ID:mbodenhamer,项目名称:syn,代码行数:11,代码来源:py.py


示例15: get

 def get(self, id):
     envelope_raw, attempts, delivered_indexes_raw = \
         self.redis.hmget(self._get_key(id), 'envelope', 'attempts',
                          'delivered_indexes')
     if not envelope_raw:
         raise KeyError(id)
     envelope = cPickle.loads(envelope_raw)
     del envelope_raw
     if delivered_indexes_raw:
         delivered_indexes = cPickle.loads(delivered_indexes_raw)
         self._remove_delivered_rcpts(envelope, delivered_indexes)
     return envelope, int(attempts or 0)
开发者ID:oasiswork,项目名称:python-slimta-redisstorage,代码行数:12,代码来源:__init__.py


示例16: assert_sml_written_to_db

 def assert_sml_written_to_db(self, sml, voter_id):
     with sqlite3.connect("sqlite_sink.db") as conn:
         c = conn.cursor()
         c.execute('SELECT sml FROM smls WHERE voter_id = "' +
                   voter_id + '"')
         fetched_sml = c.fetchone()
         if six.PY2:
             fetched_sml = cPickle.loads(str(fetched_sml[0]))
         else:
             fetched_sml = cPickle.loads(fetched_sml[0])
         self.assertEqual(len(sml), len(fetched_sml))
         self.assertTrue((sml == fetched_sml).all())
开发者ID:openstack,项目名称:monasca-analytics,代码行数:12,代码来源:test_base_sqlite.py


示例17: iterdescriptors

 def iterdescriptors(self):
     """
     Return an iterator over indexed descriptor element instances.
     """
     r = self.solr.select('%s:%s %s:*'
                          % (self.index_uuid_field, self.index_uuid,
                             self.descriptor_field))
     for doc in r.results:
         yield cPickle.loads(doc[self.descriptor_field])
     for _ in range(r.numFound // 10):
         r = r.next_batch()
         for doc in r.results:
             yield cPickle.loads(doc[self.descriptor_field])
开发者ID:Kitware,项目名称:SMQTK,代码行数:13,代码来源:solr_index.py


示例18: iteritems

 def iteritems(self):
     """
     Return an iterator over indexed descriptor key and instance pairs.
     """
     r = self.solr.select('%s:%s %s:* %s:*'
                          % (self.index_uuid_field, self.index_uuid,
                             self.d_uid_field, self.descriptor_field))
     for doc in r.results:
         d = cPickle.loads(doc[self.descriptor_field])
         yield d.uuid(), d
     for _ in range(r.numFound // 10):
         r = r.next_batch()
         for doc in r.results:
             d = cPickle.loads(doc[self.descriptor_field])
             yield d.uuid(), d
开发者ID:Kitware,项目名称:SMQTK,代码行数:15,代码来源:solr_index.py


示例19: get

        def get(self, block=True, timeout=None):
            """
            Retrieves the next item in the queue.

            Parameters
            ----------
            block: bool, default is True
                If true, the queue is blocked until it an object is retrieved reaches the timeout.
            timeout: long
                The timeout (in seconds) that the method should wait for the queue to return an item. If block is False,
                time wil ignored.

            Returns
            -------
            item: object

            """
            if block:
                item = self._db.blpop(self._key, timeout=timeout)
                if item:
                    item = item[1]
                logger.debug("Wait...")
            else:
                item = self._db.lpop(self._key)
                logger.debug("No-wait...")

            logger.debug("Item: %s" % [item])
            if item:
                return pickle.loads(item)
            else:
                raise six.moves.queue.Empty
开发者ID:KristianJensen,项目名称:cameo,代码行数:31,代码来源:parallel.py


示例20: test_pickle_unpickle_without_reoptimization

def test_pickle_unpickle_without_reoptimization():
    mode = theano.config.mode
    if mode in ["DEBUG_MODE", "DebugMode"]:
        mode = "FAST_RUN"
    x1 = T.fmatrix('x1')
    x2 = T.fmatrix('x2')
    x3 = theano.shared(numpy.ones((10, 10), dtype=floatX))
    x4 = theano.shared(numpy.ones((10, 10), dtype=floatX))
    y = T.sum(T.sum(T.sum(x1**2 + x2) + x3) + x4)

    updates = OrderedDict()
    updates[x3] = x3 + 1
    updates[x4] = x4 + 1
    f = theano.function([x1, x2], y, updates=updates, mode=mode)

    # now pickle the compiled theano fn
    string_pkl = pickle.dumps(f, -1)

    # compute f value
    in1 = numpy.ones((10, 10), dtype=floatX)
    in2 = numpy.ones((10, 10), dtype=floatX)

    # test unpickle without optimization
    default = theano.config.reoptimize_unpickled_function
    try:
        # the default is True
        theano.config.reoptimize_unpickled_function = False
        f_ = pickle.loads(string_pkl)
        assert f(in1, in2) == f_(in1, in2)
    finally:
        theano.config.reoptimize_unpickled_function = default
开发者ID:ALISCIFP,项目名称:Segmentation,代码行数:31,代码来源:test_pickle_unpickle_theano_fn.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python configparser.ConfigParser类代码示例发布时间:2022-05-27
下一篇:
Python cPickle.load函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap