Skip to content

Commit 59b66d0

Browse files
committed
Remove Subject index modifier (Python 2 leftover)
The Subject IParsedQueryIndexModifier was a no-op: it returned the value unchanged since the utf-8 encoding branch was unreachable dead code after the early return added during the Python 3 migration. Remove the class, its ZCML registration, and the related tests. Fixes #155
1 parent b1a171c commit 59b66d0

4 files changed

Lines changed: 2 additions & 68 deletions

File tree

news/155.internal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove Subject index modifier — a Python 2 leftover that was already a no-op.
2+
@jensens

src/plone/app/querystring/indexmodifiers/configure.zcml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
i18n_domain="plone"
44
>
55

6-
<utility
7-
factory=".query_index_modifiers.Subject"
8-
provides="..interfaces.IParsedQueryIndexModifier"
9-
name="Subject"
10-
/>
116
<utility
127
factory=".query_index_modifiers.Date"
138
provides="..interfaces.IParsedQueryIndexModifier"

src/plone/app/querystring/indexmodifiers/query_index_modifiers.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,6 @@
33
from zope.interface import implementer
44

55

6-
@implementer(IParsedQueryIndexModifier)
7-
class Subject:
8-
"""
9-
The Subject field in Plone currently uses a utf-8 encoded string.
10-
When a catalog query tries to compare a unicode string from the
11-
parsedquery with existing utf-8 encoded string indexes unindexing
12-
will fail with a UnicodeDecodeError. To prevent this from happening
13-
we always encode the Subject query.
14-
15-
XXX: As soon as Plone uses unicode for all indexes, this code can
16-
be removed.
17-
"""
18-
19-
def __call__(self, value):
20-
return ("Subject", value)
21-
22-
# Get the query operator
23-
op = None
24-
if "query" in value:
25-
op = "query"
26-
elif "not" in value:
27-
op = "not"
28-
29-
query = value[op]
30-
# query can be a unicode string or a list of unicode strings.
31-
if isinstance(query, str):
32-
query = query.encode("utf-8")
33-
elif isinstance(query, list):
34-
# We do not want to change the collections' own query string,
35-
# therefore we create a new copy of the list.
36-
copy_of_query = list(query)
37-
# Iterate over all query items and encode them if they are
38-
# unicode strings
39-
i = 0
40-
for item in copy_of_query:
41-
if isinstance(item, str):
42-
copy_of_query[i] = item.encode("utf-8")
43-
i += 1
44-
query = copy_of_query
45-
else:
46-
pass
47-
value[op] = query
48-
return ("Subject", value)
49-
50-
516
@implementer(IParsedQueryIndexModifier)
527
class base:
538
"""DateIndex query modifier

src/plone/app/querystring/tests/testIndexmodifiers.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@
66

77

88
class TestIndexModifiers(unittest.TestCase):
9-
def test_subject_encoded(self):
10-
self.assertEqual(
11-
query_index_modifiers.Subject()({"query": "foobar"}),
12-
("Subject", {"query": "foobar"}),
13-
)
14-
15-
def test_subject_encoded__list(self):
16-
self.assertEqual(
17-
query_index_modifiers.Subject()({"query": ["foobar"]}),
18-
("Subject", {"query": ["foobar"]}),
19-
)
20-
21-
def test_subject_encoded__list_not(self):
22-
self.assertEqual(
23-
query_index_modifiers.Subject()({"not": ["foobar"]}),
24-
("Subject", {"not": ["foobar"]}),
25-
)
26-
279
def test_date_modifier(self):
2810
modifier = query_index_modifiers.start()
2911
self.assertTrue(

0 commit comments

Comments
 (0)