|
3 | 3 | from zope.interface import implementer |
4 | 4 |
|
5 | 5 |
|
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 | | - |
51 | 6 | @implementer(IParsedQueryIndexModifier) |
52 | 7 | class base: |
53 | 8 | """DateIndex query modifier |
|
0 commit comments