當前位置: 首頁>>代碼示例>>Python>>正文


Python copyreg.pickle方法代碼示例

本文整理匯總了Python中six.moves.copyreg.pickle方法的典型用法代碼示例。如果您正苦於以下問題:Python copyreg.pickle方法的具體用法?Python copyreg.pickle怎麽用?Python copyreg.pickle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six.moves.copyreg的用法示例。


在下文中一共展示了copyreg.pickle方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_protocol_version

# 需要導入模塊: from six.moves import copyreg [as 別名]
# 或者: from six.moves.copyreg import pickle [as 別名]
def get_protocol_version(protocol=None, target=None):
    """
    Return a suitable pickle protocol version for a given target.

    Arguments:
        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(None or int): The requested protocol version (or None for the
            default of the target python version).

    Returns:
        int: A suitable pickle protocol version.
    """

    target = get_py_internals(target)

    if protocol is None:
        protocol = target['pickle_default_protocol']

    if protocol > cPickle.HIGHEST_PROTOCOL:
        warnings.warn('Downgrading pickle protocol, running python supports up to %d.' % cPickle.HIGHEST_PROTOCOL)
        protocol = cPickle.HIGHEST_PROTOCOL

    target_highest_protocol = target['pickle_highest_protocol']
    if protocol > target_highest_protocol:
        warnings.warn('Downgrading pickle protocol, target python supports up to %d.' % target_highest_protocol)
        protocol = target_highest_protocol

    return protocol 
開發者ID:edibledinos,項目名稱:pwnypack,代碼行數:32,代碼來源:pickle.py

示例2: pickle_invoke

# 需要導入模塊: from six.moves import copyreg [as 別名]
# 或者: from six.moves.copyreg import pickle [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

示例3: _pickle_Function

# 需要導入模塊: from six.moves import copyreg [as 別名]
# 或者: from six.moves.copyreg import pickle [as 別名]
def _pickle_Function(f):
    # copy of the input storage list
    ins = list(f.input_storage)
    input_storage = []

    for (input, indices, inputs), (required, refeed, default) in \
            zip(f.indices, f.defaults):
        if isinstance(input, SymbolicInputKit):
            li = len(indices)
            if not default:
                input_storage.append(ins[:li])
            else:
                input_storage.append(default)
            ins[:li] = []
        else:
            input_storage.append(ins[0])
            del ins[0]

    inputs_data = [x.data for x in f.input_storage]

    # HACK to detect aliased storage.
    # This is here because aliased relationships are not [currently]
    # preserved across the pickle operation
    if not (f.pickle_aliased_memory_strategy == 'ignore'):
        all_data = input_storage + inputs_data
        for i, d_i in enumerate(all_data):
            for j, d_j in enumerate(all_data):
                if ((i < j) and isinstance(d_i, numpy.ndarray) and
                        isinstance(d_j, numpy.ndarray)):
                    if numpy.may_share_memory(d_i, d_j):
                        if f.pickle_aliased_memory_strategy == 'warn':
                            _logger.warning('aliased relationship between '
                                            'Function arguments %s, %s '
                                            'will not be preserved by '
                                            'un-pickling operation' %
                                            (str(d_i), str(d_j)))
                        else:
                            raise AliasedMemoryError(d_i, d_j)
    rval = (_constructor_Function, (f.maker, input_storage, inputs_data))
    return rval 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:42,代碼來源:function_module.py

示例4: _pickle_method

# 需要導入模塊: from six.moves import copyreg [as 別名]
# 或者: from six.moves.copyreg import pickle [as 別名]
def _pickle_method(m):
    """Make instance methods pickable

    See http://stackoverflow.com/questions/1816958/cant-pickle-type-instancemethod-when-using-pythons-multiprocessing-pool-ma/1816969#1816969
    """
    if m.im_self is None:
        return getattr, (m.im_class, m.im_func.func_name)
    else:
        return getattr, (m.im_self, m.im_func.func_name) 
開發者ID:mozilla,項目名稱:python_moztelemetry,代碼行數:11,代碼來源:dataset.py

示例5: fix_proto_pickling

# 需要導入模塊: from six.moves import copyreg [as 別名]
# 或者: from six.moves.copyreg import pickle [as 別名]
def fix_proto_pickling():
  """Fix pickling issues (see b/121323638)."""
  for proto_cls in _PROTO_CLASSES:
    copyreg.pickle(proto_cls, _pickle_proto) 
開發者ID:tensorflow,項目名稱:transform,代碼行數:6,代碼來源:pickle_helper.py

示例6: __init__

# 需要導入模塊: from six.moves import copyreg [as 別名]
# 或者: from six.moves.copyreg import pickle [as 別名]
def __init__(cls, name, bases, dictionary):
    """Here we perform the majority of our work on the class.
    We add enum getters, an __init__ method, implementations
    of all Message methods, and properties for all fields
    in the protocol type.

    Args:
      name: Name of the class (ignored, but required by the
        metaclass protocol).
      bases: Base classes of the class we're constructing.
        (Should be message.Message).  We ignore this field, but
        it's required by the metaclass protocol
      dictionary: The class dictionary of the class we're
        constructing.  dictionary[_DESCRIPTOR_KEY] must contain
        a Descriptor object describing this protocol message
        type.
    """
    descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
    cls._decoders_by_tag = {}
    cls._extensions_by_name = {}
    cls._extensions_by_number = {}
    if (descriptor.has_options and
        descriptor.GetOptions().message_set_wire_format):
      cls._decoders_by_tag[decoder.MESSAGE_SET_ITEM_TAG] = (
          decoder.MessageSetItemDecoder(cls._extensions_by_number), None)

    # Attach stuff to each FieldDescriptor for quick lookup later on.
    for field in descriptor.fields:
      _AttachFieldHelpers(cls, field)

    descriptor._concrete_class = cls  # pylint: disable=protected-access
    _AddEnumValues(descriptor, cls)
    _AddInitMethod(descriptor, cls)
    _AddPropertiesForFields(descriptor, cls)
    _AddPropertiesForExtensions(descriptor, cls)
    _AddStaticMethods(cls)
    _AddMessageMethods(descriptor, cls)
    _AddPrivateHelperMethods(descriptor, cls)
    copyreg.pickle(cls, lambda obj: (cls, (), obj.__getstate__()))

    superclass = super(GeneratedProtocolMessageType, cls)
    superclass.__init__(name, bases, dictionary)


# Stateless helpers for GeneratedProtocolMessageType below.
# Outside clients should not access these directly.
#
# I opted not to make any of these methods on the metaclass, to make it more
# clear that I'm not really using any state there and to keep clients from
# thinking that they have direct access to these construction helpers. 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:52,代碼來源:python_message.py


注:本文中的six.moves.copyreg.pickle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。