[Python-modules-commits] [dill] 01/08: Import dill_0.2.5.orig.tar.gz

Josué Ortega noahfx-guest at moszumanska.debian.org
Wed Feb 10 14:40:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

noahfx-guest pushed a commit to branch master
in repository dill.

commit 95b6d9690692ebec3128948373c7ef3fff4daf98
Author: Josue Ortega <josueortega at debian.org.gt>
Date:   Wed Feb 10 08:00:55 2016 -0600

    Import dill_0.2.5.orig.tar.gz
---
 LICENSE                    |   2 +-
 MANIFEST                   |   1 +
 PKG-INFO                   |  10 +-
 README                     |   6 +-
 dill.egg-info/PKG-INFO     |  10 +-
 dill.egg-info/SOURCES.txt  |   1 +
 dill/__diff.py             |   2 +-
 dill/__init__.py           |   4 +-
 dill/_objects.py           |   4 +-
 dill/detect.py             |   2 +-
 dill/dill.py               | 280 ++++++++++++++++++++++++++++++++++++---------
 dill/info.py               |  12 +-
 dill/objtypes.py           |   2 +-
 dill/pointers.py           |   2 +-
 dill/settings.py           |   2 +-
 dill/source.py             |   2 +-
 dill/temp.py               |   2 +-
 scripts/get_objgraph.py    |   2 +-
 scripts/unpickle.py        |   2 +-
 setup.py                   |   6 +-
 tests/dill_bugs.py         |   2 +-
 tests/test_check.py        |  45 ++++++++
 tests/test_classdef.py     |  31 ++++-
 tests/test_detect.py       |   7 +-
 tests/test_diff.py         |   2 +-
 tests/test_extendpickle.py |   2 +-
 tests/test_file.py         |   2 +-
 tests/test_functors.py     |   2 +-
 tests/test_mixins.py       |   2 +-
 tests/test_module.py       |   2 +-
 tests/test_moduledict.py   |   2 +-
 tests/test_nested.py       |   2 +-
 tests/test_objects.py      |   2 +-
 tests/test_properties.py   |   2 +-
 tests/test_source.py       |   7 ++
 tests/test_temp.py         |   2 +-
 tests/test_weakref.py      |   2 +-
 37 files changed, 364 insertions(+), 106 deletions(-)

diff --git a/LICENSE b/LICENSE
index 9dd85c2..47e842e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -31,5 +31,5 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-Copyright (c) 2015 California Institute of Technology. All rights reserved.
+Copyright (c) 2016 California Institute of Technology. All rights reserved.
 
diff --git a/MANIFEST b/MANIFEST
index 0b6eb71..b579b34 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -23,6 +23,7 @@ dill.egg-info/top_level.txt
 scripts/get_objgraph.py
 scripts/unpickle.py
 tests/dill_bugs.py
+tests/test_check.py
 tests/test_classdef.py
 tests/test_detect.py
 tests/test_diff.py
diff --git a/PKG-INFO b/PKG-INFO
index fa9cbb4..32c0af0 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: dill
-Version: 0.2.4
+Version: 0.2.5
 Summary: a utility for serialization of python objects
 Home-page: http://www.cacr.caltech.edu/~mmckerns
 Author: Mike McKerns
@@ -75,7 +75,7 @@ Description: -----------------------------
         Current Release
         ===============
         
-        This version is dill-0.2.4.
+        This version is dill-0.2.5.
         
         The latest stable version of dill is available from::
         
@@ -113,8 +113,8 @@ Description: -----------------------------
         download the tarball, unzip, and run the installer::
         
             [download]
-            $ tar -xvzf dill-0.2.4.tgz
-            $ cd dill-0.2.4
+            $ tar -xvzf dill-0.2.5.tgz
+            $ cd dill-0.2.5
             $ python setup py build
             $ python setup py install
         
diff --git a/README b/README
index d4ae629..89ccc00 100644
--- a/README
+++ b/README
@@ -67,7 +67,7 @@ Dill also provides the capability to::
 Current Release
 ===============
 
-This version is dill-0.2.4.
+This version is dill-0.2.5.
 
 The latest stable version of dill is available from::
 
@@ -105,8 +105,8 @@ Dill is packaged to install from source, so you must
 download the tarball, unzip, and run the installer::
 
     [download]
-    $ tar -xvzf dill-0.2.4.tgz
-    $ cd dill-0.2.4
+    $ tar -xvzf dill-0.2.5.tgz
+    $ cd dill-0.2.5
     $ python setup py build
     $ python setup py install
 
