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


Python cPickle.dumps方法代码示例

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

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

示例1: _augment_images_worker

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def _augment_images_worker(self, augseq, queue_source, queue_result):
        """Worker function that endlessly queries the source queue (input
        batches), augments batches in it and sends the result to the output
        queue."""
        while True:
            # wait for a new batch in the source queue and load it
            batch_str = queue_source.get()
            batch = pickle.loads(batch_str)

            # augment the batch
            if batch.images is not None and batch.keypoints is not None:
                augseq_det = augseq.to_deterministic()
                batch.images_aug = augseq_det.augment_images(batch.images)
                batch.keypoints_aug = augseq_det.augment_keypoints(batch.keypoints)
            elif batch.images is not None:
                batch.images_aug = augseq.augment_images(batch.images)
            elif batch.keypoints is not None:
                batch.keypoints_aug = augseq.augment_keypoints(batch.keypoints)

            # send augmented batch to output queue
            queue_result.put(pickle.dumps(batch, protocol=-1)) 
开发者ID:aleju,项目名称:cat-bbs,代码行数:23,代码来源:train.py


示例2: pickle_dict

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def pickle_dict(items):
    '''Returns a new dictionary where values which aren't instances of
    basestring are pickled. Also, a new key '_pickled' contains a comma
    separated list of keys corresponding to the pickled values.
    '''
    ret = {}
    pickled_keys = []
    for key, val in items.items():
        if isinstance(val, basestring):
            ret[key] = val
        else:
            pickled_keys.append(key)
            ret[key] = pickle.dumps(val)
    if pickled_keys:
        ret['_pickled'] = ','.join(pickled_keys)
    return ret 
开发者ID:jmarth,项目名称:plugin.video.kmediatorrent,代码行数:18,代码来源:common.py


示例3: put

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def put(self, o):
        """Encode object ``o`` and write it to the pipe.
        Block gevent-cooperatively until all data is written. The default
        encoder is ``pickle.dumps``.

        :arg o: a Python object that is encodable with the encoder of choice.

        Raises:
            - :exc:`GIPCError`
            - :exc:`GIPCClosed`
            - :exc:`pickle.PicklingError`

        """
        self._validate()
        with self._lock:
            bindata = self._encoder(o)
            self._write(struct.pack("!i", len(bindata)) + bindata) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:19,代码来源:gipc.py


示例4: to_metadata

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def to_metadata(self):
        metadata = dict()
        metadata['outputs'] = self.outputs
        metadata['inputs'] = self.inputs
        metadata['N'] = self.N
        metadata['data'] = {'x': self.data.x, 'Y': self.data.Y}
        metadata['distargs'] = self.get_distargs()
        metadata['params'] = self.get_params()
        metadata['factory'] = ('cgpm.regressions.ols', 'OrdinaryLeastSquares')

        # Pickle the sklearn regressor.
        regressor = metadata['params']['regressor']
        regressor_binary = base64.b64encode(cPickle.dumps(regressor))
        metadata['params']['regressor_binary'] = regressor_binary
        del metadata['params']['regressor']

        return metadata 
开发者ID:probcomp,项目名称:cgpm,代码行数:19,代码来源:ols.py


示例5: to_metadata

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def to_metadata(self):
        metadata = dict()
        metadata['outputs'] = self.outputs
        metadata['inputs'] = self.inputs
        metadata['N'] = self.N
        metadata['data'] = {'x': self.data.x, 'Y': self.data.Y}
        metadata['counts'] = self.counts
        metadata['distargs'] = self.get_distargs()
        metadata['hypers'] = self.get_hypers()
        metadata['params'] = self.get_params()
        metadata['factory'] = ('cgpm.regressions.forest', 'RandomForest')

        # Pickle the sklearn forest.
        forest = metadata['params']['forest']
        forest_binary = base64.b64encode(cPickle.dumps(forest))
        metadata['params']['forest_binary'] = forest_binary
        del metadata['params']['forest']

        return metadata 
开发者ID:probcomp,项目名称:cgpm,代码行数:21,代码来源:forest.py


示例6: setData

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def setData(self, data):
        """Add some data.
        
        Args:
            data (object): Object to add as data. This object has to be pickable. 
                Qt objects don't work!
        
        Raises:
            TypeError if data is not pickable
        """
        try:
            bytestream = pickle.dumps(data)
            super(MimeData, self).setData(self._mimeType, bytestream)
        except TypeError:
            raise TypeError, self.tr("can not pickle added data")
        except:
            raise 
