Skip to content

Commit

Permalink
fix imports and use decorators for py3
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jun 22, 2018
1 parent fb48b9f commit d773bd9
Show file tree
Hide file tree
Showing 26 changed files with 59 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/plone/restapi/batching.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from plone.batching.batch import Batch
from urllib import urlencode
from urlparse import parse_qsl
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import parse_qsl


DEFAULT_BATCH_SIZE = 25
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class InternalServerErrorView(BrowserView): # pragma: no cover

def __call__(self):
from urllib2 import HTTPError
from six.moves.urllib.error import HTTPError
raise HTTPError(
'http://nohost/plone/internal_server_error',
500,
Expand Down
7 changes: 4 additions & 3 deletions src/plone/restapi/deserializer/dxfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from zope.schema.interfaces import ITimedelta

import dateutil
import six


@implementer(IFieldDeserializer)
Expand All @@ -38,7 +39,7 @@ def __init__(self, field, context, request):
self.request = request

def __call__(self, value):
if not isinstance(value, unicode):
if not isinstance(value, six.text_type):
return value
return IFromUnicode(self.field).fromUnicode(value)

Expand All @@ -48,11 +49,11 @@ def __call__(self, value):
class TextLineFieldDeserializer(DefaultFieldDeserializer):

def __call__(self, value):
if isinstance(value, unicode):
if isinstance(value, six.text_type):
value = IFromUnicode(self.field).fromUnicode(value)

# Mimic what z3c.form does in it's BaseDataConverter.
if isinstance(value, unicode):
if isinstance(value, six.text_type):
value = value.strip()
if value == u'':
value = self.field.missing_value
Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/deserializer/relationfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from zope.interface import implementer
from zope.intid.interfaces import IIntIds
from zope.publisher.interfaces.browser import IBrowserRequest
import six


@implementer(IFieldDeserializer)
Expand All @@ -28,7 +29,7 @@ def __call__(self, value):
# Resolve by intid
intids = queryUtility(IIntIds)
obj = intids.queryObject(value)
elif isinstance(value, basestring):
elif isinstance(value, six.string_types):
portal = getMultiAdapter((self.context, self.request),
name='plone_portal_state').portal()
portal_url = portal.absolute_url()
Expand Down
12 changes: 6 additions & 6 deletions src/plone/restapi/pas/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from plone.keyring.interfaces import IKeyManager
from plone.keyring.keyring import GenerateSecret
from zope.component import getUtility
from zope.interface import implements
from zope.interface import implementer

import jwt
import time
Expand All @@ -39,14 +39,14 @@ def addJWTAuthenticationPlugin(self, id_, title=None, REQUEST=None):
)


@implementer(
IAuthenticationPlugin,
IChallengePlugin,
IExtractionPlugin,
)
class JWTAuthenticationPlugin(BasePlugin):
"""Plone PAS plugin for authentication with JSON web tokens (JWT).
"""
implements(
IAuthenticationPlugin,
IChallengePlugin,
IExtractionPlugin,
)
meta_type = "JWT Authentication Plugin"
security = ClassSecurityInfo()

Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/serializer/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import Missing
import pytz
import six
# import re


Expand Down Expand Up @@ -75,7 +76,7 @@ def default_converter(value):
if value is None:
return value

if type(value) in (unicode, bool, int, float, long):
if type(value) in (six.text_type, bool, int, float, int):
return value