diff --git a/dill.egg-info/PKG-INFO b/dill.egg-info/PKG-INFO
index fa9cbb4..32c0af0 100644
--- a/dill.egg-info/PKG-INFO
+++ b/dill.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: dill
-Version: 0.2.4
+Version: 0.2.5
 Summary: a utility for serialization of python objects
 Home-page: http://www.cacr.caltech.edu/~mmckerns
 Author: Mike McKerns
@@ -75,7 +75,7 @@ Description: -----------------------------
         Current Release
         ===============
         
-        This version is dill-0.2.4.
+        This version is dill-0.2.5.
         
         The latest stable version of dill is available from::
         
@@ -113,8 +113,8 @@ Description: -----------------------------
         download the tarball, unzip, and run the installer::
         
             [download]
-            $ tar -xvzf dill-0.2.4.tgz
-            $ cd dill-0.2.4
+            $ tar -xvzf dill-0.2.5.tgz
+            $ cd dill-0.2.5
             $ python setup py build
             $ python setup py install
         
diff --git a/dill.egg-info/SOURCES.txt b/dill.egg-info/SOURCES.txt
index 61ce4de..ab97f65 100644
--- a/dill.egg-info/SOURCES.txt
+++ b/dill.egg-info/SOURCES.txt
@@ -23,6 +23,7 @@ dill.egg-info/top_level.txt
 scripts/get_objgraph.py
 scripts/unpickle.py
 tests/dill_bugs.py
+tests/test_check.py
 tests/test_classdef.py
 tests/test_detect.py
 tests/test_diff.py
diff --git a/dill/__diff.py b/dill/__diff.py
index 3d3f699..df13e06 100644
--- a/dill/__diff.py
+++ b/dill/__diff.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 
diff --git a/dill/__init__.py b/dill/__init__.py
index eea1e9b..29c0476 100644
--- a/dill/__init__.py
+++ b/dill/__init__.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 
@@ -24,7 +24,7 @@ __license__ = """
 """ + __license__
 
 from .dill import dump, dumps, load, loads, dump_session, load_session, \
-    Pickler, Unpickler, register, copy, pickle, pickles, \
+    Pickler, Unpickler, register, copy, pickle, pickles, check, \
     HIGHEST_PROTOCOL, DEFAULT_PROTOCOL, PicklingError, UnpicklingError, \
     HANDLE_FMODE, CONTENTS_FMODE, FILE_FMODE
 from . import source, temp, detect
