Skip to content

Commit

Permalink
Merge pull request #25 from zopefoundation/py3
Browse files Browse the repository at this point in the history
Python 3 compatibility reached
  • Loading branch information
dataflake committed May 15, 2017
2 parents 964951b + 43c332a commit 8dcae5e
Show file tree
Hide file tree
Showing 34 changed files with 159 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*.pyo
*.egg-info
.installed.cfg
.mr.developer.cfg
.tox
bin/
build/
develop-eggs/
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
- 3.6
install:
- pip install -U setuptools==33.1.1
- python bootstrap.py
- bin/buildout
script:
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
4.0a4 (unreleased)
------------------

- Python 3 compatibility

- Target use with Zope 4: no longer support 2.13.x.

- `five.globalrequest` got merged into Zope2 itself.

- Use aq_inner before aq_parent at some places to safely get the parent
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
include *.txt
include *.rst
include *.cfg
exclude .*.cfg

recursive-include src *

global-exclude *.pyc
global-exclude *.pyo

include *.py
18 changes: 16 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
[buildout]
extends = https://raw.githubusercontent.com/zopefoundation/Zope/master/versions.cfg
extensions =
mr.developer
extends =
https://raw.githubusercontent.com/zopefoundation/Zope/master/sources.cfg
https://raw.githubusercontent.com/zopefoundation/Zope/master/versions-prod.cfg

develop = .
parts = interpreter test
parts = interpreter test tox
auto-checkout =
Zope2

[sources]
Zope2 = git ${remotes:github}/Zope pushurl=${remotes:github_push}/Zope

[versions]
Products.ZCatalog =
Expand All @@ -16,3 +25,8 @@ eggs = Products.ZCatalog
[test]
recipe = zc.recipe.testrunner
eggs = Products.ZCatalog

