Skip to content

Commit

Permalink
Merge branch 'master' into issue_482
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Mar 8, 2019
2 parents 2a3cb67 + f48dda6 commit e664569
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -2,8 +2,6 @@ language: python

matrix:
include:
- python: "2.7"
env: TOXENV=lint-py27
- python: "3.6"
env: TOXENV=lint-py36
- python: "2.7"
Expand All @@ -19,8 +17,6 @@ matrix:
env: TOXENV=py38
dist: xenial
allow_failures:
- python: "2.7"
env: TOXENV=lint-py27
- python: "3.6"
env: TOXENV=lint-py36

Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -17,6 +17,9 @@ Fixes
- Resurrected copyright and license page
(`#482 <https://github.com/zopefoundation/Zope/issues/482>`_)

- Fix FindSupport binary value handling
(`#406 <https://github.com/zopefoundation/Zope/issues/406>`_)

- Fix remove double quoting in ``ZPublisher.HTTPRequest.search_type``
(`#511 <https://github.com/zopefoundation/Zope/issues/511>`_)

Expand Down
5 changes: 5 additions & 0 deletions buildout.cfg
Expand Up @@ -19,6 +19,11 @@ parts =
requirements
sources-dir = develop
auto-checkout =
Products.BTreeFolder2
Products.MailHost
Products.PythonScripts
Products.SiteErrorLog
Products.ZCatalog

[testenv]
PYTHONHASHSEED = random
Expand Down
20 changes: 17 additions & 3 deletions src/OFS/FindSupport.py
Expand Up @@ -12,6 +12,8 @@
##############################################################################
"""Find support
"""
import six

from AccessControl import ClassSecurityInfo
from AccessControl.class_init import InitializeClass
from AccessControl.Permission import getPermissionIdentifier
Expand All @@ -27,6 +29,7 @@
from ExtensionClass import Base
from OFS.interfaces import IFindSupport
from zope.interface import implementer
from ZPublisher.HTTPRequest import default_encoding


@implementer(IFindSupport)
Expand Down Expand Up @@ -122,14 +125,25 @@ def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None,
dflag = 1

bs = aq_base(ob)
if obj_searchterm:
if hasattr(ob, 'PrincipiaSearchSource'):
pss = ob.PrincipiaSearchSource()
if six.PY3 and not isinstance(pss, str):
pss = pss.decode(default_encoding)
if hasattr(ob, 'SearchableText'):
st = ob.SearchableText()
if six.PY3 and not isinstance(st, str):
st = st.decode(default_encoding)
else:
pss = st = ''

if ((not obj_ids or absattr(bs.getId()) in obj_ids) and
(not obj_metatypes or (hasattr(bs, 'meta_type') and
bs.meta_type in obj_metatypes)) and
(not obj_searchterm or
(hasattr(ob, 'PrincipiaSearchSource') and
obj_searchterm in ob.PrincipiaSearchSource()) or
(hasattr(ob, 'SearchableText') and
obj_searchterm in ob.SearchableText())
obj_searchterm in pss) or
(hasattr(ob, 'SearchableText') and obj_searchterm in st)
) and
(not obj_expr or expr_match(ob, obj_expr)) and
(not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec)) and
Expand Down
19 changes: 18 additions & 1 deletion src/OFS/tests/testFindSupport.py
@@ -1,17 +1,22 @@
from OFS.FindSupport import FindSupport

import six
import unittest


class DummyItem(FindSupport):
""" """

def __init__(self, id):
def __init__(self, id, text=''):
self.id = id
self.text = text

def getId(self):
return self.id

def PrincipiaSearchSource(self):
return self.text


class DummyFolder(DummyItem, dict):

Expand Down Expand Up @@ -48,3 +53,15 @@ def func(obj, p):
self.assertEqual(self.base['1'].id, '1')
self.assertEqual(self.base['2'].id, 'foo2')
self.assertEqual(self.base['3'].id, '3')

@unittest.skipIf(six.PY2, 'Not applicable under Python 2')
def test_find_apply_text(self):
# Make sure ZopeFind can handle text and encoded text (binary) data
unencoded = u'\xfcml\xe4\xfct'
encoded = u'\xfcml\xe4\xfct'.encode('UTF-8')
self.base['text'] = DummyItem('text', text=unencoded)
self.base['bytes'] = DummyItem('bytes', text=encoded)

res = self.base.ZopeFind(self.base, obj_searchterm=unencoded)
self.assertEqual(len(res), 2)
self.assertEqual(set([x[0] for x in res]), set(['text', 'bytes']))
12 changes: 2 additions & 10 deletions tox.ini
Expand Up @@ -5,7 +5,6 @@ envlist =
py36,
py37,
py38,
lint-py27,
lint-py36
coverage-report

Expand Down Expand Up @@ -39,7 +38,7 @@ commands =
coverage report -i --fail-under=80

[testenv:isort-apply]
basepython = python2.7
basepython = python3.6
skip_install = true
deps =
-cconstraints.txt
Expand All @@ -50,7 +49,7 @@ commands =
#isort --apply --recursive {toxinidir}/src/OFS {posargs}

[testenv:autopep8]
basepython = python2.7
basepython = python3.6
skip_install = true
deps =
-cconstraints.txt
Expand Down Expand Up @@ -97,13 +96,6 @@ commands =
whitelist_externals =
mkdir

[testenv:lint-py27]
basepython = python2.7
skip_install = true
deps = {[lint]deps}
commands = {[lint]commands}
whitelist_externals = {[lint]whitelist_externals}

[testenv:lint-py36]
basepython = python3.6
skip_install = true
Expand Down

0 comments on commit e664569

Please sign in to comment.