Commit 66d6eabb authored by Jason Madden's avatar Jason Madden

Remove unneeded _compat._b/_u/_native.

Also some minor DRY in test_picklecache.py

Fixes #81.
parent de8680be
......@@ -7,7 +7,8 @@
- Reach and maintain 100% test coverage.
- Simplify ``__init__.py``, including removal of an attempted legacy
import of ``persistent.TimeStamp``.
import of ``persistent.TimeStamp``. See `PR 80
<https://github.com/zopefoundation/persistent/pull/80>`_.
- Add support for Python 3.7 and drop support for Python 3.3.
......@@ -27,6 +28,8 @@
- Fix deleting special (``_p``) attributes of a pure-Python persistent
object that overrides ``__delattr__`` and correctly calls ``_p_delattr``.
- Remove some internal compatibility shims that are no longer
necessary. See `PR 82 <https://github.com/zopefoundation/persistent/pull/82>`_.
4.3.0 (2018-07-30)
------------------
......
......@@ -17,25 +17,12 @@ import os
PURE_PYTHON = os.environ.get('PURE_PYTHON')
if sys.version_info[0] > 2: # pragma: no cover
if sys.version_info[0] > 2:
import copyreg as copy_reg
from collections import UserDict as IterableUserDict
from collections import UserList
from sys import intern
def _u(s):
return s
def _b(s):
if isinstance(s, str):
return s.encode('unicode_escape')
return s
def _native(s):
if isinstance(s, bytes):
return s.decode('unicode_escape')
return s
PYTHON3 = True
PYTHON2 = False
......@@ -44,16 +31,6 @@ else: # pragma: no cover
from UserDict import IterableUserDict
from UserList import UserList
def _u(s):
return unicode(s, 'unicode_escape')
def _native(s):
if isinstance(s, unicode):
return s.encode('unicode_escape')
return s
_b = _native
PYTHON3 = False
PYTHON2 = True
......
......@@ -1735,7 +1735,6 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
# but because they are newly created, they aren't in the
# pickle cache yet.
# Nothing should blow up when this happens
from persistent._compat import _b
KEY = b'123'
jar = self._makeJar()
c1 = self._makeOne()
......@@ -1753,8 +1752,7 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
def test_accessed_invalidated_with_jar_and_oid_but_no_cache(self):
# This scenario arises in ZODB tests where the jar is faked
from persistent._compat import _b
KEY = _b('123')
KEY = b'123'
class Jar(object):
accessed = False
def __getattr__(self, name):
......
This diff is collapsed.
......@@ -24,21 +24,19 @@ class WeakRefTests(unittest.TestCase):
return self._getTargetClass()(ob)
def test_ctor_target_wo_jar(self):
from persistent._compat import _b
target = _makeTarget()
wref = self._makeOne(target)
self.assertTrue(wref._v_ob is target)
self.assertEqual(wref.oid, _b('OID'))
self.assertEqual(wref.oid, b'OID')
self.assertTrue(wref.dm is None)
self.assertFalse('database_name' in wref.__dict__)
def test_ctor_target_w_jar(self):
from persistent._compat import _b
target = _makeTarget()
target._p_jar = jar = _makeJar()
wref = self._makeOne(target)
self.assertTrue(wref._v_ob is target)
self.assertEqual(wref.oid, _b('OID'))
self.assertEqual(wref.oid, b'OID')
self.assertTrue(wref.dm is jar)
self.assertEqual(wref.database_name, 'testing')
......@@ -181,14 +179,13 @@ class PersistentWeakKeyDictionaryTests(unittest.TestCase):
def test___setstate___empty(self):
from persistent.wref import WeakRef
from persistent._compat import _b
jar = _makeJar()
KEY = _b('KEY')
KEY2 = _b('KEY2')
KEY3 = _b('KEY3')
VALUE = _b('VALUE')
VALUE2 = _b('VALUE2')
VALUE3 = _b('VALUE3')
KEY = b'KEY'
KEY2 = b'KEY2'
KEY3 = b'KEY3'
VALUE = b'VALUE'
VALUE2 = b'VALUE2'
VALUE3 = b'VALUE3'
key = jar[KEY] = _makeTarget(oid=KEY)
key._p_jar = jar
kref = WeakRef(key)
......@@ -208,7 +205,7 @@ class PersistentWeakKeyDictionaryTests(unittest.TestCase):
value3._p_jar = jar
pwkd = self._makeOne(None)
pwkd.__setstate__({'data':
[(kref, value), (kref2, value2), (kref3, value3)]})
[(kref, value), (kref2, value2), (kref3, value3)]})
self.assertTrue(pwkd[key] is value)
self.assertTrue(pwkd.get(key2) is None)
self.assertTrue(pwkd[key3] is value3)
......@@ -317,9 +314,8 @@ class PersistentWeakKeyDictionaryTests(unittest.TestCase):
self.assertTrue(target[key] is value)
def _makeTarget(oid='OID'):
def _makeTarget(oid=b'OID'):
from persistent import Persistent
from persistent._compat import _b
class Derived(Persistent):
def __hash__(self):
return hash(self._p_oid)
......@@ -328,7 +324,7 @@ def _makeTarget(oid='OID'):
def __repr__(self): # pragma: no cover
return 'Derived: %s' % self._p_oid
derived = Derived()
derived._p_oid = _b(oid)
derived._p_oid = oid
return derived
def _makeJar():
......
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