[Checkins] SVN: persistent/trunk/ Py3k compat.

Tres Seaver cvs-admin at zope.org
Fri Jun 29 04:02:08 UTC 2012


Log message for revision 127171:
  Py3k compat.
  
  - Work around rename of 'copy_reg' -> 'copyreg'.
  
  - Fix deprecated class advice.
  
  
  - Drop unneeded unicode literals.

Changed:
  _U  persistent/trunk/
  U   persistent/trunk/persistent/__init__.py
  A   persistent/trunk/persistent/_compat.py
  U   persistent/trunk/persistent/interfaces.py
  U   persistent/trunk/persistent/picklecache.py
  U   persistent/trunk/persistent/pyPersistence.py
  U   persistent/trunk/persistent/tests/test_persistence.py

-=-
Modified: persistent/trunk/persistent/__init__.py
===================================================================
--- persistent/trunk/persistent/__init__.py	2012-06-29 04:02:00 UTC (rev 127170)
+++ persistent/trunk/persistent/__init__.py	2012-06-29 04:02:04 UTC (rev 127171)
@@ -29,7 +29,7 @@
     from persistent.pyPersistence import CHANGED
     from persistent.pyPersistence import STICKY
 else:
-    import copy_reg
+    from persistent._compat import copy_reg
     copy_reg.constructor(simple_new)
     # Make an interface declaration for Persistent, if zope.interface
     # is available.  Note that the pyPersistent version already does this.

Added: persistent/trunk/persistent/_compat.py
===================================================================
--- persistent/trunk/persistent/_compat.py	                        (rev 0)
+++ persistent/trunk/persistent/_compat.py	2012-06-29 04:02:04 UTC (rev 127171)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2012 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import sys
+
+if sys.version_info[0] > 2: #pragma NO COVER
+    import copyreg as copy_reg
+
+else: #pragma NO COVER
+    import copy_reg
+

Modified: persistent/trunk/persistent/interfaces.py
===================================================================
--- persistent/trunk/persistent/interfaces.py	2012-06-29 04:02:00 UTC (rev 127170)
+++ persistent/trunk/persistent/interfaces.py	2012-06-29 04:02:04 UTC (rev 127171)
@@ -548,11 +548,11 @@
         """Update the cache's size estimation for 'oid', if known to the cache.
         """
 
-    cache_size = Attribute(u'Target size of the cache')
-    cache_drain_resistance = Attribute(u'Factor for draining cache below '
-                                        u'target size')
-    cache_non_ghost_count = Attribute(u'Number of non-ghosts in the cache '
-                                        u'(XXX how is it different from '
-                                        u'ringlen?')
-    cache_data = Attribute(u"Property:  copy of our 'data' dict")
-    cache_klass_count = Attribute(u"Property: len of 'persistent_classes'")
+    cache_size = Attribute('Target size of the cache')
+    cache_drain_resistance = Attribute('Factor for draining cache below '
+                                        'target size')
+    cache_non_ghost_count = Attribute('Number of non-ghosts in the cache '
+                                        '(XXX how is it different from '
+                                        'ringlen?')
+    cache_data = Attribute("Property:  copy of our 'data' dict")
+    cache_klass_count = Attribute("Property: len of 'persistent_classes'")

Modified: persistent/trunk/persistent/picklecache.py
===================================================================
--- persistent/trunk/persistent/picklecache.py	2012-06-29 04:02:00 UTC (rev 127170)
+++ persistent/trunk/persistent/picklecache.py	2012-06-29 04:02:04 UTC (rev 127171)
@@ -14,7 +14,7 @@
 import gc
 import weakref
 
-from zope.interface import implements
+from zope.interface import implementer
 
 from persistent.interfaces import CHANGED
 from persistent.interfaces import GHOST
@@ -29,8 +29,8 @@
         self.next = next
         self.prev = prev
 
+ at implementer(IPickleCache)
 class PickleCache(object):
-    implements(IPickleCache)
 
     def __init__(self, jar, target_size=0, cache_size_bytes=0):
         # TODO:  forward-port Dieter's bytes stuff

Modified: persistent/trunk/persistent/pyPersistence.py
===================================================================
--- persistent/trunk/persistent/pyPersistence.py	2012-06-29 04:02:00 UTC (rev 127170)
+++ persistent/trunk/persistent/pyPersistence.py	2012-06-29 04:02:04 UTC (rev 127171)
@@ -11,20 +11,18 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-from copy_reg import __newobj__
-from copy_reg import _slotnames
 import sys
 
