Skip to content

Commit

Permalink
More Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
rbu committed May 3, 2017
1 parent db506d2 commit c346b23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/App/tests/testImageFile.py
Expand Up @@ -63,7 +63,7 @@ def test_index_html(self):
'www', 'zopelogo.png')
image = App.ImageFile.ImageFile(path)
result = image.index_html(request, response)
self.assertEqual(stdout.getvalue(), '')
self.assertEqual(stdout.getvalue(), b'')
self.assertTrue(isinstance(result, io.FileIO))
self.assertTrue(b''.join(result).startswith(b'\x89PNG\r\n'))
self.assertEqual(len(result), image.size)
13 changes: 6 additions & 7 deletions src/Products/Five/browser/decode.py
Expand Up @@ -21,8 +21,7 @@
from ZPublisher.HTTPRequest import isCGI_NAMEs
from zope.i18n.interfaces import IUserPreferredCharsets

if sys.version_info >= (3, ):
unicode = str
from six import text_type, binary_type


def _decode(text, charsets):
Expand All @@ -31,7 +30,7 @@ def _decode(text, charsets):
# taken and adapted from zope.publisher.browser.BrowserRequest
for charset in charsets:
try:
text = unicode(text, charset)
text = text_type(text, charset)
break
except UnicodeError:
pass
Expand All @@ -54,16 +53,16 @@ def processInputValue(value, charsets):
for k, v in list(value.items()):
value[k] = processInputValue(v, charsets)
return value
elif isinstance(value, str):
elif isinstance(value, binary_type):
return _decode(value, charsets)
else:
return value


def processInputs(request, charsets=None):
"""Process the values in request.form to decode strings to unicode, using
the passed-in list of charsets. If none are passed in, look up the user's
preferred charsets. The default is to use utf-8.
"""Process the values in request.form to decode binary_type to text_type,
using the passed-in list of charsets. If none are passed in, look up the
user's preferred charsets. The default is to use utf-8.
"""
warn(u'processInputs() is deprecated and will be removed in Zope 5.0. If '
u'your view implements IBrowserPage, similar processing is now '
Expand Down
8 changes: 4 additions & 4 deletions src/Products/Five/tests/test_i18n.py
Expand Up @@ -46,10 +46,10 @@ def test_directive():
As you can see, both the default functionality and translation to
German work:
>>> translate(msg)
u'This is an explicit message'
>>> translate(msg, target_language='de')
u'Dies ist eine explizite Nachricht'
>>> translate(msg) == u'This is an explicit message'
True
>>> translate(msg, target_language='de') == u'Dies ist eine explizite Nachricht'
True
"""


Expand Down
6 changes: 2 additions & 4 deletions src/Products/Five/utilities/marker.py
Expand Up @@ -16,8 +16,6 @@
Allows for arbitrary application of marker interfaces to objects.
"""

from sets import Set

from zope.interface import implementer, implementedBy, providedBy
from zope.interface import directlyProvides, directlyProvidedBy
from zope.interface.interfaces import IInterface
Expand Down Expand Up @@ -105,12 +103,12 @@ def update(self, add=(), remove=()):
marker_ifaces = self.getAvailableInterfaces()
if len(add):
[mark(self.context, interface)
for interface in Set(marker_ifaces) & Set(add)]
for interface in set(marker_ifaces) & set(add)]

direct_ifaces = self.getDirectlyProvided()
if len(remove):
[erase(self.context, interface)
for interface in Set(direct_ifaces) & Set(remove)]
for interface in set(direct_ifaces) & set(remove)]

def _getInterfaceNames(self, interfaces):
return [interfaceToName(self, iface) for iface in interfaces]
Expand Down
4 changes: 2 additions & 2 deletions src/Testing/ZopeTestCase/zopedoctest/functional.py
Expand Up @@ -305,8 +305,8 @@ def setup_globs(self):
globs['http'] = http
globs['getRootFolder'] = getRootFolder
globs['sync'] = sync
globs['user_auth'] = base64.encodestring(
'%s:%s' % (user_name, user_password))
unencoded_user_auth = ('%s:%s' % (user_name, user_password)).encode('utf-8')
globs['user_auth'] = base64.encodestring(unencoded_user_auth)

def setup_test_class(self):
test_class = self._kw.get('test_class', FunctionalTestCase)
Expand Down

0 comments on commit c346b23

Please sign in to comment.