Commit 97ef73c6 authored by Jason Madden's avatar Jason Madden

Simplify __init__.py to not repeat itself three times.

There are many fewer 'no cover' lines now.

Remove the call to copy_reg.constructor---it doesn't do anything anymore except check that the object is callable, there is no registry.

Also make timestamp support PURE_PYTHON.
parent eee0f323
...@@ -15,55 +15,49 @@ ...@@ -15,55 +15,49 @@
Fall back to pure Python implementations. Fall back to pure Python implementations.
""" """
import os
PURE_PYTHON = os.environ.get('PURE_PYTHON') import sys
if not PURE_PYTHON:
try: __all__ = [
from persistent.cPersistence import Persistent 'IPersistent',
from persistent.cPersistence import GHOST 'Persistent',
from persistent.cPersistence import UPTODATE 'GHOST',
from persistent.cPersistence import CHANGED 'UPTODATE',
from persistent.cPersistence import STICKY 'CHANGED',
from persistent.cPersistence import simple_new 'STICKY',
except ImportError: # pragma: no cover 'PickleCache',
from persistent.persistence import Persistent 'TimeStamp',
from persistent.persistence import GHOST ]
from persistent.persistence import UPTODATE from persistent._compat import PURE_PYTHON
from persistent.persistence import CHANGED from persistent.interfaces import IPersistent
from persistent.persistence import STICKY
else: import persistent.timestamp as TimeStamp
from persistent._compat import copy_reg
copy_reg.constructor(simple_new) from persistent import persistence as pyPersistence
# Make an interface declaration for Persistent, if zope.interface from persistent import picklecache as pyPickleCache
# is available. Note that the Python version already does this.
try: try:
# Be careful not to shadow the modules
from persistent import cPersistence as _cPersistence
from persistent import cPickleCache as _cPickleCache
except ImportError: # pragma: no cover
_cPersistence = None
_cPickleCache = None
else:
# Make an interface declaration for Persistent
# Note that the Python version already does this.
from zope.interface import classImplements from zope.interface import classImplements
except ImportError: # pragma: no cover classImplements(_cPersistence.Persistent, IPersistent)
pass
else:
from persistent.interfaces import IPersistent _persistence = pyPersistence if PURE_PYTHON or _cPersistence is None else _cPersistence
classImplements(Persistent, IPersistent) _picklecache = pyPickleCache if PURE_PYTHON or _cPickleCache is None else _cPickleCache
try: Persistent = _persistence.Persistent
from persistent.cPickleCache import PickleCache GHOST = _persistence.GHOST
except ImportError: # pragma: no cover UPTODATE = _persistence.UPTODATE
from persistent.picklecache import PickleCache CHANGED = _persistence.CHANGED
STICKY = _persistence.STICKY
PickleCache = _picklecache.PickleCache
try: sys.modules['persistent.TimeStamp'] = sys.modules['persistent.timestamp']
import persistent.TimeStamp
except ImportError: # pragma: no cover
import persistent.timestamp as TimeStamp
import sys
sys.modules['persistent.TimeStamp'
] = sys.modules['persistent.timestamp']
else: # pragma: no cover
from persistent.persistence import Persistent
from persistent.persistence import GHOST
from persistent.persistence import UPTODATE
from persistent.persistence import CHANGED
from persistent.persistence import STICKY
from persistent.picklecache import PickleCache
import persistent.timestamp as TimeStamp
import sys
sys.modules['persistent.TimeStamp'] = sys.modules['persistent.timestamp']
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
############################################################################## ##############################################################################
import sys import sys
import os
PURE_PYTHON = os.environ.get('PURE_PYTHON')
if sys.version_info[0] > 2: # pragma: no cover if sys.version_info[0] > 2: # pragma: no cover
import copyreg as copy_reg import copyreg as copy_reg
......
...@@ -18,6 +18,8 @@ import math ...@@ -18,6 +18,8 @@ import math
import struct import struct
import sys import sys
from persistent._compat import PURE_PYTHON
_RAWTYPE = bytes _RAWTYPE = bytes
_MAXINT = sys.maxsize _MAXINT = sys.maxsize
...@@ -205,6 +207,8 @@ class pyTimeStamp(object): ...@@ -205,6 +207,8 @@ class pyTimeStamp(object):
try: try:
from persistent._timestamp import TimeStamp from persistent._timestamp import TimeStamp as CTimeStamp
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
TimeStamp = pyTimeStamp CTimeStamp = None
TimeStamp = pyTimeStamp if PURE_PYTHON or CTimeStamp is None else CTimeStamp
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