Commit 7372b310 authored by Jason Madden's avatar Jason Madden

Cleanups in _compat.

parent 0012ca0f
...@@ -18,7 +18,8 @@ IS_JYTHON = sys.platform.startswith('java') ...@@ -18,7 +18,8 @@ IS_JYTHON = sys.platform.startswith('java')
try: try:
# Python 2.x # Python 2.x
import cPickle import cPickle
if (hasattr(cPickle.Unpickler, 'load') and not hasattr(cPickle.Unpickler, 'noload')) or sys.version_info >= (2,7): if ((hasattr(cPickle.Unpickler, 'load') and not hasattr(cPickle.Unpickler, 'noload')) or
sys.version_info >= (2,7)):
# PyPy doesn't have noload, and noload is broken in Python 2.7. # PyPy doesn't have noload, and noload is broken in Python 2.7.
# Get the fastest version we can (PyPy has no fastpickle) # Get the fastest version we can (PyPy has no fastpickle)
try: try:
...@@ -83,13 +84,12 @@ def PersistentPickler(persistent_id, *args, **kwargs): ...@@ -83,13 +84,12 @@ def PersistentPickler(persistent_id, *args, **kwargs):
p = Pickler(*args, **kwargs) p = Pickler(*args, **kwargs)
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
p.inst_persistent_id = persistent_id p.inst_persistent_id = persistent_id
# PyPy uses a python implementation of cPickle in both Python 2
# and Python 3. We can't really detect inst_persistent_id as its # PyPy uses a python implementation of cPickle/zodbpickle in both Python 2
# a magic attribute that's not readable, but it doesn't hurt to # and Python 3. We can't really detect inst_persistent_id as its
# simply always assign to persistent_id also # a magic attribute that's not readable, but it doesn't hurt to
p.persistent_id = persistent_id # simply always assign to persistent_id also
else: p.persistent_id = persistent_id
p.persistent_id = persistent_id
return p return p
def PersistentUnpickler(find_global, load_persistent, *args, **kwargs): def PersistentUnpickler(find_global, load_persistent, *args, **kwargs):
...@@ -114,16 +114,8 @@ def PersistentUnpickler(find_global, load_persistent, *args, **kwargs): ...@@ -114,16 +114,8 @@ def PersistentUnpickler(find_global, load_persistent, *args, **kwargs):
try: try:
# Python 2.x # XXX: why not just import BytesIO from io?
if IS_JYTHON: from cStringIO import StringIO as BytesIO
# Jython 2.7rc2 cStringIO.StringIO class has a bug
# resulting in StringIndexOutOfBoundExceptions
# when repeatedly writing and then seeking back to 0
# http://bugs.jython.org/issue2324
from io import BytesIO
else:
# XXX: why not just import BytesIO from io?
from cStringIO import StringIO as BytesIO
except ImportError: except ImportError:
# Python 3.x # Python 3.x
from io import BytesIO from io import BytesIO
......
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