开发者ID:datalyze-solutions,项目名称:pandas-qt,代码行数:19,代码来源:mime.py


示例7: __call__

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def __call__(self, *args, **kwargs):
        arguments = self.base_dict.copy()
        if not self.pass_arguments:
            if len(args) > 0:
                arguments.update(args[0])
            if kwargs:
                arguments.update(kwargs)
        else:
            spooler_args = {}
            for key in ('message_dict', 'spooler', 'priority', 'at', 'body'):
                if key in kwargs:
                    spooler_args.update({key: kwargs.pop(key)})
            arguments.update(spooler_args)
            arguments.update(
                {'args': pickle.dumps(args), 'kwargs': pickle.dumps(kwargs)})
        return uwsgi.spool(_encode_to_spooler(arguments))

    # For backward compatibility (uWSGI < 1.9.13) 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:uwsgidecorators.py


示例8: _build_model

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def _build_model(self):
        model_path = self._get_model_path()
        if os.path.isfile(model_path):
            return

        freq = {}
        print('building model..')
        for path, _ in tqdm.tqdm(iterate_data_files(self.from_dtm, self.to_dtm),
                                 mininterval=1):
            for line in open(path):
                seen = line.strip().split()[1:]
                for s in seen:
                    freq[s] = freq.get(s, 0) + 1
        freq = sorted(freq.items(), key=lambda x: x[1], reverse=True)
        open(model_path, 'wb').write(cPickle.dumps(freq, 2))
        print('model built') 
开发者ID:kakao-arena,项目名称:brunch-article-recommendation,代码行数:18,代码来源:mostpopular.py


示例9: _memoize

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def _memoize(func, *args, **kw):
    # should we refresh the cache?
    refresh = False
    refresh_kw = func.mrefresh_keyword

    # kw is not always set - check args
    if refresh_kw in func.__code__.co_varnames:
        if args[func.__code__.co_varnames.index(refresh_kw)]:
            refresh = True

    # check in kw if not already set above
    if not refresh and refresh_kw in kw:
        if kw[refresh_kw]:
            refresh = True

    key = pickle.dumps(args, 1) + pickle.dumps(kw, 1)

    cache = func.mcache
    if not refresh and key in cache:
        return cache[key]
    else:
        cache[key] = result = func(*args, **kw)
        return result 
开发者ID:pmorissette,项目名称:ffn,代码行数:25,代码来源:utils.py


示例10: apply

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def apply(self, callback, route):
        dumps = self.json_dumps
        if not dumps: return callback
        def wrapper(*a, **ka):
            try:
                rv = callback(*a, **ka)
            except HTTPError:
                rv = _e()

            if isinstance(rv, dict):
                #Attempt to serialize, raises exception on failure
                json_response = dumps(rv)
                #Set content type only if serialization succesful
                response.content_type = 'application/json'
                return json_response
            elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict):
                rv.body = dumps(rv.body)
                rv.content_type = 'application/json'
            return rv

        return wrapper 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:23,代码来源:__init__.py


示例11: pickle_dict

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def pickle_dict(items):
    """Convert `items` values into pickled values.

    Args:
        items (dict): A dictionary

    Returns:
        dict: Values which aren't instances of basestring are pickled. Also,
            a new key '_pickled' contains a comma separated list of keys
            corresponding to the pickled values.
    """
    ret = {}
    pickled_keys = []
    for k, v in items.items():
        if isinstance(v, basestring):
            ret[k] = v
        else:
            pickled_keys.append(k)
            ret[k] = pickle.dumps(v)
    if pickled_keys:
        ret['_pickled'] = ','.join(pickled_keys)
    return ret 
开发者ID:afrase,项目名称:kodiswift,代码行数:24,代码来源:common.py


示例12: makePickle

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def makePickle(self, record):
        """
        Pickles the record in binary format with a length prefix, and
        returns it ready for transmission across the socket.
        """
        ei = record.exc_info
        if ei:
            # just to get traceback text into record.exc_text ...
            dummy = self.format(record)
            record.exc_info = None  # to avoid Unpickleable error
        # See issue #14436: If msg or args are objects, they may not be
        # available on the receiving end. So we convert the msg % args
        # to a string, save it as msg and zap the args.
        d = dict(record.__dict__)
        d['msg'] = record.getMessage()
        d['args'] = None
        s = cPickle.dumps(d, 1)
        if ei:
            record.exc_info = ei  # for next handler
        slen = struct.pack(">L", len(s))
        return slen + s 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:handlers.py