diff --git a/dill/_objects.py b/dill/_objects.py
index 2d9e20b..802c45b 100644
--- a/dill/_objects.py
+++ b/dill/_objects.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 """
@@ -371,7 +371,7 @@ except NameError:
     # built-in constants (CH 4)
     a['QuitterType'] = quit
     d['ExitType'] = a['QuitterType']
-try: # numpy
+try: # numpy #FIXME: slow... 0.05 to 0.1 sec to import numpy
     from numpy import ufunc as _numpy_ufunc
     from numpy import array as _numpy_array
     from numpy import int32 as _numpy_int32
diff --git a/dill/detect.py b/dill/detect.py
index d5126f3..2a176be 100644
--- a/dill/detect.py
+++ b/dill/detect.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 """
diff --git a/dill/dill.py b/dill/dill.py
index a2340b7..a7aca4f 100644
--- a/dill/dill.py
+++ b/dill/dill.py
@@ -16,7 +16,7 @@ Test against CH16+ Std. Lib. ... TBD.
 """
 __all__ = ['dump','dumps','load','loads','dump_session','load_session',
            'Pickler','Unpickler','register','copy','pickle','pickles',
-           'HIGHEST_PROTOCOL','DEFAULT_PROTOCOL','PicklingError',
+           'check','HIGHEST_PROTOCOL','DEFAULT_PROTOCOL','PicklingError',
            'UnpicklingError','HANDLE_FMODE','CONTENTS_FMODE','FILE_FMODE']
 
 import logging
@@ -28,12 +28,14 @@ def _trace(boolean):
     else: log.setLevel(logging.WARN)
     return
 
+stack = set()  # record of 'recursion-sensitive' pickled objects
+
 import os
 import sys
 diff = None
 _use_diff = False
 PY3 = (sys.hexversion >= 0x30000f0)
-if PY3: #XXX: get types from dill.objtypes ?
+if PY3: #XXX: get types from .objtypes ?
     import builtins as __builtin__
     from pickle import _Pickler as StockPickler, _Unpickler as StockUnpickler
     from _thread import LockType
@@ -78,27 +80,59 @@ if sys.hexversion < 0x03030000:
 try:
     import ctypes
     HAS_CTYPES = True
-    IS_PYPY = True
+    # if using `pypi`, pythonapi is not found
+    IS_PYPY = hasattr(ctypes, 'pythonapi')
 except ImportError:
     HAS_CTYPES = False
     IS_PYPY = False
 try:
+    import imp
+    imp.find_module('numpy')
+    NumpyUfuncType = True
+    NumpyArrayType = True
+except ImportError:
+    NumpyUfuncType = None
+    NumpyArrayType = None
+def __hook__():
+    global NumpyArrayType, NumpyUfuncType
     from numpy import ufunc as NumpyUfuncType
     from numpy import ndarray as NumpyArrayType
+    return True
+if NumpyArrayType: # then has numpy
     def ndarraysubclassinstance(obj):
+        if type(obj) in (TypeType, ClassType):
+            return False # all classes return False
         try: # check if is ndarray, and elif is subclass of ndarray
-            if getattr(obj, '__class__', type) is NumpyArrayType: return False
-            elif not isinstance(obj, NumpyArrayType): return False
+            cls = getattr(obj, '__class__', None)
+            if cls is None: return False
+            elif cls is TypeType: return False
+            elif 'numpy.ndarray' not in str(getattr(cls, 'mro', int.mro)()):
+                return False
         except ReferenceError: return False # handle 'R3' weakref in 3.x
+        except TypeError: return False
+        # anything below here is a numpy array (or subclass) instance
+        __hook__() # import numpy (so the following works!!!)
         # verify that __reduce__ has not been overridden
         NumpyInstance = NumpyArrayType((0,),'int8')
         if id(obj.__reduce_ex__) == id(NumpyInstance.__reduce_ex__) and \
            id(obj.__reduce__) == id(NumpyInstance.__reduce__): return True
         return False
-except ImportError:
-    NumpyUfuncType = None
-    NumpyArrayType = None
+    def numpyufunc(obj):
+        if type(obj) in (TypeType, ClassType):
+            return False # all classes return False
+        try: # check if is ufunc
+            cls = getattr(obj, '__class__', None)
+            if cls is None: return False
+            elif cls is TypeType: return False
+            if 'numpy.ufunc' not in str(getattr(cls, 'mro', int.mro)()):
+                return False
+        except ReferenceError: return False # handle 'R3' weakref in 3.x
+        except TypeError: return False
+        # anything below here is a numpy ufunc
+        return True
+else:
     def ndarraysubclassinstance(obj): return False
+    def numpyufunc(obj): return False
 
 # make sure to add these 'hand-built' types to _typemap
 if PY3:
@@ -166,6 +200,7 @@ def dump(obj, file, protocol=None, byref=None, fmode=None, recurse=None):#, stri
     if byref is None: byref = settings['byref']
     if fmode is None: fmode = settings['fmode']
     if recurse is None: recurse = settings['recurse']
+    stack.clear()  # clear record of 'recursion-sensitive' pickled objects
     pik = Pickler(file, protocol)
     pik._main = _main_module
     # apply kwd settings
@@ -173,7 +208,21 @@ def dump(obj, file, protocol=None, byref=None, fmode=None, recurse=None):#, stri
     pik._strictio = bool(strictio)
     pik._fmode = fmode
     pik._recurse = bool(recurse)
-    # hack to catch subclassed numpy array instances
+    # register if the object is a numpy ufunc
+    # thanks to Paul Kienzle for pointing out ufuncs didn't pickle
+    if NumpyUfuncType and numpyufunc(obj):
+        @register(type(obj))
+        def save_numpy_ufunc(pickler, obj):
+            log.info("Nu: %s" % obj)
+            StockPickler.save_global(pickler, obj)
+            log.info("# Nu")
+            return
+        # NOTE: the above 'save' performs like:
+        #   import copy_reg
+        #   def udump(f): return f.__name__
+        #   def uload(name): return getattr(numpy, name)
+        #   copy_reg.pickle(NumpyUfuncType, udump, uload)
+    # register if the object is a subclassed numpy array instance
     if NumpyArrayType and ndarraysubclassinstance(obj):
         @register(type(obj))
         def save_numpy_array(pickler, obj):
@@ -181,9 +230,11 @@ def dump(obj, file, protocol=None, byref=None, fmode=None, recurse=None):#, stri
             npdict = getattr(obj, '__dict__', None)
             f, args, state = obj.__reduce__()
             pik.save_reduce(_create_array, (f, args, state, npdict), obj=obj)
+            log.info("# Nu")
             return
     # end hack
     pik.dump(obj)
+    stack.clear()  # clear record of 'recursion-sensitive' pickled objects
     return
 
 def dumps(obj, protocol=None, byref=None, fmode=None, recurse=None):#, strictio=None):
@@ -350,6 +401,8 @@ class Unpickler(StockUnpickler):
     def find_class(self, module, name):
         if (module, name) == ('__builtin__', '__main__'):
             return self._main.__dict__ #XXX: above set w/save_module_dict
+        elif (module, name) == ('__builtin__', 'NoneType'):
+            return type(None) #XXX: special case: NoneType missing
         return StockUnpickler.find_class(self, module, name)
 
     def __init__(self, *args, **kwds):
@@ -602,16 +655,12 @@ class _attrgetter_helper(object):
             attrs[index] = ".".join([attrs[index], attr])
         return type(self)(attrs, index)
 
-if HAS_CTYPES and IS_PYPY:
-    try: # if using `pypi`, pythonapi is not found
-        ctypes.pythonapi.PyCell_New.restype = ctypes.py_object
-        ctypes.pythonapi.PyCell_New.argtypes = [ctypes.py_object]
-        # thanks to Paul Kienzle for cleaning the ctypes CellType logic
-        def _create_cell(contents):
-            return ctypes.pythonapi.PyCell_New(contents)
-
-    except AttributeError:
-        IS_PYPY = False
+if PY3:
+    def _create_cell(contents):
+        return (lambda y: contents).__closure__[0]
+else:
+    def _create_cell(contents):
+        return (lambda y: contents).func_closure[0]
 
 def _create_weakref(obj, *args):
     from weakref import ref
@@ -686,10 +735,36 @@ def _locate_function(obj, session=False):
     found = _import_module(obj.__module__ + '.' + obj.__name__, safe=True)
     return found is obj
 
+#@register(CodeType)
+#def save_code(pickler, obj):
+#    log.info("Co: %s" % obj)
+#    pickler.save_reduce(_unmarshal, (marshal.dumps(obj),), obj=obj)
+#    log.info("# Co")
+#    return
+
+# The following function is based on 'save_codeobject' from 'cloudpickle'
+# Copyright (c) 2012, Regents of the University of California.
+# Copyright (c) 2009 `PiCloud, Inc. <http://www.picloud.com>`_.
+# License: https://github.com/cloudpipe/cloudpickle/blob/master/LICENSE
 @register(CodeType)
 def save_code(pickler, obj):
     log.info("Co: %s" % obj)
-    pickler.save_reduce(_unmarshal, (marshal.dumps(obj),), obj=obj)
+    if PY3:
+        args = (
+            obj.co_argcount, obj.co_kwonlyargcount, obj.co_nlocals,
+            obj.co_stacksize, obj.co_flags, obj.co_code, obj.co_consts,
+            obj.co_names, obj.co_varnames, obj.co_filename, obj.co_name,
+            obj.co_firstlineno, obj.co_lnotab, obj.co_freevars, obj.co_cellvars
+        )
+    else:
+        args = (
+            obj.co_argcount, obj.co_nlocals, obj.co_stacksize, obj.co_flags,
+            obj.co_code, obj.co_consts, obj.co_names, obj.co_varnames,
+            obj.co_filename, obj.co_name, obj.co_firstlineno, obj.co_lnotab,
+            obj.co_freevars, obj.co_cellvars
+        )
+    pickler.save_reduce(CodeType, args, obj=obj)
+    log.info("# Co")
     return
 
 @register(FunctionType)
@@ -700,10 +775,17 @@ def save_function(pickler, obj):
             # recurse to get all globals referred to by obj
             from .detect import globalvars
             globs = globalvars(obj, recurse=True, builtin=True)
-            if obj in globs.values(): #ABORT: use _recurse=False
+            # remove objects that have already been serialized
+           #stacktypes = (ClassType, TypeType, FunctionType)
+           #for key,value in list(globs.items()):
+           #    if isinstance(value, stacktypes) and value in stack:
+           #        del globs[key]
+            # ABORT: if self-references, use _recurse=False
+            if obj in globs.values(): # or obj in stack:
                 globs = obj.__globals__ if PY3 else obj.func_globals
         else:
             globs = obj.__globals__ if PY3 else obj.func_globals
+       #stack.add(obj)
         if PY3:
             pickler.save_reduce(_create_function, (obj.__code__,
                                 globs, obj.__name__,
@@ -714,9 +796,11 @@ def save_function(pickler, obj):
                                 globs, obj.func_name,
                                 obj.func_defaults, obj.func_closure,
                                 obj.__dict__), obj=obj)
+        log.info("# F1")
     else:
         log.info("F2: %s" % obj)
         StockPickler.save_global(pickler, obj) #NOTE: also takes name=...
+        log.info("# F2")
     return
 
 @register(dict)
@@ -727,12 +811,14 @@ def save_module_dict(pickler, obj):
             pickler.write(bytes('c__builtin__\n__main__\n', 'UTF-8'))
         else:
             pickler.write('c__builtin__\n__main__\n')
+        log.info("# D1")
     elif not is_dill(pickler) and obj == _main_module.__dict__:
         log.info("D3: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
         if PY3:
             pickler.write(bytes('c__main__\n__dict__\n', 'UTF-8'))
         else:
             pickler.write('c__main__\n__dict__\n')   #XXX: works in general?
+        log.info("# D3")
     elif '__name__' in obj and obj != _main_module.__dict__ \
     and obj is getattr(_import_module(obj['__name__'],True), '__dict__', None):
         log.info("D4: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
@@ -740,30 +826,36 @@ def save_module_dict(pickler, obj):
             pickler.write(bytes('c%s\n__dict__\n' % obj['__name__'], 'UTF-8'))
         else:
             pickler.write('c%s\n__dict__\n' % obj['__name__'])
+        log.info("# D4")
     else:
         log.info("D2: <dict%s" % str(obj.__repr__).split('dict')[-1]) # obj
         if is_dill(pickler) and pickler._session:
             # we only care about session the first pass thru
-            pickler._session = False 
+            pickler._session = False
         StockPickler.save_dict(pickler, obj)
+        log.info("# D2")
     return
 
 @register(ClassType)
 def save_classobj(pickler, obj): #FIXME: enable pickler._byref
+   #stack.add(obj)
     if obj.__module__ == '__main__': #XXX: use _main_module.__name__ everywhere?
         log.info("C1: %s" % obj)
         pickler.save_reduce(ClassType, (obj.__name__, obj.__bases__,
                                         obj.__dict__), obj=obj)
                                        #XXX: or obj.__dict__.copy()), obj=obj) ?
+        log.info("# C1")
     else:
         log.info("C2: %s" % obj)
         StockPickler.save_global(pickler, obj)
+        log.info("# C2")
     return
 
 @register(LockType)
 def save_lock(pickler, obj):
     log.info("Lo: %s" % obj)
     pickler.save_reduce(_create_lock, (obj.locked(),), obj=obj)
+    log.info("# Lo")
     return
 
 @register(ItemGetterType)
@@ -772,6 +864,7 @@ def save_itemgetter(pickler, obj):
     helper = _itemgetter_helper()
     obj(helper)
     pickler.save_reduce(type(obj), tuple(helper.items), obj=obj)
+    log.info("# Ig")
     return
 
 @register(AttrGetterType)
@@ -781,13 +874,14 @@ def save_attrgetter(pickler, obj):
     helper = _attrgetter_helper(attrs)
     obj(helper)
     pickler.save_reduce(type(obj), tuple(attrs), obj=obj)
+    log.info("# Ag")
     return
 
 def _save_file(pickler, obj, open_):
-    obj.flush()
     if obj.closed:
         position = None
     else:
+        obj.flush()
         if obj in (sys.__stdout__, sys.__stderr__, sys.__stdin__):
             position = -1
         else:
@@ -817,7 +911,9 @@ def _save_file(pickler, obj, open_):
 @register(TextWrapperType)
 def save_file(pickler, obj):
     log.info("Fi: %s" % obj)
-    return _save_file(pickler, obj, open)
+    f = _save_file(pickler, obj, open)
+    log.info("# Fi")
+    return f
 
 if PyTextWrapperType:
     @register(PyBufferedRandomType)
@@ -826,7 +922,9 @@ if PyTextWrapperType:
     @register(PyTextWrapperType)
     def save_file(pickler, obj):
         log.info("Fi: %s" % obj)
-        return _save_file(pickler, obj, _open)
+        f = _save_file(pickler, obj, _open)
+        log.info("# Fi")
+        return f
 
 # The following two functions are based on 'saveCStringIoInput'
 # and 'saveCStringIoOutput' from spickle
@@ -842,6 +940,7 @@ if InputType:
             value = obj.getvalue(); position = obj.tell()
         pickler.save_reduce(_create_stringi, (value, position, \
                                               obj.closed), obj=obj)
+        log.info("# Io")
         return
 
     @register(OutputType)
@@ -853,6 +952,7 @@ if InputType:
             value = obj.getvalue(); position = obj.tell()
         pickler.save_reduce(_create_stringo, (value, position, \
                                               obj.closed), obj=obj)
+        log.info("# Io")
         return
 
 @register(PartialType)
@@ -860,12 +960,14 @@ def save_functor(pickler, obj):
     log.info("Fu: %s" % obj)
     pickler.save_reduce(_create_ftype, (type(obj), obj.func, obj.args,
                                         obj.keywords), obj=obj)
+    log.info("# Fu")
     return
 
 @register(SuperType)
 def save_functor(pickler, obj):
     log.info("Su: %s" % obj)
     pickler.save_reduce(super, (obj.__thisclass__, obj.__self__), obj=obj)
+    log.info("# Su")
     return
 
 @register(BuiltinMethodType)
@@ -873,17 +975,23 @@ def save_builtin_method(pickler, obj):
     if obj.__self__ is not None:
         if obj.__self__ is __builtin__:
             module = 'builtins' if PY3 else '__builtin__'
-            log.info("B1: %s" % obj)
+            _t = "B1"
+            log.info("%s: %s" % (_t, obj))
         else:
             module = obj.__self__
-            log.info("B3: %s" % obj)
-        _recurse = pickler._recurse
-        pickler._recurse = False
+            _t = "B3"
+            log.info("%s: %s" % (_t, obj))
+        if is_dill(pickler):
+            _recurse = pickler._recurse
+            pickler._recurse = False
         pickler.save_reduce(_get_attr, (module, obj.__name__), obj=obj)
-        pickler._recurse = _recurse
+        if is_dill(pickler):
+            pickler._recurse = _recurse
+        log.info("# %s" % _t)
     else:
         log.info("B2: %s" % obj)
         StockPickler.save_global(pickler, obj)
+        log.info("# B2")
     return
 
 @register(MethodType) #FIXME: fails for 'hidden' or 'name-mangled' classes
@@ -894,6 +1002,7 @@ def save_instancemethod0(pickler, obj):# example: cStringIO.StringI
     else:
         pickler.save_reduce(MethodType, (obj.im_func, obj.im_self,
                                          obj.im_class), obj=obj)
+    log.info("# Me")
     return
 
 if sys.hexversion >= 0x20500f0:
@@ -905,12 +1014,14 @@ if sys.hexversion >= 0x20500f0:
         log.info("Wr: %s" % obj)
         pickler.save_reduce(_getattr, (obj.__objclass__, obj.__name__,
                                        obj.__repr__()), obj=obj)
+        log.info("# Wr")
         return
 
     @register(MethodWrapperType)
     def save_instancemethod(pickler, obj):
         log.info("Mw: %s" % obj)
         pickler.save_reduce(getattr, (obj.__self__, obj.__name__), obj=obj)
+        log.info("# Mw")
         return
 else:
     @register(MethodDescriptorType)
@@ -919,15 +1030,16 @@ else:
         log.info("Wr: %s" % obj)
         pickler.save_reduce(_getattr, (obj.__objclass__, obj.__name__,
                                        obj.__repr__()), obj=obj)
+        log.info("# Wr")
         return
 
-if HAS_CTYPES and IS_PYPY:
-    @register(CellType)
-    def save_cell(pickler, obj):
-        log.info("Ce: %s" % obj)
-        pickler.save_reduce(_create_cell, (obj.cell_contents,), obj=obj)
-        return
- 
+ at register(CellType)
+def save_cell(pickler, obj):
+    log.info("Ce: %s" % obj)
+    pickler.save_reduce(_create_cell, (obj.cell_contents,), obj=obj)
+    log.info("# Ce")
+    return
+
 # The following function is based on 'saveDictProxy' from spickle
 # Copyright (c) 2011 by science+computing ag
 # License: http://www.apache.org/licenses/LICENSE-2.0
@@ -940,6 +1052,7 @@ if IS_PYPY:
         if type(attr) == GetSetDescriptorType and attr.__name__ == "__dict__" \
         and getattr(attr.__objclass__, "__dict__", None) == obj:
             pickler.save_reduce(getattr, (attr.__objclass__,"__dict__"),obj=obj)
+            log.info("# Dp")
             return
         # all bad below... so throw ReferenceError or TypeError
         from weakref import ReferenceError
@@ -949,6 +1062,7 @@ if IS_PYPY:
 def save_slice(pickler, obj):
     log.info("Sl: %s" % obj)
     pickler.save_reduce(slice, (obj.start, obj.stop, obj.step), obj=obj)
+    log.info("# Sl")
     return
 
 @register(XRangeType)
@@ -957,21 +1071,9 @@ def save_slice(pickler, obj):
 def save_singleton(pickler, obj):
     log.info("Si: %s" % obj)
     pickler.save_reduce(_eval_repr, (obj.__repr__(),), obj=obj)
+    log.info("# Si")
     return
 
-# thanks to Paul Kienzle for pointing out ufuncs didn't pickle
-if NumpyArrayType:
-    @register(NumpyUfuncType)
-    def save_numpy_ufunc(pickler, obj):
-        log.info("Nu: %s" % obj)
-        StockPickler.save_global(pickler, obj)
-        return
-# NOTE: the above 'save' performs like:
-#   import copy_reg
-#   def udump(f): return f.__name__
-#   def uload(name): return getattr(numpy, name)
-#   copy_reg.pickle(NumpyUfuncType, udump, uload)
-
 def _proxy_helper(obj): # a dead proxy returns a reference to None
     """get memory address of proxy's reference object"""
     try: #FIXME: has to be a smarter way to identify if it's a proxy
