Commit 64b6afd8 authored by Tres Seaver's avatar Tres Seaver

Python3 compat:

- (Temporary) Disable C extension building under Py3k.

- Work around move of UserDict / UserList.

- Make test of 'cmp' conditional on PYTHON2.

- Make '__setslice__' / '__delslice__' conditional on PYTHON2.
parent ad9fc8db
......@@ -16,13 +16,22 @@ import sys
if sys.version_info[0] > 2: #pragma NO COVER
import copyreg as copy_reg
from collections import UserDict as IterableUserDict
from collections import UserList
def _u(s):
return s
PYTHON3 = True
PYTHON2 = False
else: #pragma NO COVER
import copy_reg
from UserDict import IterableUserDict
from UserList import UserList
def _u(s):
return unicode(s, 'unicode_escape')
PYTHON3 = False
PYTHON2 = True
......@@ -17,13 +17,15 @@
$Id$"""
import persistent
from UserList import UserList
from persistent._compat import UserList
from persistent._compat import PYTHON2
class PersistentList(UserList, persistent.Persistent):
__super_setitem = UserList.__setitem__
__super_delitem = UserList.__delitem__
__super_setslice = UserList.__setslice__
__super_delslice = UserList.__delslice__
if PYTHON2:
__super_setslice = UserList.__setslice__
__super_delslice = UserList.__delslice__
__super_iadd = UserList.__iadd__
__super_imul = UserList.__imul__
__super_append = UserList.append
......
......@@ -17,7 +17,7 @@
$Id$"""
import persistent
import UserDict
from persistent._compat import IterableUserDict
class default(object):
......@@ -30,7 +30,7 @@ class default(object):
return self.func(inst)
class PersistentMapping(UserDict.IterableUserDict, persistent.Persistent):
class PersistentMapping(IterableUserDict, persistent.Persistent):
"""A persistent wrapper for mapping objects.
This class allows wrapping of mapping objects so that object
......@@ -47,13 +47,13 @@ class PersistentMapping(UserDict.IterableUserDict, persistent.Persistent):
# state as changed when a method actually changes the state. At
# the mapping API evolves, we may need to add more methods here.
__super_delitem = UserDict.IterableUserDict.__delitem__
__super_setitem = UserDict.IterableUserDict.__setitem__
__super_clear = UserDict.IterableUserDict.clear
__super_update = UserDict.IterableUserDict.update
__super_setdefault = UserDict.IterableUserDict.setdefault
__super_pop = UserDict.IterableUserDict.pop
__super_popitem = UserDict.IterableUserDict.popitem
__super_delitem = IterableUserDict.__delitem__
__super_setitem = IterableUserDict.__setitem__
__super_clear = IterableUserDict.clear
__super_update = IterableUserDict.update
__super_setdefault = IterableUserDict.setdefault
__super_pop = IterableUserDict.pop
__super_popitem = IterableUserDict.popitem
def __delitem__(self, key):
self.__super_delitem(key)
......@@ -75,7 +75,7 @@ class PersistentMapping(UserDict.IterableUserDict, persistent.Persistent):
# We could inline all of UserDict's implementation into the
# method here, but I'd rather not depend at all on the
# implementation in UserDict (simple as it is).
if not self.has_key(key):
if not key in self.data:
self._p_changed = 1
return self.__super_setdefault(key, failobj)
......
......@@ -44,6 +44,7 @@ class TestPList(unittest.TestCase):
self.failIf('_v_baz' in state)
def testTheWorld(self):
from persistent._compat import PYTHON2
# Test constructors
pl = self._getTargetClass()
u = pl()
......@@ -68,17 +69,18 @@ class TestPList(unittest.TestCase):
# Test __cmp__ and __len__
def mycmp(a, b):
r = cmp(a, b)
if r < 0: return -1
if r > 0: return 1
return r
if PYTHON2:
def mycmp(a, b):
r = cmp(a, b)
if r < 0: return -1
if r > 0: return 1
return r
all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2]
for a in all:
for b in all:
eq(mycmp(a, b), mycmp(len(a), len(b)),
"mycmp(a, b) == mycmp(len(a), len(b))")
all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2]
for a in all:
for b in all:
eq(mycmp(a, b), mycmp(len(a), len(b)),
"mycmp(a, b) == mycmp(len(a), len(b))")
# Test __getitem__
......@@ -218,8 +220,9 @@ class TestPList(unittest.TestCase):
eq(u, u2, "u == u2")
# Test keyword arguments to sort
u.sort(cmp=lambda x,y: cmp(y, x))
eq(u, [1, 0], "u == [1, 0]")
if PYTHON2:
u.sort(cmp=lambda x,y: cmp(y, x))
eq(u, [1, 0], "u == [1, 0]")
u.sort(key=lambda x:-x)
eq(u, [1, 0], "u == [1, 0]")
......
......@@ -67,6 +67,7 @@ class PersistentMappingTests(unittest.TestCase):
self.failIf('_v_baz' in state)
def testTheWorld(self):
from persistent._compat import PYTHON2
# Test constructors
l0 = {}
l1 = {0:0}
......@@ -81,7 +82,7 @@ class PersistentMappingTests(unittest.TestCase):
uu1 = self._makeOne(u1)
uu2 = self._makeOne(u2)
class OtherMapping:
class OtherMapping(dict):
def __init__(self, initmapping):
self.__data = initmapping
def items(self):
......@@ -97,17 +98,18 @@ class PersistentMappingTests(unittest.TestCase):
# Test __cmp__ and __len__
def mycmp(a, b):
r = cmp(a, b)
if r < 0: return -1
if r > 0: return 1
return r
all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2]
for a in all:
for b in all:
eq(mycmp(a, b), mycmp(len(a), len(b)),
"mycmp(a, b) == mycmp(len(a), len(b))")
if PYTHON2:
def mycmp(a, b):
r = cmp(a, b)
if r < 0: return -1
if r > 0: return 1
return r
all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2]
for a in all:
for b in all:
eq(mycmp(a, b), mycmp(len(a), len(b)),
"mycmp(a, b) == mycmp(len(a), len(b))")
# Test __getitem__
......
......@@ -18,8 +18,6 @@ import os
import platform
import sys
from ez_setup import use_setuptools
use_setuptools()
from setuptools import Extension
from setuptools import find_packages
......@@ -40,7 +38,7 @@ is_jython = 'java' in sys.platform
# Jython cannot build the C optimizations, while on PyPy they are
# anti-optimizations (the C extension compatibility layer is known-slow,
# and defeats JIT opportunities).
if is_pypy or is_jython:
if is_pypy or is_jython or sys.version_info[0] > 2:
ext_modules = headers = []
else:
ext_modules = [Extension(name = 'persistent.cPersistence',
......
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