raise TypeError(
Expand Down
7 changes: 3 additions & 4 deletions src/plone/restapi/services/content/tus.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from uuid import uuid4
from zExceptions import Unauthorized
from zope.component import queryMultiAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces import NotFound

Expand Down Expand Up @@ -121,8 +121,8 @@ def reply(self):
return super(UploadPost, self).reply()


@implementer(IPublishTraverse)
class UploadFileBase(TUSBaseService):
implements(IPublishTraverse)

def __init__(self, context, request):
super(UploadFileBase, self).__init__(context, request)
Expand Down Expand Up @@ -181,11 +181,10 @@ def reply(self):
return super(UploadHead, self).reply()


@implementer(IPublishTraverse)
class UploadPatch(UploadFileBase):
"""TUS upload endpoint for handling PATCH requests"""

implements(IPublishTraverse)

def reply(self):

tus_upload = self.tus_upload()
Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/services/copymove/copymove.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from zope.security import checkPermission

import plone
import six


class BaseCopyMove(Service):
Expand All @@ -24,7 +25,7 @@ def __init__(self, context, request):

def get_object(self, key):
"""Get an object by url, path or UID."""
if isinstance(key, basestring):
if isinstance(key, six.string_types):
if key.startswith(self.portal_url):
# Resolve by URL
return self.portal.restrictedTraverse(
Expand Down
8 changes: 4 additions & 4 deletions src/plone/restapi/services/discussion/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CommentsGet(Service):

def publishTraverse(self, request, name):
if name:
self.comment_id = long(name)
self.comment_id = int(name)
return self

def reply(self):
Expand All @@ -64,7 +64,7 @@ class CommentsAdd(Service):

def publishTraverse(self, request, name):
if name:
self.comment_id = long(name)
self.comment_id = int(name)
request['form.widgets.in_reply_to'] = name
return self

Expand Down Expand Up @@ -104,7 +104,7 @@ class CommentsUpdate(Service):

def publishTraverse(self, request, name):
if name:
self.comment_id = long(name)
self.comment_id = int(name)
request['form.widgets.comment_id'] = name
return self

Expand Down Expand Up @@ -148,7 +148,7 @@ class CommentsDelete(Service):
comment_id = None

def publishTraverse(self, request, name):
self.comment_id = long(name)
self.comment_id = int(name)
return self

def reply(self):
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/services/email_send/post.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from AccessControl import getSecurityManager
from AccessControl.Permissions import use_mailhost_services
from email.MIMEText import MIMEText
from email.mime.text import MIMEText
from plone.registry.interfaces import IRegistry
from plone.restapi import _
from plone.restapi.deserializer import json_body
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/groups/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
from Products.CMFCore.utils import getToolByName
from zExceptions import NotFound
from zope.component.hooks import getSite
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse


@implementer(IPublishTraverse)
class GroupsDelete(Service):
"""Deletes a user.
"""

implements(IPublishTraverse)

def __init__(self, context, request):
super(GroupsDelete, self).__init__(context, request)
self.params = []
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/groups/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from zExceptions import BadRequest
from zope.component.hooks import getSite
from zope.component import queryMultiAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse

DEFAULT_SEARCH_RESULTS_LIMIT = 25


@implementer(IPublishTraverse)
class GroupsGet(Service):

implements(IPublishTraverse)

def __init__(self, context, request):
super(GroupsGet, self).__init__(context, request)
self.params = []
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/groups/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
from Products.CMFCore.utils import getToolByName
from zExceptions import BadRequest
from zope.component.hooks import getSite
from zope.interface import alsoProvides, implements
from zope.interface import alsoProvides, implementer
from zope.publisher.interfaces import IPublishTraverse

import plone


@implementer(IPublishTraverse)
class GroupsPatch(Service):
"""Updates an existing group.
"""

implements(IPublishTraverse)

def __init__(self, context, request):
super(GroupsPatch, self).__init__(context, request)
self.params = []
Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/services/history/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from zope.publisher.interfaces import IPublishTraverse

from datetime import datetime as dt
import six


@implementer(IPublishTraverse)
Expand Down Expand Up @@ -74,7 +75,7 @@ def reply(self):

# Versioning entries use a timestamp,
# workflow ISO formatted string
if not isinstance(item['time'], basestring):
if not isinstance(item['time'], six.string_types):
item['time'] = dt.fromtimestamp(item['time']).isoformat()

# The create event has an empty 'action', but we like it to say
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/registry/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from plone.registry.interfaces import IRegistry
from plone.restapi.services import Service
from zope.component import getUtility, getMultiAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from plone.restapi.interfaces import ISerializeToJson


@implementer(IPublishTraverse)
class RegistryGet(Service):

implements(IPublishTraverse)

def __init__(self, context, request):
super(RegistryGet, self).__init__(context, request)
self.params = []
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/services/types/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from zExceptions import Unauthorized
from zope.component import getUtility
from zope.component import getMultiAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from zope.schema.interfaces import IVocabularyFactory


@implementer(IPublishTraverse)
class TypesGet(Service):

implements(IPublishTraverse)

def __init__(self, context, request):
super(TypesGet, self).__init__(context, request)
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/users/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from zope.component import queryMultiAdapter
from zope.component.hooks import getSite
from zope.interface import alsoProvides
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse

import plone.protect.interfaces
Expand All @@ -32,12 +32,11 @@
from Products.PasswordResetTool.PasswordResetTool import InvalidRequestError # noqa


@implementer(IPublishTraverse)
class UsersPost(Service):
"""Creates a new user.
"""

implements(IPublishTraverse)

def __init__(self, context, request):
super(UsersPost, self).__init__(context, request)
self.params = []
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/users/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from plone.restapi.services import Service
from Products.CMFCore.utils import getToolByName
from zope.component.hooks import getSite
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse


@implementer(IPublishTraverse)
class UsersDelete(Service):
"""Deletes a user.
"""

implements(IPublishTraverse)

def __init__(self, context, request):
super(UsersDelete, self).__init__(context, request)
self.params = []
Expand Down
5 changes: 2 additions & 3 deletions src/plone/restapi/services/users/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from zExceptions import BadRequest
from zope.component.hooks import getSite
from zope.component import queryMultiAdapter
from zope.interface import implements
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse

DEFAULT_SEARCH_RESULTS_LIMIT = 25


@implementer(IPublishTraverse)
class UsersGet(Service):

implements(IPublishTraverse)

def __init__(self, context, request):
super(UsersGet, self).__init__(context, request)
self.params = []
Expand Down
Loading

0 comments on commit d773bd9

Please sign in to comment.