From d5dea80d8afb8d10c888c596e905b18d37838956 Mon Sep 17 00:00:00 2001 From: David Glick Date: Sun, 1 Oct 2023 22:04:45 +0200 Subject: [PATCH] Fix compatibility with Python 2.7 (#163) * Fix compatibility with Python 2.7 * changelog --- news/162.bugfix | 1 + src/plone/rest/tests/test_traversal.py | 4 ++-- src/plone/rest/traverse.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 news/162.bugfix diff --git a/news/162.bugfix b/news/162.bugfix new file mode 100644 index 0000000..6cb67bf --- /dev/null +++ b/news/162.bugfix @@ -0,0 +1 @@ +Fix compatibility with Python 2.7. @davisagli diff --git a/src/plone/rest/tests/test_traversal.py b/src/plone/rest/tests/test_traversal.py index 5d5389d..cda30bf 100644 --- a/src/plone/rest/tests/test_traversal.py +++ b/src/plone/rest/tests/test_traversal.py @@ -118,7 +118,7 @@ def test_html_request_via_double_apis_raises_redirect(self): self.traverse(path="/plone/++api++/++api++", accept="text/html") self.assertEqual( exc.exception.headers["Location"], - f"{portal_url}/++api++", + "{}/++api++".format(portal_url), ) def test_html_request_via_multiple_apis_raises_redirect(self): @@ -129,7 +129,7 @@ def test_html_request_via_multiple_apis_raises_redirect(self): ) self.assertEqual( exc.exception.headers["Location"], - f"{portal_url}/++api++/search", + "{}/++api++/search".format(portal_url), ) def test_html_request_via_multiple_bad_apis_raises_not_found(self): diff --git a/src/plone/rest/traverse.py b/src/plone/rest/traverse.py index 0a151c8..115f8d6 100644 --- a/src/plone/rest/traverse.py +++ b/src/plone/rest/traverse.py @@ -69,8 +69,8 @@ def traverse(self, name_ignored, subpath_ignored): url = self.request.ACTUAL_URL if url.count(name) > 1: # Redirect to proper url. - while f"{name}{name}" in url: - url = url.replace(f"{name}{name}", name) + while name + name in url: + url = url.replace(name + name, name) if url.count(name) > 1: # Something like: .../++api++/something/++api++ # Return nothing, so a NotFound is raised.