Skip to content

Commit

Permalink
Merge pull request #296 from plone/py3
Browse files Browse the repository at this point in the history
Imports are Python3 compatible
  • Loading branch information
pbauer authored Jan 25, 2018
2 parents ab08f39 + b11a935 commit 1ffe2e8
Show file tree
Hide file tree
Showing 48 changed files with 172 additions and 140 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ New features:
[jensens]

Bug fixes:
- Imports are Python3 compatible
[ale-rt, jensens]

- Fix serialization of query variables for selector links in Zope 4.
[davisagli]
Expand Down
11 changes: 6 additions & 5 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
use the -c option to specify an alternate configuration file.
"""

from optparse import OptionParser

import os
import pkg_resources
import setuptools
import shutil
import subprocess
import sys
import tempfile
import zc.buildout.buildout

from optparse import OptionParser

tmpeggs = tempfile.mkdtemp()

Expand Down Expand Up @@ -96,8 +101,6 @@
setup_args['version'] = options.setuptools_version

ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources

# This does not (always?) update the default working set. We will
# do it.
Expand Down Expand Up @@ -166,7 +169,6 @@ def _final_version(parsed_version):
requirement = '=='.join((requirement, version))
cmd.append(requirement)

import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])
Expand All @@ -176,7 +178,6 @@ def _final_version(parsed_version):

ws.add_entry(tmpeggs)
ws.require(requirement)
import zc.buildout.buildout

if not [a for a in args if '=' not in a]:
args.append('bootstrap')
Expand Down
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
2 changes: 2 additions & 0 deletions src/plone/app/multilingual/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from zope.i18nmessageid import MessageFactory

import logging
import pkg_resources


try:
pkg_resources.get_distribution('Products.LinguaPlone')
except pkg_resources.DistributionNotFound:
Expand Down
10 changes: 5 additions & 5 deletions src/plone/app/multilingual/browser/add.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
from Products.CMFCore.interfaces import IFolderish
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.multilingual.dx.interfaces import ILanguageIndependentField
from plone.app.multilingual.dx.interfaces import IMultilingualAddForm
from Products.CMFPlone.interfaces import ILanguage
from plone.app.multilingual.events import ObjectTranslatedEvent
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.app.multilingual.interfaces import ITG
Expand All @@ -14,12 +10,16 @@
from plone.dexterity.interfaces import IDexterityContent
from plone.registry.interfaces import IRegistry
from plone.z3cform.fieldsets.group import Group
from Products.CMFCore.interfaces import IFolderish
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import ILanguage
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import adapter
from zope.component import getUtility
from zope.component import queryMultiAdapter
from zope.event import notify
from zope.interface import Interface
from zope.interface import implementer
from zope.interface import Interface
from zope.traversing.interfaces import ITraversable
from zope.traversing.interfaces import TraversalError

Expand Down
20 changes: 9 additions & 11 deletions src/plone/app/multilingual/browser/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.statusmessages.interfaces import IStatusMessage
from Products.CMFPlone.controlpanel.browser.language import \
LanguageControlPanelForm
from plone.app.registry.browser import controlpanel

from plone.app.multilingual import isLPinstalled
from plone.app.multilingual.browser.migrator import portal_types_blacklist
from plone.app.multilingual.browser.setup import SetupMultilingualSite
from Products.CMFPlone.interfaces import ILanguage
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.app.registry.browser import controlpanel
from plone.app.uuid.utils import uuidToObject
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.controlpanel.browser.language import LanguageControlPanelForm
from Products.CMFPlone.interfaces import ILanguage
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.statusmessages.interfaces import IStatusMessage
from z3c.form import button
from zc.relation.interfaces import ICatalog as IRelationCatalog
from zope.component import getUtility
from zope.component.interfaces import ComponentLookupError
from zope.i18nmessageid import MessageFactory
from zope.schema.interfaces import IVocabularyFactory
from z3c.form import button


import json


_ = MessageFactory('plone.app.multilingual')


Expand Down
4 changes: 2 additions & 2 deletions src/plone/app/multilingual/browser/edit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.i18n.locales.browser.selector import LanguageSelector
from plone.app.multilingual.browser.selector import LanguageSelectorViewlet
from plone.app.multilingual.dx.interfaces import ILanguageIndependentField
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.dexterity.browser.edit import DefaultEditForm
from plone.registry.interfaces import IRegistry
from plone.z3cform import layout
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getUtility


Expand Down
19 changes: 10 additions & 9 deletions src/plone/app/multilingual/browser/helper_views.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# -*- coding: utf-8 -*-
from AccessControl.SecurityManagement import getSecurityManager
from Acquisition import aq_chain
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.i18n.interfaces import INegotiateLanguage
from borg.localrole.interfaces import IFactoryTempFolder
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.app.multilingual.interfaces import ITG
from plone.app.multilingual.browser.selector import NOT_TRANSLATED_YET_TEMPLATE
from plone.app.multilingual.browser.selector import addQuery
from plone.app.multilingual.browser.selector import NOT_TRANSLATED_YET_TEMPLATE
from plone.app.multilingual.interfaces import ILanguageRootFolder
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.app.multilingual.interfaces import ITG
from plone.app.multilingual.interfaces import ITranslatable
from plone.app.multilingual.interfaces import ITranslationManager
from plone.app.multilingual.manager import TranslationManager
from plone.i18n.interfaces import INegotiateLanguage
from plone.i18n.locales.interfaces import IContentLanguageAvailability
from plone.registry.interfaces import IRegistry
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component.hooks import getSite
Expand All @@ -26,6 +26,7 @@
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound


try:
from Products.ATContentTypes.interfaces.factory import IFactoryTool
except ImportError:
Expand Down Expand Up @@ -167,7 +168,7 @@ def getClosestDestination(self):
if prefered in languages:
context = languages[prefered]
else:
context = languages[languages.keys()[0]]
context = languages[list(languages.keys())[0]]

checkPermission = getSecurityManager().checkPermission
chain = self.getParentChain(context)
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/multilingual/browser/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from zope import schema
from zope.browsermenu.interfaces import IBrowserMenu
from zope.browsermenu.interfaces import IBrowserSubMenuItem
from zope.component.hooks import getSite
from zope.interface import provider
from zope.schema.interfaces import IContextAwareDefaultFactory
from zope.component.hooks import getSite

import pkg_resources

Expand Down
10 changes: 5 additions & 5 deletions src/plone/app/multilingual/browser/menu.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# -*- coding: utf-8 -*-
from AccessControl import getSecurityManager
from Acquisition import aq_parent
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_unicode
from plone.app.multilingual.interfaces import ILanguageRootFolder
from plone.app.multilingual import _
from plone.app.multilingual.browser.interfaces import ITranslateMenu
from plone.app.multilingual.browser.interfaces import ITranslateSubMenuItem
from plone.app.multilingual.browser.utils import is_language_independent
from plone.app.multilingual.browser.vocabularies import translated_languages
from plone.app.multilingual.browser.vocabularies import translated_urls
from plone.app.multilingual.browser.vocabularies import untranslated_languages
from Products.CMFPlone.defaultpage import is_default_page
from Products.CMFPlone.interfaces import ILanguage
from plone.app.multilingual.interfaces import ILanguageRootFolder
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.app.multilingual.interfaces import IPloneAppMultilingualInstalled
from plone.app.multilingual.interfaces import ITG
Expand All @@ -22,6 +18,10 @@
from plone.app.multilingual.permissions import ManageTranslations
from plone.memoize import view
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.defaultpage import is_default_page
from Products.CMFPlone.interfaces import ILanguage
from Products.CMFPlone.utils import safe_unicode
from zope.browsermenu.menu import BrowserMenu
from zope.browsermenu.menu import BrowserSubMenuItem
from zope.component import getUtility
Expand Down
15 changes: 8 additions & 7 deletions src/plone/app/multilingual/browser/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition import aq_parent
from plone.app.multilingual import _
from plone.app.multilingual.content.lrf import LanguageRootFolder
from plone.app.multilingual.interfaces import ITranslationManager
from plone.locking.interfaces import ILockable
from Products.CMFCore.exceptions import ResourceLockedError
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import ILanguage
from Products.CMFPlone.interfaces import IPloneSiteRoot
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.multilingual import _
from plone.app.multilingual.content.lrf import LanguageRootFolder
from Products.CMFPlone.interfaces import ILanguage
from plone.app.multilingual.interfaces import ITranslationManager
from plone.locking.interfaces import ILockable
from zc.relation.interfaces import ICatalog
from zope.component import getUtility
from zope.component.hooks import getSite
from zope.component.interfaces import ComponentLookupError
from zope.interface import Interface

import logging


Expand Down Expand Up @@ -203,7 +204,7 @@ def step1andstep2(self):
'/'.join(content.getPhysicalPath()),
'/'.join(target_folder.getPhysicalPath()))
log = logger.info
except Exception, err:
except Exception as err:
info_str = "ERROR. Step 2: not possible to move " \
"object %s to folder %s. Error: %s" % (
'/'.join(content.getPhysicalPath()),
Expand Down Expand Up @@ -256,7 +257,7 @@ def step3(self):
info_str = "Moved object %s to language root folder "\
"%s" % (old_path, lang)
log = logger.info
except Exception, err:
except Exception as err:
info_str = "ERROR. Step 3: not possible to move "\
"object %s to root language folder %s. Error: %s"\
% (old_path, lang, err)
Expand Down
4 changes: 3 additions & 1 deletion src/plone/app/multilingual/browser/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from z3c.form import button
from z3c.form.form import Form
from zope.component import getUtility

import logging


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -73,7 +75,7 @@ def __call__(self):
manager = ITranslationManager(context)
try:
manager.remove_translation(language)
except Exception, e:
except Exception as e:
messages = IStatusMessage(self.request)
messages.addStatusMessage(e, type='error')

Expand Down
8 changes: 5 additions & 3 deletions src/plone/app/multilingual/browser/selector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from ZTUtils import make_query
from plone.app.i18n.locales.browser.selector import LanguageSelector
from plone.app.multilingual.interfaces import ITG
from plone.app.multilingual.interfaces import NOTG
from zope.component import queryAdapter
from zope.component.hooks import getSite
from ZTUtils import make_query

import six


def addQuery(request, url, exclude=tuple(), **extras):
Expand All @@ -14,12 +16,12 @@ def addQuery(request, url, exclude=tuple(), **extras):
formvariables = {}
for k, v in request.form.items():
if k not in exclude:
if isinstance(v, unicode):
if isinstance(v, six.text_type):
formvariables[k] = v.encode('utf-8')
else:
formvariables[k] = v
for k, v in extras.items():
if isinstance(v, unicode):
if isinstance(v, six.text_type):
formvariables[k] = v.encode('utf-8')
else:
formvariables[k] = v
Expand Down
15 changes: 8 additions & 7 deletions src/plone/app/multilingual/browser/setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import _createObjectByType
from Products.Five import BrowserView
from logging import getLogger
from plone.app.dexterity.behaviors.exclfromnav import IExcludeFromNavigation
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.multilingual.dx.interfaces import IDexterityTranslatable
from Products.CMFPlone.interfaces import ILanguage
from plone.app.multilingual import _
from plone.app.multilingual.dx.interfaces import IDexterityTranslatable
from plone.app.multilingual.interfaces import ITranslatable
from plone.app.multilingual.interfaces import ITranslationManager
from plone.app.multilingual.interfaces import LANGUAGE_INDEPENDENT
from plone.app.multilingual.subscriber import set_recursive_language
from plone.dexterity.interfaces import IDexterityFTI
from plone.i18n.locales.languages import _combinedlanguagelist
from plone.i18n.locales.languages import _languagelist
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import ILanguage
from Products.CMFPlone.utils import _createObjectByType
from Products.Five import BrowserView
from zope.component.hooks import getSite
from zope.event import notify
from zope.i18n import translate
from zope.interface import alsoProvides
from zope.lifecycleevent import modified


logger = getLogger('plone.app.multilingual')


Expand Down Expand Up @@ -95,7 +96,7 @@ def linkTranslations(self):

try:
canonical = ITranslationManager(self.folders[self.defaultLanguage])
except TypeError, e:
except TypeError as e:
raise TypeError(str(e) + u' Are your folders ITranslatable?')

for language in self.languages:
Expand Down Expand Up @@ -234,7 +235,7 @@ def resetDefaultPage(self):

try:
target.manage_pasteObjects(objects)
except ValueError, exc:
except ValueError as exc:
# This portal_type may not be allowed. This should not be
# fatal, so we only log a warning.
logger.warn((u"Could not move default page '{0:s}' j"
Expand Down
Loading

0 comments on commit 1ffe2e8

Please sign in to comment.