@@ -1006,18 +1108,24 @@ def save_weakref(pickler, obj):
     log.info("R1: %s" % obj)
    #refobj = ctypes.pythonapi.PyWeakref_GetObject(obj) # dead returns "None"
     pickler.save_reduce(_create_weakref, (refobj,), obj=obj)
+    log.info("# R1")
     return
 
 @register(ProxyType)
 @register(CallableProxyType)
 def save_weakproxy(pickler, obj):
     refobj = _locate_object(_proxy_helper(obj))
-    try: log.info("R2: %s" % obj)
-    except ReferenceError: log.info("R3: %s" % sys.exc_info()[1])
+    try:
+        _t = "R2"
+        log.info("%s: %s" % (_t, obj))
+    except ReferenceError:
+        _t = "R3"
+        log.info("%s: %s" % (_t, sys.exc_info()[1]))
    #callable = bool(getattr(refobj, '__call__', None))
     if type(obj) is CallableProxyType: callable = True
     else: callable = False
     pickler.save_reduce(_create_weakproxy, (refobj, callable), obj=obj)
+    log.info("# %s" % _t)
     return
 
 @register(ModuleType)
@@ -1033,10 +1141,12 @@ def save_module(pickler, obj):
                 log.info("Diff: %s", changed.keys())
                 pickler.save_reduce(_import_module, (obj.__name__,), obj=obj,
                                     state=changed)