[tox]
recipe = zc.recipe.egg
eggs =
tox
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
"License :: OSI Approved :: Zope Public License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2 :: Only",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Internet :: WWW/HTTP :: Indexing/Search",
],
install_requires=[
'setuptools',
Expand Down
28 changes: 14 additions & 14 deletions src/Products/PluginIndexes/BooleanIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,26 @@ def test_index_many_true(self):
for i in range(0, 100):
obj = Dummy(i, i < 80 and True or False)
index._index_object(obj.id, obj, attr='truth')
self.assertEqual(list(index._index), range(80, 100))
self.assertEqual(list(index._index), list(range(80, 100)))
self.assertEqual(len(index._unindex), 100)

res, idx = index._apply_index({'truth': True})
self.assertEqual(list(res), range(0, 80))
self.assertEqual(list(res), list(range(0, 80)))
res, idx = index._apply_index({'truth': False})
self.assertEqual(list(res), range(80, 100))
self.assertEqual(list(res), list(range(80, 100)))

def test_index_many_false(self):
index = self._makeOne()
for i in range(0, 100):
obj = Dummy(i, i >= 80 and True or False)
index._index_object(obj.id, obj, attr='truth')
self.assertEqual(list(index._index), range(80, 100))
self.assertEqual(list(index._index), list(range(80, 100)))
self.assertEqual(len(index._unindex), 100)

res, idx = index._apply_index({'truth': False})
self.assertEqual(list(res), range(0, 80))
self.assertEqual(list(res), list(range(0, 80)))
res, idx = index._apply_index({'truth': True})
self.assertEqual(list(res), range(80, 100))
self.assertEqual(list(res), list(range(80, 100)))

def test_index_many_change(self):
index = self._makeOne()
Expand All @@ -144,26 +144,26 @@ def add(i, value):
# Now add an equal number of False values
for i in range(4, 8):
add(i, False)
self.assertEqual(list(index._index), range(4, 8))
self.assertEqual(list(index._index), list(range(4, 8)))
self.assertEqual(len(index._unindex), 8)
# Once False gets to be more than 60% of the indexed set, we switch
add(8, False)
self.assertEqual(list(index._index), range(4, 9))
self.assertEqual(list(index._index), list(range(4, 9)))
add(9, False)
self.assertEqual(list(index._index), range(0, 4))
self.assertEqual(list(index._index), list(range(0, 4)))
res, idx = index._apply_index({'truth': True})
self.assertEqual(list(res), range(0, 4))
self.assertEqual(list(res), list(range(0, 4)))
res, idx = index._apply_index({'truth': False})
self.assertEqual(list(res), range(4, 10))
self.assertEqual(list(res), list(range(4, 10)))
# and we can again switch if the percentages change again
for i in range(6, 10):
index.unindex_object(i)
self.assertEqual(list(index._index), range(4, 6))
self.assertEqual(list(index._index), list(range(4, 6)))
self.assertEqual(len(index._unindex), 6)
res, idx = index._apply_index({'truth': True})
self.assertEqual(list(res), range(0, 4))
self.assertEqual(list(res), list(range(0, 4)))
res, idx = index._apply_index({'truth': False})
self.assertEqual(list(res), range(4, 6))
self.assertEqual(list(res), list(range(4, 6)))

def test_items(self):
index = self._makeOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def update(self, d):
self.__setitem__(key, val)

def values(self):
return map(self.get, self._keys)
return list(map(self.get, self._keys))


class Component(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
states = ['published', 'pending', 'private', 'intranet']
types = ['Document', 'News', 'File', 'Image']
default_pages = [True, False, False, False, False, False]
subjects = map(lambda x: 'subject_%s' % x, range(6))
keywords = map(lambda x: 'keyword_%s' % x, range(6))
subjects = list(map(lambda x: 'subject_%s' % x, range(6)))
keywords = list(map(lambda x: 'keyword_%s' % x, range(6)))


class TestObject(object):
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/DateRangeIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def checkApply():
result = result.keys()
assert used == (index._since_field, index._until_field)
assert len(result) == len(expectedValues), \
'%s | %s' % (map(None, result), expectedValues)
'%s | %s' % (list(result), expectedValues)
for k, v in expectedValues:
assert k in result
return result, used
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_retrieval(self):
results, used = self._checkApply(index, {'work': value}, matches)
matches = sorted(matches, key=lambda d: d[1].name())

for result, match in map(None, results, matches):
for result, match in zip(results, matches):
self.assertEqual(index.getEntryForObject(result),
match[1].datum())

Expand Down
19 changes: 6 additions & 13 deletions src/Products/PluginIndexes/FieldIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def setUp(self):
(4, Dummy('abcd')),
(5, Dummy('abce')),
(6, Dummy('abce')),
(7, Dummy(0))]
(7, Dummy('0'))]
self._forward = {}
self._backward = {}
for k, v in self._values:
Expand All @@ -85,7 +85,7 @@ def setUp(self):
'range': 'max'}}
self._max_req_n = {'foo': {'query': 'abc',
'range': 'max',
'not': ['a', 'b', 0]}}
'not': ['a', 'b', '0']}}
self._range_req = {'foo': {'query': ('abc', 'abcd'),
'range': 'min:max'}}
self._range_ren = {'foo': {'query': ('abc', 'abcd'),
Expand All @@ -94,11 +94,11 @@ def setUp(self):
self._range_non = {'foo': {'query': ('a', 'aa'),
'range': 'min:max',
'not': 'a'}}
self._zero_req = {'foo': 0}
self._zero_req = {'foo': '0'}
self._not_1 = {'foo': {'query': 'a', 'not': 'a'}}
self._not_2 = {'foo': {'query': ['a', 'ab'], 'not': 'a'}}
self._not_3 = {'foo': {'not': 'a'}}
self._not_4 = {'foo': {'not': [0]}}
self._not_4 = {'foo': {'not': ['0']}}
self._not_5 = {'foo': {'not': ['a', 'b']}}
self._not_6 = {'foo': 'a', 'bar': {'query': 123, 'not': 1}}

Expand All @@ -114,9 +114,9 @@ def checkApply():
result = result.keys()
assert used == ('foo', )
assert len(result) == len(expectedValues), \
'%s | %s' % (map(None, result), expectedValues)
'%s | %s' % (list(result), expectedValues)
for k, v in expectedValues:
assert k in result
self.assertTrue(k in result)

index = self._index

Expand Down Expand Up @@ -210,13 +210,6 @@ def testPopulated(self):
self._checkApply(self._not_5, values[1:])
self._checkApply(self._not_6, values[0:1])

def testZero(self):
# Make sure 0 gets indexed.
self._populateIndex()
values = self._values
self._checkApply(self._zero_req, values[-1:])
assert 0 in self._index.uniqueValues('foo')

def testNone(self):
# Make sure None is ignored.
self._index.index_object(10, Dummy(None))
Expand Down
31 changes: 8 additions & 23 deletions src/Products/PluginIndexes/KeywordIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ def __str__(self):
__repr__ = __str__


def sortedUnique(seq):
unique = {}
for i in seq:
unique[i] = None
unique = unique.keys()
unique.sort()
return unique


class TestKeywordIndex(unittest.TestCase):

_old_log_write = None
Expand Down Expand Up @@ -75,20 +66,20 @@ def setUp(self):
(4, Dummy(['a', 'b', 'c', 'd'])),
(5, Dummy(['a', 'b', 'c', 'e'])),
(6, Dummy(['a', 'b', 'c', 'e', 'f'])),
(7, Dummy([0])),
(7, Dummy(['0'])),
]
self._noop_req = {'bar': 123}
self._all_req = {'foo': ['a']}
self._some_req = {'foo': ['e']}
self._overlap_req = {'foo': ['c', 'e']}
self._string_req = {'foo': 'a'}
self._zero_req = {'foo': [0]}
self._zero_req = {'foo': ['0']}

self._not_1 = {'foo': {'query': 'f', 'not': 'f'}}
self._not_2 = {'foo': {'query': ['e', 'f'], 'not': 'f'}}
self._not_3 = {'foo': {'not': 0}}
self._not_4 = {'foo': {'not': [0, 'e']}}
self._not_5 = {'foo': {'not': [0, 'no-value']}}
self._not_3 = {'foo': {'not': '0'}}
self._not_4 = {'foo': {'not': ['0', 'e']}}
self._not_5 = {'foo': {'not': ['0', 'no-value']}}
self._not_6 = {'foo': 'c', 'bar': {'query': 123, 'not': 1}}

def _populateIndex(self):
Expand All @@ -101,8 +92,8 @@ def checkApply():
result, used = self._index._apply_index(req)
assert used == ('foo', )
assert len(result) == len(expectedValues), \
'%s | %s' % (map(None, result),
map(lambda x: x[0], expectedValues))
'%s | %s' % (list(result),
list(map(lambda x: x[0], expectedValues)))

if hasattr(result, 'keys'):
result = result.keys()
Expand Down Expand Up @@ -176,7 +167,7 @@ def testPopulated(self):
for k, v in values:
entry = self._index.getEntryForObject(k)
entry.sort()
kw = sortedUnique(v.foo())
kw = sorted(set(v.foo()))
self.assertEqual(entry, kw)

assert len(list(self._index.uniqueValues('foo'))) == len(values) - 1
Expand All @@ -194,12 +185,6 @@ def testPopulated(self):
self._checkApply(self._not_5, values[:7])
self._checkApply(self._not_6, values[2:7])

def testZero(self):
self._populateIndex()
values = self._values
self._checkApply(self._zero_req, values[-1:])
assert 0 in self._index.uniqueValues('foo')

def testReindexChange(self):
self._populateIndex()
values = self._values
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/PathIndex/PathIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def index_object(self, docid, obj, threshold=100):
if isinstance(path, (list, tuple)):
path = '/' + '/'.join(path[1:])

comps = filter(None, path.split('/'))
comps = list(filter(None, path.split('/')))

old_value = self._unindex.get(docid, None)
if old_value == path:
Expand Down Expand Up @@ -280,7 +280,7 @@ def _search(self, path, default_level=0):
[self._search(path, level)
for level in range(self._depth + 1)])

