Skip to content

Commit

Permalink
pyupgrade --py37-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Jul 1, 2022
1 parent 67c95d9 commit 9710090
Show file tree
Hide file tree
Showing 40 changed files with 109 additions and 178 deletions.
1 change: 0 additions & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__import__("pkg_resources").declare_namespace(__name__)
1 change: 0 additions & 1 deletion plone/dexterity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
# Kick dynamic module factory
from . import schema # noqa
3 changes: 1 addition & 2 deletions plone/dexterity/bbb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import zope.deferredimport


Expand All @@ -20,7 +19,7 @@
NullResource = None


class Resource(object):
class Resource:
def dav__init(self, request, response):
pass

Expand Down
6 changes: 2 additions & 4 deletions plone/dexterity/behavior.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.behavior.interfaces import IBehaviorAssignable
from plone.dexterity.interfaces import IDexterityContent
from plone.dexterity.schema import SCHEMA_CACHE
Expand All @@ -8,7 +7,7 @@

@implementer(IBehaviorAssignable)
@adapter(IDexterityContent)
class DexterityBehaviorAssignable(object):
class DexterityBehaviorAssignable:
"""Support plone.behavior behaviors stored in the FTI"""

def __init__(self, context):
Expand All @@ -21,5 +20,4 @@ def supports(self, behavior_interface):
return False

def enumerateBehaviors(self):
for behavior in SCHEMA_CACHE.behavior_registrations(self.context.portal_type):
yield behavior
yield from SCHEMA_CACHE.behavior_registrations(self.context.portal_type)
1 change: 0 additions & 1 deletion plone/dexterity/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
9 changes: 4 additions & 5 deletions plone/dexterity/browser/add.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition.interfaces import IAcquirer
Expand Down Expand Up @@ -40,7 +39,7 @@ class DefaultAddForm(DexterityExtensibleForm, form.AddForm):
success_message = _("Item created")

def __init__(self, context, request, ti=None):
super(DefaultAddForm, self).__init__(context, request)
super().__init__(context, request)
if ti is not None:
self.ti = ti
self.portal_type = ti.getId()
Expand Down Expand Up @@ -135,13 +134,13 @@ def update(self):
"Subobject type disallowed by IConstrainTypes adapter: %s"
% self.portal_type
)
super(DefaultAddForm, self).update()
super().update()
# fire the edit begun only if no action was executed
if len(self.actions.executedActions) == 0:
notify(AddBegunEvent(self.context))

def updateActions(self):
super(DefaultAddForm, self).updateActions()
super().updateActions()
if "save" in self.actions:
self.actions["save"].addClass("context")

Expand All @@ -168,7 +167,7 @@ class DefaultAddView(layout.FormWrapper, BrowserPage):
form = DefaultAddForm

def __init__(self, context, request, ti):
super(DefaultAddView, self).__init__(context, request)
super().__init__(context, request)
self.ti = ti

# Set portal_type name on newly created form instance
Expand Down
1 change: 0 additions & 1 deletion plone/dexterity/browser/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.autoform.form import AutoExtensibleForm
from plone.dexterity.i18n import MessageFactory as _
from plone.dexterity.interfaces import IDexterityFTI
Expand Down
5 changes: 2 additions & 3 deletions plone/dexterity/browser/edit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.dexterity.browser.base import DexterityExtensibleForm
from plone.dexterity.events import EditBegunEvent
from plone.dexterity.events import EditCancelledEvent
Expand Down Expand Up @@ -51,14 +50,14 @@ def nextURL(self):

def update(self):
self.portal_type = self.context.portal_type
super(DefaultEditForm, self).update()
super().update()

# fire the edit begun only if no action was executed
if len(self.actions.executedActions) == 0:
notify(EditBegunEvent(self.context))

def updateActions(self):
super(DefaultEditForm, self).updateActions()
super().updateActions()