+                log.info("# M1")
                 return
 
         log.info("M2: %s" % obj)
         pickler.save_reduce(_import_module, (obj.__name__,), obj=obj)
+        log.info("# M2")
     else:
         # if a module file name starts with prefx, it should be a builtin
         # module, so should be pickled as a reference
@@ -1056,50 +1166,70 @@ def save_module(pickler, obj):
                 + ["__builtins__", "__loader__"]]
             pickler.save_reduce(_import_module, (obj.__name__,), obj=obj,
                                 state=_main_dict)
+            log.info("# M1")
         else:
             log.info("M2: %s" % obj)
             pickler.save_reduce(_import_module, (obj.__name__,), obj=obj)
+            log.info("# M2")
         return
     return
 
 @register(TypeType)
 def save_type(pickler, obj):
+   #stack.add(obj) #XXX: probably don't need object from all cases below
     if obj in _typemap:
         log.info("T1: %s" % obj)
         pickler.save_reduce(_load_type, (_typemap[obj],), obj=obj)
+        log.info("# T1")
     elif obj.__module__ == '__main__':
         try: # use StockPickler for special cases [namedtuple,]
             [getattr(obj, attr) for attr in ('_fields','_asdict',
                                              '_make','_replace')]
             log.info("T6: %s" % obj)
             StockPickler.save_global(pickler, obj)
