Skip to content

Commit

Permalink
Merge 082344b into be97576
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 11, 2018
2 parents be97576 + 082344b commit 2062881
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 40 deletions.
26 changes: 15 additions & 11 deletions .travis.yml
@@ -1,16 +1,20 @@
language: python
sudo: false
python:
- 2.7
- 3.6
- pypy
- pypy3
matrix:
include:
- python: 2.7
env: PURE_PYTHON=1
- python: 3.6
env: PURE_PYTHON=1
group: travis_latest
language: python
jobs:
include:
- python: 2.7 # 2.7.14 pip 9.0.1
- python: 3.6 # 3.6.3 pip 9.0.1
- python: 3.7 # 3.7.0 pip 10.0.1
dist: xenial
sudo: true
- python: pypy # 2.7.13 pip 9.0.1
- python: pypy3 # 3.5.3 pip 9.0.1
- python: 2.7
env: PURE_PYTHON=1
- python: 3.6
env: PURE_PYTHON=1
env:
global:
- CC="ccache gcc"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -139,8 +139,8 @@ def _c(m):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down
1 change: 0 additions & 1 deletion src/nti/externalization/externalization/_externalizer.pxd
Expand Up @@ -6,7 +6,6 @@ from nti.externalization.__base_interfaces cimport LocatedExternalDict as LED
from nti.externalization.externalization._decorate cimport decorate_external_object

# Imports
cdef collections
cdef defaultdict
cdef six
cdef numbers
Expand Down
13 changes: 9 additions & 4 deletions src/nti/externalization/externalization/externalizer.py
Expand Up @@ -14,8 +14,14 @@
from __future__ import print_function

# stdlib imports
import collections
import warnings
try:
from collections.abc import Set
from collections.abc import Mapping
except ImportError:
from collections import Set
from collections import Mapping
from collections import defaultdict
from weakref import WeakKeyDictionary

import BTrees.OOBTree
Expand All @@ -42,7 +48,6 @@

logger = __import__('logging').getLogger(__name__)

defaultdict = collections.defaultdict

# It turns out that the name we use for externalization (and really the registry, too)
# we must keep thread-local. We call into objects without any context,
Expand All @@ -63,7 +68,7 @@
#: to be directly externalized.
SEQUENCE_TYPES = (
persistent.list.PersistentList,
collections.Set,
Set,
list,
tuple,
)
Expand All @@ -73,7 +78,7 @@
MAPPING_TYPES = (
persistent.mapping.PersistentMapping,
BTrees.OOBTree.OOBTree,
collections.Mapping
Mapping
)


Expand Down
5 changes: 4 additions & 1 deletion src/nti/externalization/internalization/externals.py
Expand Up @@ -14,7 +14,10 @@


# stdlib imports
from collections import MutableSequence
try:
from collections.abc import MutableSequence
except ImportError:
from collections import MutableSequence


from zope import component
Expand Down
8 changes: 6 additions & 2 deletions src/nti/externalization/internalization/updater.py
Expand Up @@ -11,8 +11,12 @@


# stdlib imports
from collections import MutableSequence
from collections import MutableMapping
try:
from collections.abc import MutableSequence
from collections.abc import MutableMapping
except ImportError:
from collections import MutableSequence
from collections import MutableMapping
import inspect
import warnings

Expand Down
35 changes: 21 additions & 14 deletions src/nti/externalization/persistence.py
Expand Up @@ -9,7 +9,15 @@
from __future__ import print_function

# stdlib imports
import collections
try:
from collections.abc import Sequence
except ImportError:
from collections import Sequence

try:
from itertools import izip
except ImportError:
izip = zip

import persistent
from persistent.list import PersistentList
Expand Down Expand Up @@ -86,16 +94,15 @@ def setPersistentStateChanged(obj):

def _weakRef_toExternalObject(self):
val = self()
if val is not None:
return toExternalObject(val)
return toExternalObject(val) if val is not None else None

PWeakRef.toExternalObject = _weakRef_toExternalObject
interface.classImplements(PWeakRef, IExternalObject)


def _weakRef_toExternalOID(self):
val = self()
if val is not None:
return toExternalOID(val)
return toExternalOID(val) if val is not None else None
PWeakRef.toExternalOID = _weakRef_toExternalOID


Expand Down Expand Up @@ -176,17 +183,17 @@ def __getitem__(self, i):
def __eq__(self, other):
# If we just compare lists, weak refs will fail badly
# if they're compared with non-weak refs
if not isinstance(other, collections.Sequence):
if not isinstance(other, Sequence):
return False

result = False
if len(self) == len(other):
result = True
for i in range(len(self)):
if self[i] != other[i]:
result = False
break
return result
if len(self) != len(other):
return False

for obj1, obj2 in izip(self, other):
if obj1 != obj2:
return False

return True

def __wrap(self, obj):
return obj if isinstance(obj, PWeakRef) else PWeakRef(obj)
Expand Down
13 changes: 11 additions & 2 deletions src/nti/externalization/tests/test_persistence.py
Expand Up @@ -95,6 +95,17 @@ def test_mutate(self):
obj.remove(pers2)
assert_that(obj, is_([]))

def test_equality(self):

obj = PersistentExternalizableWeakList()
pers = Persistent()
obj.append(pers)

assert_that(obj, is_([pers]))
assert_that(obj, is_not([pers, pers]))
assert_that(obj, is_not([]))
assert_that(obj, is_not([self]))

class TestPersistentExternalizableDict(unittest.TestCase):

def test_to_external_dict(self):
Expand Down Expand Up @@ -162,7 +173,6 @@ class P(Persistent):
def toExternalObject(self, **kwargs):
return {'a': 42}

p = P()
wref = PWeakRef(P())

assert_that(wref.toExternalObject(), is_({'a': 42}))
Expand All @@ -173,7 +183,6 @@ class P(Persistent):
def toExternalOID(self, **kwargs):
return b'abc'

p = P()
wref = PWeakRef(P())

assert_that(wref.toExternalOID(), is_(b'abc'))
8 changes: 4 additions & 4 deletions src/nti/externalization/tests/test_representation.py
Expand Up @@ -58,7 +58,7 @@ class Foo(object):
def test_raises_POSError(self):
def raise_(self):
from ZODB.POSException import ConnectionStateError
raise ConnectionStateError("CSE")
raise ConnectionStateError()

@representation.WithRepr(raise_)
class Foo(object):
Expand All @@ -67,11 +67,11 @@ class Foo(object):
r = repr(Foo())
assert_that(r,
is_("<nti.externalization.tests.test_representation.Foo(Ghost, "
"ConnectionStateError('CSE',))>"))
"ConnectionStateError())>"))

def test_raises_attribute_error(self):
def raise_(self):
raise AttributeError("an attr")
raise AttributeError()

@representation.WithRepr(raise_)
class Foo(object):
Expand All @@ -80,7 +80,7 @@ class Foo(object):
r = repr(Foo())
assert_that(r,
is_("<nti.externalization.tests.test_representation.Foo("
"AttributeError('an attr',))>"))
"AttributeError())>"))

class TestYaml(unittest.TestCase):

Expand Down

0 comments on commit 2062881

Please sign in to comment.