Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 2 / 3 compatibility #22

Merged
merged 2 commits into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Breaking changes:

New features:

- *add item here*
- Add python 2 / 3 compatibility

Bug fixes:

Expand Down
22 changes: 13 additions & 9 deletions plone/resource/directory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base, aq_parent
import os.path
import re
import zipfile

import six
from Acquisition import aq_base
from Acquisition import aq_parent
from OFS.Image import File
from OFS.interfaces import IObjectManager
from plone.resource.events import PloneResourceCreatedEvent
Expand All @@ -9,15 +15,13 @@
from plone.resource.interfaces import IWritableResourceDirectory
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from Products.CMFCore.utils import getToolByName
from StringIO import StringIO
from six import StringIO
from zExceptions import Forbidden
from zExceptions import NotFound
from zope.event import notify
from zope.interface import implementer
from zope.site.hooks import getSite
import os.path
import re
import zipfile


# filter dot files, Mac resource forks
FILTERS = (r'\..*', '__MACOSX')
Expand Down Expand Up @@ -46,7 +50,7 @@ def __repr__(self):
'/'.join(self.context.getPhysicalPath()))

def publishTraverse(self, request, name):
if isinstance(name, unicode):
if isinstance(name, six.text_type):
name = name.encode('utf-8')

context = self.context
Expand All @@ -70,7 +74,7 @@ def __getitem__(self, name):
return self.publishTraverse(None, name)

def __setitem__(self, name, item):
if isinstance(name, unicode):
if isinstance(name, six.text_type):
name = name.encode('utf-8')

if IResourceDirectory.providedBy(item):
Expand Down Expand Up @@ -142,7 +146,7 @@ def makeDirectory(self, path):
names = path.strip('/').split('/')
for name in names:
if name not in parent:
if isinstance(name, unicode):
if isinstance(name, six.text_type):
name = name.encode('utf-8')
f = BTreeFolder2(name)
parent._setOb(name, f)
Expand All @@ -153,7 +157,7 @@ def writeFile(self, path, data):
if basepath:
self.makeDirectory(basepath)
filename = path.split('/')[-1]
if isinstance(filename, unicode):
if isinstance(filename, six.text_type):
filename = filename.encode('utf-8')
f = File(filename, filename, data)
ct = f.getContentType()
Expand Down
2 changes: 1 addition & 1 deletion plone/resource/download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from StringIO import StringIO
from six import StringIO
from zope.publisher.browser import BrowserView


Expand Down
6 changes: 4 additions & 2 deletions plone/resource/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
``bar``. ``title`` and ``description`` will be ``None`` if not found in the
manifest. ``bar`` will be ``baz`` if not found.
"""
from ConfigParser import SafeConfigParser
import logging

from plone.resource.directory import FILTERS
from plone.resource.interfaces import IResourceDirectory
from plone.resource.utils import iterDirectoriesOfType
from six.moves.configparser import SafeConfigParser
from zope.component import getUtility
import logging


MANIFEST_FILENAME = 'manifest.cfg'

Expand Down
11 changes: 5 additions & 6 deletions plone/resource/tests/test_zcml.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-
import os.path
import unittest

from plone.resource.interfaces import IResourceDirectory
from StringIO import StringIO
from six import StringIO
from zope.component import getUtility
from zope.component.testing import tearDown
from zope.configuration.exceptions import ConfigurationError
from zope.configuration.xmlconfig import xmlconfig
from zope.configuration.xmlconfig import XMLConfig

import os.path
import unittest
from zope.configuration.xmlconfig import XMLConfig, xmlconfig


def clearZCML(test=None):
Expand Down
10 changes: 5 additions & 5 deletions plone/resource/tests/test_zip_download.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# -*- coding: utf-8 -*-
import os.path
import unittest
import zipfile

from OFS.Image import File
from plone.resource.directory import FilesystemResourceDirectory
from plone.resource.directory import PersistentResourceDirectory
from plone.resource.interfaces import IResourceDirectory
from plone.resource.testing import DEMO_TRAVERSER_INTEGRATION_TESTING
from plone.testing import zca
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from StringIO import StringIO
from six import StringIO
from zope.component import provideUtility

import os.path
import unittest
import zipfile


base_path = os.path.dirname(__file__)
test_dir_path = os.path.join(base_path, 'resources')
Expand Down
4 changes: 2 additions & 2 deletions plone/resource/traversal.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from plone.resource.interfaces import IUniqueResourceRequest
from plone.resource.utils import queryResourceDirectory
from six.moves import urllib
from zExceptions import NotFound
from zope.interface import alsoProvides
from zope.traversing.namespace import SimpleHandler
import urllib


class ResourceTraverser(SimpleHandler):
Expand All @@ -18,7 +18,7 @@ def traverse(self, name, remaining):
_type = self.name

# Note: also fixes possible unicode problems
name = urllib.quote(name)
name = urllib.parse.quote(name)

res = queryResourceDirectory(_type, name)
if res is not None:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'zope.schema',
'zope.traversing',
'Zope2',
'six',
],
extras_require={
'test': test_requires,
Expand Down