+            log.info("# T6")
             return
         except AttributeError: pass
         if issubclass(type(obj), type):
         #   try: # used when pickling the class as code (or the interpreter)
             if is_dill(pickler) and not pickler._byref:
                 # thanks to Tom Stepleton pointing out pickler._session unneeded
-                log.info("T2: %s" % obj)
+                _t = 'T2'
+                log.info("%s: %s" % (_t, obj))
                 _dict = _dict_from_dictproxy(obj.__dict__)
         #   except: # punt to StockPickler (pickle by class reference)
             else:
                 log.info("T5: %s" % obj)
                 StockPickler.save_global(pickler, obj)
+                log.info("# T5")
                 return
         else:
-            log.info("T3: %s" % obj)
+            _t = 'T3'
+            log.info("%s: %s" % (_t, obj))
             _dict = obj.__dict__
        #print (_dict)
        #print ("%s\n%s" % (type(obj), obj.__name__))
        #print ("%s\n%s" % (obj.__bases__, obj.__dict__))
+        for name in _dict.get("__slots__", []):
+            del _dict[name]
         pickler.save_reduce(_create_type, (type(obj), obj.__name__,
                                            obj.__bases__, _dict), obj=obj)
+        log.info("# %s" % _t)
+    # special cases: NoneType
+    elif obj is type(None):
+        log.info("T7: %s" % obj)
+        if PY3:
+            pickler.write(bytes('c__builtin__\nNoneType\n', 'UTF-8'))
+        else:
+            pickler.write('c__builtin__\nNoneType\n')
+        log.info("# T7")
     else:
         log.info("T4: %s" % obj)
        #print (obj.__dict__)
        #print ("%s\n%s" % (type(obj), obj.__name__))
        #print ("%s\n%s" % (obj.__bases__, obj.__dict__))
         StockPickler.save_global(pickler, obj)