comps = filter(None, path.split('/'))
comps = list(filter(None, path.split('/')))

if level + len(comps) - 1 > self._depth:
# Our search is for a path longer than anything in the index
Expand Down
4 changes: 2 additions & 2 deletions src/Products/PluginIndexes/PathIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ def test___apply_index_root_levelO_dict(self):
_populateIndex(index)
query = {'path': {'query': '/', 'level': 0}}
res = index._apply_index(query)
self.assertEqual(list(res[0].keys()), range(1, 19))
self.assertEqual(list(res[0].keys()), list(range(1, 19)))

def test___apply_index_root_levelO_tuple(self):
index = self._makeOne()
_populateIndex(index)
query = {'path': (('/', 0),)}
res = index._apply_index(query)
self.assertEqual(list(res[0].keys()), range(1, 19))
self.assertEqual(list(res[0].keys()), list(range(1, 19)))

def test__apply_index_simple(self):
index = self._makeOne()
Expand Down
2 changes: 1 addition & 1 deletion src/Products/PluginIndexes/TopicIndex/FilteredSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def setExpression(self, expr):
self.expr = expr

def __repr__(self):
return '%s: (%s) %s' % (self.id, self.expr, map(None, self.ids))
return '%s: (%s) %s' % (self.id, self.expr, list(map(None, self.ids)))

__str__ = __repr__

Expand Down
8 changes: 4 additions & 4 deletions src/Products/PluginIndexes/UUIDIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def setUp(self):
self._values = [
(0, Dummy('a')),
(1, Dummy('ab')),
(2, Dummy(123)),
(3, Dummy(234)),
(4, Dummy(0))]
(2, Dummy('123')),
(3, Dummy('234')),
(4, Dummy('0'))]
self._forward = {}
self._backward = {}
for k, v in self._values:
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_populated(self):
self.assertEqual(self._index.getEntryForObject(k), v.foo())

self._checkApply({'foo': 'a'}, [values[0]])
self._checkApply({'foo': 0}, [values[4]])
self._checkApply({'foo': '0'}, [values[4]])
self._checkApply({'foo': ['a', 'ab']}, values[:2])

def test_none(self):
Expand Down
Loading

0 comments on commit 8dcae5e

Please sign in to comment.