-from zope.interface import implements
+from zope.interface import implementer
 
 from persistent.interfaces import IPersistent
-from persistent.interfaces import IPersistentDataManager
 from persistent.interfaces import GHOST
 from persistent.interfaces import UPTODATE
 from persistent.interfaces import CHANGED
 from persistent.interfaces import STICKY
 from persistent.timestamp import TimeStamp
 from persistent.timestamp import _ZERO
+from persistent._compat import copy_reg
 
 OID_TYPE = SERIAL_TYPE = bytes
 
@@ -47,11 +45,11 @@
                 )
 
 
+ at implementer(IPersistent)
 class Persistent(object):
     """ Pure Python implmentation of Persistent base class
     """
     __slots__ = ('__jar', '__oid', '__serial', '__flags', '__size')
-    implements(IPersistent)
 
     def __new__(cls, *args, **kw):
         inst = super(Persistent, cls).__new__(cls)
@@ -254,7 +252,7 @@
         object.__delattr__(self, name)
 
     def _slotnames(self):
-        slotnames = _slotnames(type(self))
+        slotnames = copy_reg._slotnames(type(self))
         return [x for x in slotnames
                    if not x.startswith('_p_') and
                       not x.startswith('_v_') and
@@ -303,7 +301,8 @@
         """ See IPersistent.
         """
         gna = getattr(self, '__getnewargs__', lambda: ())
-        return (__newobj__, (type(self),) + gna(), self.__getstate__())
+        return (copy_reg.__newobj__,
+                (type(self),) + gna(), self.__getstate__())
 
     def _p_activate(self):
         """ See IPersistent.

Modified: persistent/trunk/persistent/tests/test_persistence.py
===================================================================
--- persistent/trunk/persistent/tests/test_persistence.py	2012-06-29 04:02:00 UTC (rev 127170)
+++ persistent/trunk/persistent/tests/test_persistence.py	2012-06-29 04:02:04 UTC (rev 127171)
@@ -781,37 +781,37 @@
         self.assertEqual(inst.qux, 'spam')
 
     def test___reduce__(self):
-        from copy_reg import __newobj__
+        from persistent._compat import copy_reg
         inst = self._makeOne()
         first, second, third = inst.__reduce__()
-        self.failUnless(first is __newobj__)
+        self.failUnless(first is copy_reg.__newobj__)
         self.assertEqual(second, (self._getTargetClass(),))
         self.assertEqual(third, None)
 
     def test___reduce__w_subclass_having_getnewargs(self):
-        from copy_reg import __newobj__
+        from persistent._compat import copy_reg
         class Derived(self._getTargetClass()):
             def __getnewargs__(self):
                 return ('a', 'b')
         inst = Derived()
         first, second, third = inst.__reduce__()
-        self.failUnless(first is __newobj__)
+        self.failUnless(first is copy_reg.__newobj__)
         self.assertEqual(second, (Derived, 'a', 'b'))
         self.assertEqual(third, {})
 
     def test___reduce__w_subclass_having_getstate(self):
-        from copy_reg import __newobj__
+        from persistent._compat import copy_reg
         class Derived(self._getTargetClass()):
             def __getstate__(self):
                 return {}
         inst = Derived()
         first, second, third = inst.__reduce__()
-        self.failUnless(first is __newobj__)
+        self.failUnless(first is copy_reg.__newobj__)
         self.assertEqual(second, (Derived,))
         self.assertEqual(third, {})
 
     def test___reduce__w_subclass_having_getnewargs_and_getstate(self):
-        from copy_reg import __newobj__
+        from persistent._compat import copy_reg
         class Derived(self._getTargetClass()):
             def __getnewargs__(self):
                 return ('a', 'b')
@@ -819,7 +819,7 @@
                 return {'foo': 'bar'}
         inst = Derived()
         first, second, third = inst.__reduce__()
-        self.failUnless(first is __newobj__)
+        self.failUnless(first is copy_reg.__newobj__)
         self.assertEqual(second, (Derived, 'a', 'b'))
         self.assertEqual(third, {'foo': 'bar'})
 



More information about the checkins mailing list