+        log.info("# T4")
     return
 
 @register(property)
@@ -1107,6 +1237,21 @@ def save_property(pickler, obj):
     log.info("Pr: %s" % obj)
     pickler.save_reduce(property, (obj.fget, obj.fset, obj.fdel, obj.__doc__),
                         obj=obj)
+    log.info("# Pr")
+
+ at register(staticmethod)
+ at register(classmethod)
+def save_classmethod(pickler, obj):
+    log.info("Cm: %s" % obj)
+    im_func = '__func__' if PY3 else 'im_func'
+    try:
+        orig_func = getattr(obj, im_func)
+    except AttributeError:  # Python 2.6
+        orig_func = obj.__get__(None, object)
+        if isinstance(obj, classmethod):
+            orig_func = getattr(orig_func, im_func) # Unbind
+    pickler.save_reduce(type(obj), (orig_func,), obj=obj)
+    log.info("# Cm")
 
 # quick sanity checking
 def pickles(obj,exact=False,safe=False,**kwds):
@@ -1130,6 +1275,33 @@ def pickles(obj,exact=False,safe=False,**kwds):
     except exceptions:
         return False
 
+def check(obj, *args, **kwds):
+    """check pickling of an object across another process"""
+   # == undocumented ==
+   # python -- the string path or executable name of the selected python
+   # verbose -- if True, be verbose about printing warning messages
+   # all other args and kwds are passed to dill.dumps
+    verbose = kwds.pop('verbose', False)
+    python = kwds.pop('python', None)
+    if python is None:
+        import sys
+        python = sys.executable
+    # type check
+    isinstance(python, str)
+    import subprocess
+    fail = True
+    try:
+        _obj = dumps(obj, *args, **kwds)
+        fail = False
+    finally:
+        if fail and verbose:
+            print("DUMP FAILED")
+    msg = "%s -c import dill; print(dill.loads(%s))" % (python, repr(_obj))
+    msg = "SUCCESS" if not subprocess.call(msg.split(None,2)) else "LOAD FAILED"
+    if verbose:
+        print(msg)
+    return
+
 # use to protect against missing attributes
 def is_dill(pickler):
     "check the dill-ness of your pickler"
