Skip to content

Commit

Permalink
Prepare for more Python 2 / 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jan 28, 2018
1 parent f50db20 commit 1c562a8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ New features:

Bug fixes:

- Imports are Python3 compatible
[ale-rt]
- Prepare for Python 2 / 3 compatibility
[ale-rt, pbauer]

- remove mention of "retina" (https://github.com/plone/Products.CMFPlone/issues/2123)
[tkimnguyen]
Expand Down
4 changes: 2 additions & 2 deletions plone/namedfile/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from zope.schema.fieldproperty import FieldProperty

import piexif
import six
import transaction


log = getLogger(__name__)


Expand Down Expand Up @@ -179,7 +179,7 @@ def _getData(self):
def _setData(self, data):

# Handle case when data is a string
if isinstance(data, unicode):
if isinstance(data, six.text_type):
data = data.encode('UTF-8')

if isinstance(data, str):
Expand Down
4 changes: 2 additions & 2 deletions plone/namedfile/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from zope.traversing.interfaces import TraversalError

import logging

import six

logger = logging.getLogger(__name__)
_marker = object()
Expand Down Expand Up @@ -114,7 +114,7 @@ def tag(self, height=_marker, width=_marker, alt=_marker,
if isinstance(v, int):
v = str(v)
elif isinstance(v, str):
v = unicode(v, 'utf8')
v = six.text_type(v, 'utf8')
parts.append(u'{0}={1}'.format(k, quoteattr(v)))
parts.append('/>')

Expand Down
3 changes: 2 additions & 1 deletion plone/namedfile/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from zope.interface import implementer
from zope.publisher.browser import FileUpload

import six

MAXCHUNKSIZE = 1 << 16

Expand All @@ -27,7 +28,7 @@ def store(self, data, blob):
class UnicodeStorable(StringStorable):

def store(self, data, blob):
if not isinstance(data, unicode):
if not isinstance(data, six.text_type):
raise NotStorable('Could not store data (not of "unicode" type).')

data = data.encode('UTF-8')
Expand Down
10 changes: 5 additions & 5 deletions plone/namedfile/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from plone.namedfile.utils.tiff_utils import process_tiff
from plone.registry.interfaces import IRegistry
from six import StringIO
from six.moves import urllib
from zope.component import queryUtility
from zope.deprecation import deprecate

import mimetypes
import os.path
import piexif
import PIL.Image
import six
import struct
import urllib


log = getLogger(__name__)

Expand Down Expand Up @@ -75,9 +75,9 @@ def set_headers(file, response, filename=None):
response.setHeader('Content-Length', file.getSize())

if filename is not None:
if not isinstance(filename, unicode):
filename = unicode(filename, 'utf-8', errors='ignore')
filename = urllib.quote(filename.encode('utf8'))
if not isinstance(filename, six.text_type):
filename = six.text_type(filename, 'utf-8', errors='ignore')
filename = urllib.parse.quote(filename.encode('utf8'))
response.setHeader(
'Content-Disposition',
'attachment; filename*=UTF-8\'\'{0}'.format(filename)
Expand Down

1 comment on commit 1c562a8

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pbauer Jenkins CI reporting about code analysis
See the full report here: http://jenkins.plone.org/job/package-plone.namedfile/66/violations

plone/namedfile/marshaler.py:67:36: C812 missing trailing comma
plone/namedfile/storages.py:12:1: I003 isort expected 1 blank line in imports, found 0
plone/namedfile/testing.py:18:9: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/namedfile/testing.py:22:36: C812 missing trailing comma
plone/namedfile/file.py:25:1: I003 isort expected 1 blank line in imports, found 0
plone/namedfile/file.py:261:9: Q001 Remove bad quotes from multiline string.
plone/namedfile/file.py:302:9: Q001 Remove bad quotes from multiline string.
plone/namedfile/handler.py:11:23: C812 missing trailing comma
plone/namedfile/interfaces.py:17:25: C812 missing trailing comma
plone/namedfile/scaling.py:33:1: I003 isort expected 1 blank line in imports, found 0
plone/namedfile/scaling.py:192:25: C815 missing trailing comma in Python 3.5+
plone/namedfile/scaling.py:195:5: C901 'DefaultImageScalingFactory.__call__' is too complex (15)
plone/namedfile/scaling.py:202:25: C816 missing trailing comma in Python 3.6+
plone/namedfile/scaling.py:242:29: C815 missing trailing comma in Python 3.5+
plone/namedfile/scaling.py:406:21: C816 missing trailing comma in Python 3.6+
plone/namedfile/scaling.py:433:25: C815 missing trailing comma in Python 3.5+
plone/namedfile/scaling.py:445:25: C815 missing trailing comma in Python 3.5+
plone/namedfile/scaling.py:459:21: C816 missing trailing comma in Python 3.6+
plone/namedfile/scaling.py:485:29: C815 missing trailing comma in Python 3.5+
plone/namedfile/scaling.py:499:17: C816 missing trailing comma in Python 3.6+
plone/namedfile/utils/__init__.py:19:1: I003 isort expected 1 blank line in imports, found 0
plone/namedfile/utils/__init__.py:83:66: C812 missing trailing comma
plone/namedfile/utils/__init__.py:150:15: T000 Todo note found.
plone/namedfile/utils/__init__.py:155:73: C812 missing trailing comma
plone/namedfile/utils/__init__.py:175:15: T000 Todo note found.
plone/namedfile/utils/__init__.py:182:18: C812 missing trailing comma
plone/namedfile/utils/__init__.py:187:1: C901 'rotate_image' is too complex (20)
plone/namedfile/utils/__init__.py:218:14: C812 missing trailing comma
plone/namedfile/utils/__init__.py:275:1: E302 expected 2 blank lines, found 1
plone/namedfile/utils/__init__.py:279:1: E302 expected 2 blank lines, found 1
plone/namedfile/utils/tiff_utils.py:11:1: C901 'process_tiff' is too complex (11)
plone/namedfile/utils/tiff_utils.py:20:7: T000 Todo note found.
plone/namedfile/utils/tiff_utils.py:81:7: T000 Todo note found.
plone/namedfile/utils/tiff_utils.py:82:7: T000 Todo note found.
plone/namedfile/tests/test_blobfile.py:40:31: C812 missing trailing comma
plone/namedfile/tests/test_blobfile.py:45:35: C812 missing trailing comma
plone/namedfile/tests/test_blobfile.py:50:46: C812 missing trailing comma
plone/namedfile/tests/test_blobfile.py:55:32: C812 missing trailing comma
plone/namedfile/tests/test_scaling.py:85:80: E501 line too long (86 > 79 characters)
plone/namedfile/tests/test_scaling.py:102:80: E501 line too long (81 > 79 characters)
plone/namedfile/tests/test_scaling.py:133:80: E501 line too long (86 > 79 characters)
plone/namedfile/tests/test_scaling.py:156:80: E501 line too long (86 > 79 characters)
plone/namedfile/tests/test_scaling.py:178:80: E501 line too long (86 > 79 characters)
plone/namedfile/tests/test_scaling.py:200:80: E501 line too long (86 > 79 characters)
plone/namedfile/tests/test_doctests.py:25:51: C812 missing trailing comma
plone/namedfile/tests/test_doctests.py:27:10: C812 missing trailing comma
plone/namedfile/tests/test_scaling_functional.py:116:28: C812 missing trailing comma
plone/namedfile/tests/test_scaling_functional.py:146:70: C812 missing trailing comma
plone/namedfile/tests/test_scaling_functional.py:153:76: C812 missing trailing comma
plone/namedfile/tests/test_scaling_functional.py:164:74: C812 missing trailing comma
plone/namedfile/tests/test_scaling_functional.py:197:75: C812 missing trailing comma
plone/namedfile/tests/test_scaling_functional.py:202:78: C812 missing trailing comma

Follow these instructions to reproduce it locally.

Please sign in to comment.