if "save" in self.actions:
self.actions["save"].addClass("context")
Expand Down
1 change: 0 additions & 1 deletion plone/dexterity/browser/fti.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.dexterity.fti import DexterityFTI
from Products.CMFCore.browser.typeinfo import FactoryTypeInformationAddView

Expand Down
5 changes: 2 additions & 3 deletions plone/dexterity/browser/traversal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from Acquisition import aq_parent
from Acquisition.interfaces import IAcquirer
Expand Down Expand Up @@ -48,7 +47,7 @@ def publishTraverse(self, request, name):
):
return FolderDataResource(DAV_FOLDER_DATA_ID, context).__of__(context)

defaultTraversal = super(DexterityPublishTraverse, self).publishTraverse(
defaultTraversal = super().publishTraverse(
request, name
)

Expand Down Expand Up @@ -85,4 +84,4 @@ def browserDefault(self, request):
):
return self.context, ()

return super(DexterityPublishTraverse, self).browserDefault(request)
return super().browserDefault(request)
1 change: 0 additions & 1 deletion plone/dexterity/browser/view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.autoform.view import WidgetsView
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.utils import getAdditionalSchemata
Expand Down
27 changes: 13 additions & 14 deletions plone/dexterity/content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager
from AccessControl import Permissions as acpermissions
Expand Down Expand Up @@ -233,7 +232,7 @@ def __call__(self, name, value):
return 0


class PasteBehaviourMixin(object):
class PasteBehaviourMixin:
def _notifyOfCopyTo(self, container, op=0):
"""Keep Archetypes' reference info internally when op == 1 (move)
because in those cases we need to keep Archetypes' refeferences.
Expand Down Expand Up @@ -270,7 +269,7 @@ def _verifyObjectPaste(self, obj, validate_src=True):
# Products.CMFCore.PortalFolder.PortalFolderBase (permission checks and
# allowed content types) to also ask the FTI if construction is
# allowed.
super(PasteBehaviourMixin, self)._verifyObjectPaste(obj, validate_src)
super()._verifyObjectPaste(obj, validate_src)
if validate_src:
portal_type = getattr(aq_base(obj), "portal_type", None)
if portal_type:
Expand All @@ -287,7 +286,7 @@ def _getCopy(self, container):
# Copied from Products.Archetypes.Referenceable.Referenceable._getCopy
is_cp_flag = getattr(self, "_v_is_cp", None)
cp_refs_flag = getattr(self, "_v_cp_refs", None)
ob = super(PasteBehaviourMixin, self)._getCopy(container)
ob = super()._getCopy(container)
if is_cp_flag:
setattr(ob, "_v_is_cp", is_cp_flag)
if cp_refs_flag:
Expand Down Expand Up @@ -416,7 +415,7 @@ def _get__name__(self):
return self.id

def _set__name__(self, value):
if six.PY2 and isinstance(value, six.text_type):
if six.PY2 and isinstance(value, str):
value = str(value) # may throw, but id must be ASCII in py2
self.id = value

Expand Down Expand Up @@ -463,7 +462,7 @@ def setModificationDate(self, modification_date=None):
@security.protected(permissions.View)
def Title(self):
# this is a CMF accessor, so should return utf8-encoded
if six.PY2 and isinstance(self.title, six.text_type):
if six.PY2 and isinstance(self.title, str):
return self.title.encode("utf-8")
return self.title or ""

Expand All @@ -478,7 +477,7 @@ def Description(self):
value = value.replace("\r\n", " ").replace("\r", " ").replace("\n", " ") # noqa

# this is a CMF accessor, so should return utf8-encoded
if six.PY2 and isinstance(value, six.text_type):
if six.PY2 and isinstance(value, str):
value = value.encode("utf-8")

return value
Expand Down Expand Up @@ -658,21 +657,21 @@ def setDescription(self, description):
@security.protected(permissions.ModifyPortalContent)
def setCreators(self, creators):
# Set Dublin Core Creator elements - resource authors.
if isinstance(creators, six.string_types):
if isinstance(creators, str):
creators = [creators]
self.creators = tuple(safe_unicode(c.strip()) for c in creators)

@security.protected(permissions.ModifyPortalContent)
def setSubject(self, subject):
# Set Dublin Core Subject element - resource keywords.
if isinstance(subject, six.string_types):
if isinstance(subject, str):
subject = [subject]
self.subject = tuple(safe_unicode(s.strip()) for s in subject)

@security.protected(permissions.ModifyPortalContent)
def setContributors(self, contributors):
# Set Dublin Core Contributor elements - resource collaborators.
if isinstance(contributors, six.string_types):
if isinstance(contributors, str):
contributors = contributors.split(";")
self.contributors = tuple(safe_unicode(c.strip()) for c in contributors)

Expand Down Expand Up @@ -785,15 +784,15 @@ def manage_delObjects(self, ids=None, REQUEST=None):
"""
if ids is None:
ids = []
if isinstance(ids, six.string_types):
if isinstance(ids, str):
ids = [ids]
for id in ids:
item = self._getOb(id)
if not getSecurityManager().checkPermission(
permissions.DeleteObjects, item
):
raise Unauthorized("Do not have permissions to remove this object")
return super(Container, self).manage_delObjects(ids, REQUEST=REQUEST)
return super().manage_delObjects(ids, REQUEST=REQUEST)