示例13: TestCustomFormat

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def TestCustomFormat():
    OpenClipboard()
    try:
        # Just for the fun of it pickle Python objects through the clipboard
        fmt = RegisterClipboardFormat("Python Pickle Format")
        import cPickle
        pickled_object = Foo(a=1, b=2, Hi=3)
        SetClipboardData(fmt, cPickle.dumps( pickled_object ) )
        # Now read it back.
        data = GetClipboardData(fmt)
        loaded_object = cPickle.loads(data)
        assert cPickle.loads(data) == pickled_object, "Didnt get the correct data!"

        print "Clipboard custom format tests worked correctly"
    finally:
        CloseClipboard() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:win32clipboardDemo.py


示例14: test_float

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def test_float(self):
        for_bin_protos = [4.94e-324, 1e-310]
        neg_for_bin_protos = [-x for x in for_bin_protos]
        test_values = [0.0, 7e-308, 6.626e-34, 0.1, 0.5,
                       3.14, 263.44582062374053, 6.022e23, 1e30]
        test_proto0_values = test_values + [-x for x in test_values]
        test_values = test_proto0_values + for_bin_protos + neg_for_bin_protos

        for value in test_proto0_values:
            pickle = self.dumps(value, 0)
            got = self.loads(pickle)
            self.assertEqual(value, got)

        for proto in pickletester.protocols[1:]:
            for value in test_values:
                pickle = self.dumps(value, proto)
                got = self.loads(pickle)
                self.assertEqual(value, got)

    # Backwards compatibility was explicitly broken in r67934 to fix a bug. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_xpickle.py


示例15: test_pytype_long_ready

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def test_pytype_long_ready(self):
        # Testing SF bug 551412 ...

        # This dumps core when SF bug 551412 isn't fixed --
        # but only when test_descr.py is run separately.
        # (That can't be helped -- as soon as PyType_Ready()
        # is called for PyLong_Type, the bug is gone.)
        class UserLong(object):
            def __pow__(self, *args):
                pass
        try:
            pow(0L, UserLong(), 0L)
        except:
            pass

        # Another segfault only when run early
        # (before PyType_Ready(tuple) is called)
        type.mro(tuple) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_descr.py


示例16: to_string

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def to_string(self):
        return pickle.dumps(self, protocol=-1) 
开发者ID:aleju,项目名称:cat-bbs,代码行数:4,代码来源:plotting.py


示例17: _load_batches

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def _load_batches(self, load_batch_func, queue):
        while True:
            queue.put(pickle.dumps(load_batch_func(), protocol=-1)) 
开发者ID:aleju,项目名称:cat-bbs,代码行数:5,代码来源:train.py


示例18: dump_object

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def dump_object(self, value):
        """Dumps an object into a string for redis.  By default it serializes
        integers as regular string and pickle dumps everything else.
        """
        t = type(value)
        if t is int or t is long:
            return str(value)
        return '!' + pickle.dumps(value) 
开发者ID:jojoin,项目名称:cutout,代码行数:10,代码来源:rediscache.py


示例19: set

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def set(self, key, value, timeout=None):
        if timeout is None:
            timeout = self.default_timeout
        self._prune()
        self._cache[key] = (time() + timeout, pickle.dumps(value,
            pickle.HIGHEST_PROTOCOL)) 
开发者ID:jojoin,项目名称:cutout,代码行数:8,代码来源:memcache.py


示例20: add

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def add(self, key, value, timeout=None):
        if timeout is None:
            timeout = self.default_timeout
        if len(self._cache) > self._threshold:
            self._prune()
        item = (time() + timeout, pickle.dumps(value,
            pickle.HIGHEST_PROTOCOL))
        self._cache.setdefault(key, item) 
开发者ID:jojoin,项目名称:cutout,代码行数:10,代码来源:memcache.py


示例21: save

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def save(self, filename, protocol=-1):
        """Save a pickled serialization of the flow to 'filename'.
        If 'filename' is None, return a string.

        Note: the pickled Flow is not guaranteed to be upward or
        backward compatible."""
        if filename is None:
            return _cPickle.dumps(self, protocol)
        else:
            # if protocol != 0 open the file in binary mode
            mode = 'w' if protocol == 0 else 'wb'
            with open(filename, mode) as flh:
                _cPickle.dump(self, flh, protocol) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:15,代码来源:linear_flows.py