diff --git a/dill/info.py b/dill/info.py
index 38e7c14..e3304f8 100644
--- a/dill/info.py
+++ b/dill/info.py
@@ -1,6 +1,6 @@
 # THIS FILE GENERATED FROM SETUP.PY
-this_version = '0.2.4'
-stable_version = '0.2.4'
+this_version = '0.2.5'
+stable_version = '0.2.5'
 readme = '''-----------------------------
 dill: serialize all of python
 -----------------------------
@@ -70,7 +70,7 @@ Dill also provides the capability to::
 Current Release
 ===============
 
-This version is dill-0.2.4.
+This version is dill-0.2.5.
 
 The latest stable version of dill is available from::
 
@@ -108,8 +108,8 @@ Dill is packaged to install from source, so you must
 download the tarball, unzip, and run the installer::
 
     [download]
-    $ tar -xvzf dill-0.2.4.tgz
-    $ cd dill-0.2.4
+    $ tar -xvzf dill-0.2.5.tgz
+    $ cd dill-0.2.5
     $ python setup py build
     $ python setup py install
 
@@ -207,6 +207,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-Copyright (c) 2015 California Institute of Technology. All rights reserved.
+Copyright (c) 2016 California Institute of Technology. All rights reserved.
 
 '''
diff --git a/dill/objtypes.py b/dill/objtypes.py
index b87314a..2a57736 100644
--- a/dill/objtypes.py
+++ b/dill/objtypes.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 """
diff --git a/dill/pointers.py b/dill/pointers.py
index c7b2472..21f43b4 100644
--- a/dill/pointers.py
+++ b/dill/pointers.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 
diff --git a/dill/settings.py b/dill/settings.py
index 8c315f0..940a67a 100644
--- a/dill/settings.py
+++ b/dill/settings.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 """
diff --git a/dill/source.py b/dill/source.py
index efd9eb2..621299a 100644
--- a/dill/source.py
+++ b/dill/source.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 #
diff --git a/dill/temp.py b/dill/temp.py
index c439ce7..8f06bf9 100644
--- a/dill/temp.py
+++ b/dill/temp.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
-# Copyright (c) 2008-2015 California Institute of Technology.
+# Copyright (c) 2008-2016 California Institute of Technology.
 # License: 3-clause BSD.  The full license text is available at:
 #  - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE
 """
diff --git a/scripts/get_objgraph.py b/scripts/get_objgraph.py
... 363 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/dill.git



More information about the Python-modules-commits mailing list