# override PortalFolder's allowedContentTypes to respect IConstrainTypes
# adapters
Expand All @@ -803,7 +802,7 @@ def allowedContentTypes(self, context=None):

constrains = IConstrainTypes(context, None)
if not constrains:
return super(Container, self).allowedContentTypes()
return super().allowedContentTypes()

return constrains.allowedContentTypes()

Expand All @@ -827,7 +826,7 @@ def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
% type_name
)

return super(Container, self).invokeFactory(
return super().invokeFactory(
type_name, id, RESPONSE, *args, **kw
)

Expand Down
1 change: 0 additions & 1 deletion plone/dexterity/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.dexterity import interfaces
from zope.interface import implementer
from zope.interface.interfaces import ObjectEvent
Expand Down
7 changes: 3 additions & 4 deletions plone/dexterity/exportimport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from csv import reader
from csv import writer
from Products.GenericSetup.content import _globtest
Expand Down Expand Up @@ -47,7 +46,7 @@ def export(self, export_context, subdir, root=False):
context = self.context

if not root:
subdir = "%s/%s" % (subdir, context.getId())
subdir = "{}/{}".format(subdir, context.getId())

exportable = self.listExportableItems()

Expand Down Expand Up @@ -89,7 +88,7 @@ def import_(self, import_context, subdir, root=False):
"""See IFilesystemImporter."""
context = self.context
if not root:
subdir = "%s/%s" % (subdir, context.getId())
subdir = "{}/{}".format(subdir, context.getId())

data = import_context.readDataFile(".data", subdir)
if data is not None:
Expand Down Expand Up @@ -139,7 +138,7 @@ def import_(self, import_context, subdir, root=False):
if object is None:
logger = import_context.getLogger("SFWA")
logger.warning(
"Couldn't make instance: %s/%s" % (subdir, object_id)
"Couldn't make instance: {}/{}".format(subdir, object_id)
)
continue

Expand Down
3 changes: 1 addition & 2 deletions plone/dexterity/factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from persistent import Persistent
from plone.dexterity.interfaces import IDexterityFactory
from plone.dexterity.interfaces import IDexterityFTI
Expand Down Expand Up @@ -58,4 +57,4 @@ def getInterfaces(self):
return spec

def __repr__(self):
return "<%s for %s>" % (self.__class__.__name__, self.portal_type)
return "<{} for {}>".format(self.__class__.__name__, self.portal_type)
Loading

0 comments on commit 9710090

Please sign in to comment.