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:
from persistent.cPersistence import Persistent
from persistent.cPersistence import GHOST
from persistent.cPersistence import UPTODATE
from persistent.cPersistence import CHANGED
from persistent.cPersistence import STICKY
from persistent.cPersistence import simple_new
except ImportError: # 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
else:
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 Python version already does this.
try:
from zope.interface import classImplements
except ImportError: # pragma: no cover
pass
else:
from persistent.interfaces import IPersistent
classImplements(Persistent, IPersistent)
try: __all__ = [
from persistent.cPickleCache import PickleCache 'IPersistent',
except ImportError: # pragma: no cover 'Persistent',
from persistent.picklecache import PickleCache 'GHOST',
'UPTODATE',
'CHANGED',
'STICKY',
'PickleCache',
'TimeStamp',
]
from persistent._compat import PURE_PYTHON
from persistent.interfaces import IPersistent
try: import persistent.timestamp as TimeStamp
import persistent.TimeStamp
except ImportError: # pragma: no cover from persistent import persistence as pyPersistence
import persistent.timestamp as TimeStamp from persistent import picklecache as pyPickleCache
import sys
sys.modules['persistent.TimeStamp' try:
] = sys.modules['persistent.timestamp'] # Be careful not to shadow the modules
else: # pragma: no cover from persistent import cPersistence as _cPersistence
from persistent.persistence import Persistent from persistent import cPickleCache as _cPickleCache
from persistent.persistence import GHOST except ImportError: # pragma: no cover
from persistent.persistence import UPTODATE _cPersistence = None
from persistent.persistence import CHANGED _cPickleCache = None
from persistent.persistence import STICKY else:
from persistent.picklecache import PickleCache # Make an interface declaration for Persistent
import persistent.timestamp as TimeStamp # Note that the Python version already does this.
import sys from zope.interface import classImplements
sys.modules['persistent.TimeStamp'] = sys.modules['persistent.timestamp'] classImplements(_cPersistence.Persistent, IPersistent)
_persistence = pyPersistence if PURE_PYTHON or _cPersistence is None else _cPersistence
_picklecache = pyPickleCache if PURE_PYTHON or _cPickleCache is None else _cPickleCache
Persistent = _persistence.Persistent
GHOST = _persistence.GHOST
UPTODATE = _persistence.UPTODATE
CHANGED = _persistence.CHANGED
STICKY = _persistence.STICKY
PickleCache = _picklecache.PickleCache
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