示例22: save

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def save(self, filename, protocol=-1):
        """Save a pickled serialization of the node to `filename`.
        If `filename` is None, return a string.

        Note: the pickled `Node` is not guaranteed to be forwards or
        backwards compatible."""
        if filename is None:
            return _cPickle.dumps(self, protocol)
        else:
            # if protocol != 0 open the file in binary mode
            mode = 'wb' if protocol != 0 else 'w'
            with open(filename, mode) as flh:
                _cPickle.dump(self, flh, protocol) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:15,代码来源:signal_node.py


示例23: _process_task

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def _process_task(self, data, task_callable, task_index):
        """Add a task, if possible without blocking.

        It blocks when the maximum number of threads is reached (given by
        n_threads) or when the system is not able to start a new thread.
        """
        task_started = False
        while not task_started:
            if self._n_active_threads >= self._n_threads:
                # release lock for other threads and wait
                self._lock.release()
                time.sleep(SLEEP_TIME)
                self._lock.acquire()
            else:
                self._lock.release()
                task_callable = task_callable.fork()
                if self.copy_callable:
                    # create a deep copy of the task_callable,
                    # since it might not be thread safe 
                    # (but the fork is still required)
                    as_str = pickle.dumps(task_callable, -1)
                    task_callable = pickle.loads(as_str)
                try:
                    thread = threading.Thread(target=self._task_thread,
                                              args=(data, task_callable,
                                                    task_index))
                    thread.start()
                    task_started = True
                except Exception:
                    if self.verbose:
                        print ("unable to create new thread,"
                               " waiting 2 seconds...")
                    time.sleep(2) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:35,代码来源:thread_schedule.py


示例24: get_node_size

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def get_node_size(x):
    """Return node total byte-size using cPickle with protocol=2.

    The byte-size is related to the memory needed by the node).
    """
    # TODO: add check for problematic node types, like NoiseNode?
    # TODO: replace this with sys.getsizeof for Python >= 2.6
    size = len(cPickle.dumps(x, protocol = 2))
    return size 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:11,代码来源:introspection.py


示例25: __setitem__

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def __setitem__(self, key, value, expires=None):
        self._db[key] = pickle.dumps((expires, value)) 
开发者ID:RIPE-NCC,项目名称:ripe-atlas-tools,代码行数:4,代码来源:cache.py


示例26: __call__

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def __call__(self, *args, **kwargs):

        key = pickle.dumps([args, kwargs])
        value = cache[key]

        if value:
            return value

        value = self._function(*args, **kwargs)
        cache.set(key, value, self._cache_time)

        return value 
开发者ID:RIPE-NCC,项目名称:ripe-atlas-tools,代码行数:14,代码来源:cache.py


示例27: db_value

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def db_value(self, value):
        if value is not None:
            return pickle.dumps(value) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:5,代码来源:fields.py


示例28: _default_encoder

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def _default_encoder(o):
    return pickle.dumps(o, pickle.HIGHEST_PROTOCOL) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:4,代码来源:gipc.py


示例29: test_pickle

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def test_pickle(ms_lib):
    buff = pickle.dumps(ms_lib)
    mnew = pickle.loads(buff)
    assert ms_lib._arctic_lib.get_name() == mnew._arctic_lib.get_name()

    assert "arctic_test.TEST" in str(ms_lib)
    assert str(ms_lib) == repr(ms_lib) 
开发者ID:man-group,项目名称:arctic,代码行数:9,代码来源:test_metadata_store.py


示例30: test_arctic_set_get_state

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import dumps [as 别名]
def test_arctic_set_get_state():
    sentinel.mongo_host = Mock(nodes={("host", "port")})
    with patch('arctic._cache.Cache.__init__', autospec=True, return_value=None):
        store = Arctic(sentinel.mongo_host, allow_secondary="allow_secondary", app_name="app_name",
                       socketTimeoutMS=1234, connectTimeoutMS=2345, serverSelectionTimeoutMS=3456)
        buff = pickle.dumps(store)
        mnew = pickle.loads(buff)
        assert mnew.mongo_host == "host:port"
        assert mnew._allow_secondary == "allow_secondary"
        assert mnew._application_name == "app_name"
        assert mnew._socket_timeout == 1234
        assert mnew._connect_timeout == 2345
        assert mnew._server_selection_timeout == 3456 
开发者ID:man-group,项目名称:arctic,代码行数:15,代码来源:test_arctic.py



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