Commit 1b019545 authored by Tres Seaver's avatar Tres Seaver

Py3k compat.

- Work around rename of 'copy_reg' -> 'copyreg'.

- Fix deprecated class advice.


- Drop unneeded unicode literals.
parent 78de25e0
......@@ -29,7 +29,7 @@ except ImportError: #pragma NO COVER
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.
......
##############################################################################
#
# 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
......@@ -548,11 +548,11 @@ class IPickleCache(Interface):
"""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'")
......@@ -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 @@ class RingNode(object):
self.next = next
self.prev = prev
@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
......
......@@ -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 @@ SPECIAL_NAMES = ('__class__',
)
@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 @@ class Persistent(object):
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 @@ class Persistent(object):
""" 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.
......
......@@ -781,37 +781,37 @@ class _Persistent_Base(object):
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 @@ class _Persistent_Base(object):
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'})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment