diff --git a/plone/__init__.py b/plone/__init__.py index 03d08ff..5284146 100644 --- a/plone/__init__.py +++ b/plone/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- __import__("pkg_resources").declare_namespace(__name__) diff --git a/plone/dexterity/__init__.py b/plone/dexterity/__init__.py index cfa51cd..1cbc5de 100644 --- a/plone/dexterity/__init__.py +++ b/plone/dexterity/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- # Kick dynamic module factory from . import schema # noqa diff --git a/plone/dexterity/bbb.py b/plone/dexterity/bbb.py index 9b3770e..e9983aa 100644 --- a/plone/dexterity/bbb.py +++ b/plone/dexterity/bbb.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import zope.deferredimport @@ -20,7 +19,7 @@ NullResource = None -class Resource(object): +class Resource: def dav__init(self, request, response): pass diff --git a/plone/dexterity/behavior.py b/plone/dexterity/behavior.py index bf015f3..4521738 100644 --- a/plone/dexterity/behavior.py +++ b/plone/dexterity/behavior.py @@ -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 @@ -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): @@ -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) diff --git a/plone/dexterity/browser/__init__.py b/plone/dexterity/browser/__init__.py index 40a96af..e69de29 100644 --- a/plone/dexterity/browser/__init__.py +++ b/plone/dexterity/browser/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/plone/dexterity/browser/add.py b/plone/dexterity/browser/add.py index 7700833..d29e14d 100644 --- a/plone/dexterity/browser/add.py +++ b/plone/dexterity/browser/add.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from Acquisition import aq_base from Acquisition import aq_inner from Acquisition.interfaces import IAcquirer @@ -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() @@ -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") @@ -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 diff --git a/plone/dexterity/browser/base.py b/plone/dexterity/browser/base.py index 1558516..d057fed 100644 --- a/plone/dexterity/browser/base.py +++ b/plone/dexterity/browser/base.py @@ -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 diff --git a/plone/dexterity/browser/edit.py b/plone/dexterity/browser/edit.py index c32d898..096819d 100644 --- a/plone/dexterity/browser/edit.py +++ b/plone/dexterity/browser/edit.py @@ -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 @@ -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") diff --git a/plone/dexterity/browser/fti.py b/plone/dexterity/browser/fti.py index 35fe812..93062f4 100644 --- a/plone/dexterity/browser/fti.py +++ b/plone/dexterity/browser/fti.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.dexterity.fti import DexterityFTI from Products.CMFCore.browser.typeinfo import FactoryTypeInformationAddView diff --git a/plone/dexterity/browser/traversal.py b/plone/dexterity/browser/traversal.py index 0487ea5..02c70b1 100644 --- a/plone/dexterity/browser/traversal.py +++ b/plone/dexterity/browser/traversal.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from Acquisition import aq_inner from Acquisition import aq_parent from Acquisition.interfaces import IAcquirer @@ -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 ) @@ -85,4 +84,4 @@ def browserDefault(self, request): ): return self.context, () - return super(DexterityPublishTraverse, self).browserDefault(request) + return super().browserDefault(request) diff --git a/plone/dexterity/browser/view.py b/plone/dexterity/browser/view.py index deed522..ad90ac5 100644 --- a/plone/dexterity/browser/view.py +++ b/plone/dexterity/browser/view.py @@ -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 diff --git a/plone/dexterity/content.py b/plone/dexterity/content.py index 969fa9b..be4d7fb 100644 --- a/plone/dexterity/content.py +++ b/plone/dexterity/content.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from AccessControl import ClassSecurityInfo from AccessControl import getSecurityManager from AccessControl import Permissions as acpermissions @@ -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. @@ -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: @@ -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: @@ -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 @@ -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 "" @@ -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 @@ -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) @@ -785,7 +784,7 @@ 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) @@ -793,7 +792,7 @@ def manage_delObjects(self, ids=None, REQUEST=None): 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 @@ -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() @@ -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 ) diff --git a/plone/dexterity/events.py b/plone/dexterity/events.py index 81e08bd..67932c9 100644 --- a/plone/dexterity/events.py +++ b/plone/dexterity/events.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.dexterity import interfaces from zope.interface import implementer from zope.interface.interfaces import ObjectEvent diff --git a/plone/dexterity/exportimport.py b/plone/dexterity/exportimport.py index ee39472..8911b8c 100644 --- a/plone/dexterity/exportimport.py +++ b/plone/dexterity/exportimport.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from csv import reader from csv import writer from Products.GenericSetup.content import _globtest @@ -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() @@ -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: @@ -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 diff --git a/plone/dexterity/factory.py b/plone/dexterity/factory.py index e0d0d29..fc87b38 100644 --- a/plone/dexterity/factory.py +++ b/plone/dexterity/factory.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from persistent import Persistent from plone.dexterity.interfaces import IDexterityFactory from plone.dexterity.interfaces import IDexterityFTI @@ -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) diff --git a/plone/dexterity/filerepresentation.py b/plone/dexterity/filerepresentation.py index d4a5f87..3ea6075 100644 --- a/plone/dexterity/filerepresentation.py +++ b/plone/dexterity/filerepresentation.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from AccessControl import ClassSecurityInfo from AccessControl.class_init import InitializeClass from Acquisition import aq_base @@ -43,7 +42,7 @@ Resource = bbb.Resource -class DAVResourceMixin(object): +class DAVResourceMixin: """Mixin class for WebDAV resource support. The main purpose of this class is to implement the Zope 2 WebDAV API to @@ -235,7 +234,7 @@ def listDAVObjects(self): We add a non-folderish pseudo object which contains the "body" data for this container. """ - parentList = super(DAVCollectionMixin, self).listDAVObjects() + parentList = super().listDAVObjects() if not parentList: parentList = [] else: @@ -329,7 +328,7 @@ def PROPFIND(self, REQUEST, RESPONSE): Certain things may be acquired, notably .propertysheets """ - return super(FolderDataResource, self).PROPFIND(REQUEST, RESPONSE) + return super().PROPFIND(REQUEST, RESPONSE) @security.protected(permissions.ModifyPortalContent) def PROPPATCH(self, REQUEST, RESPONSE): @@ -338,7 +337,7 @@ def PROPPATCH(self, REQUEST, RESPONSE): Certain things may be acquired, notably .propertysheets """ - return super(FolderDataResource, self).PROPPATCH(REQUEST, RESPONSE) + return super().PROPPATCH(REQUEST, RESPONSE) @security.protected(permissions.ModifyPortalContent) def LOCK(self, REQUEST, RESPONSE): @@ -395,7 +394,7 @@ def listDAVObjects(self): @implementer(IStreamIterator) -class StringStreamIterator(object): +class StringStreamIterator: """Simple stream iterator to allow efficient data streaming.""" def __init__(self, data, size=None, chunk=1 << 16): @@ -436,7 +435,7 @@ def __len__(self): @implementer(IDirectoryFactory) @adapter(IDexterityContainer) -class DefaultDirectoryFactory(object): +class DefaultDirectoryFactory: """Default directory factory, invoked when an FTP/WebDAV operation attempts to create a new folder via a MKCOL request. @@ -452,7 +451,7 @@ def __call__(self, name): @implementer(IFileFactory) @adapter(IDexterityContainer) -class DefaultFileFactory(object): +class DefaultFileFactory: """Default file factory, invoked when an FTP/WebDAV operation attempts to create a new resource via a PUT request. @@ -534,7 +533,7 @@ def __call__(self, name, contentType, data): @implementer(IRawReadFile) -class ReadFileBase(object): +class ReadFileBase: """Convenience base class for read files which delegate to another stream type (e.g. a temporary file or StringIO) @@ -672,10 +671,7 @@ def _getStream(self): # transaction is closed message = self._getMessage() out = tempfile.TemporaryFile(mode="w+b") - if six.PY2: - out.write(message.as_string()) - else: - out.write(message.as_string().encode("utf-8")) + out.write(message.as_string().encode("utf-8")) self._size = out.tell() out.seek(0) return out @@ -686,7 +682,7 @@ def __next__(self): @implementer(IRawWriteFile) -class WriteFileBase(object): +class WriteFileBase: """Convenience base class for write files which delegate to another stream, e.g. a file or StringIO. @@ -748,7 +744,7 @@ def _getStream(self): @implementer(IRawWriteFile) @adapter(IDexterityContent) -class DefaultWriteFile(object): +class DefaultWriteFile: """IRawWriteFile file adapter for Dexterity objects. Uses RFC822 marshaler. @@ -818,7 +814,7 @@ def close(self): def write(self, data): if self._closed: raise ValueError("File is closed") - if isinstance(data, six.text_type): + if isinstance(data, str): data = data.encode() self._written += len(data) self._parser.feed(data) diff --git a/plone/dexterity/fti.py b/plone/dexterity/fti.py index db13166..ace851b 100644 --- a/plone/dexterity/fti.py +++ b/plone/dexterity/fti.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from AccessControl import getSecurityManager from Acquisition import aq_base from plone.dexterity import utils @@ -51,7 +50,7 @@ def get_suffix(fti): @implementer(IDexterityFTIModificationDescription) -class DexterityFTIModificationDescription(object): +class DexterityFTIModificationDescription: def __init__(self, attribute, oldValue): self.attribute = attribute self.oldValue = oldValue @@ -163,7 +162,7 @@ class DexterityFTI(base.DynamicViewTypeInformation): schema_policy = "dexterity" def __init__(self, *args, **kwargs): - super(DexterityFTI, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) if "aliases" not in kwargs: self.setMethodAliases(self.default_aliases) @@ -215,13 +214,7 @@ def __init__(self, *args, **kwargs): def Title(self): if self.title and self.i18n_domain: - if six.PY2: - try: - return Message(self.title.decode("utf8"), self.i18n_domain) - except UnicodeDecodeError: - return Message(self.title.decode("latin-1"), self.i18n_domain) - else: - return Message(self.title, self.i18n_domain) + return Message(self.title, self.i18n_domain) else: if six.PY2: if self.title: @@ -231,13 +224,7 @@ def Title(self): def Description(self): if self.description and self.i18n_domain: - if six.PY2: - try: - return Message(self.description.decode("utf8"), self.i18n_domain) - except UnicodeDecodeError: - return Message(self.description.decode("latin-1"), self.i18n_domain) - else: - return Message(self.description, self.i18n_domain) + return Message(self.description, self.i18n_domain) else: if six.PY2 and self.description: return self.description.decode("utf8") @@ -311,7 +298,7 @@ def _updateProperty(self, id, value): """ oldValue = getattr(self, id, None) - super(DexterityFTI, self)._updateProperty(id, value) + super()._updateProperty(id, value) new_value = getattr(self, id, None) if oldValue != new_value: diff --git a/plone/dexterity/i18n.py b/plone/dexterity/i18n.py index fe387f4..fa171bb 100644 --- a/plone/dexterity/i18n.py +++ b/plone/dexterity/i18n.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import zope.i18nmessageid diff --git a/plone/dexterity/interfaces.py b/plone/dexterity/interfaces.py index 66977de..b4e134c 100644 --- a/plone/dexterity/interfaces.py +++ b/plone/dexterity/interfaces.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from Products.CMFCore.interfaces import ITypeInformation from zope.component.interfaces import IFactory from zope.interface import Attribute diff --git a/plone/dexterity/primary.py b/plone/dexterity/primary.py index 759d530..3e98ffe 100644 --- a/plone/dexterity/primary.py +++ b/plone/dexterity/primary.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.dexterity.interfaces import IDexterityContent from plone.dexterity.utils import iterSchemata from plone.rfc822.interfaces import IPrimaryField @@ -10,7 +9,7 @@ @implementer(IPrimaryFieldInfo) @adapter(IDexterityContent) -class PrimaryFieldInfo(object): +class PrimaryFieldInfo: def __init__(self, context): self.context = context primary = None diff --git a/plone/dexterity/schema.py b/plone/dexterity/schema.py index d372dc8..f3747c5 100644 --- a/plone/dexterity/schema.py +++ b/plone/dexterity/schema.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .interfaces import IContentType from .interfaces import IDexterityFTI from .interfaces import IDexteritySchema @@ -55,7 +54,7 @@ def invalidate_cache(fti): def lookup_fti(portal_type, cache=True): # if its a string lookup fti - if isinstance(portal_type, six.string_types): + if isinstance(portal_type, str): # looking up a utility is expensive, using the global request as # cache is twice as fast if cache: @@ -80,7 +79,7 @@ def lookup_fti(portal_type, cache=True): return portal_type raise ValueError( "portal_type has to either string or IDexterityFTI instance but is " - "{0!r}".format(portal_type) + "{!r}".format(portal_type) ) @@ -117,7 +116,7 @@ def decorator(self, portal_type): return decorator -class SchemaCache(object): +class SchemaCache: """Simple schema cache for FTI based schema information. This cache will store a Python object reference to the schema, as returned @@ -176,8 +175,8 @@ def behavior_registrations(self, fti): if registration is None: # BBB - this case should be deprecated in v 3.0 warnings.warn( - 'No behavior registration found for behavior named "{0}"' - ' for factory "{1}"' + 'No behavior registration found for behavior named "{}"' + ' for factory "{}"' " - trying deprecated fallback lookup (will be removed " 'in 3.0)..."'.format(behavior_name, fti.getId()), DeprecationWarning, @@ -186,7 +185,7 @@ def behavior_registrations(self, fti): schema_interface = resolve(behavior_name) except (ValueError, ImportError): log.error( - "Error resolving behavior {0} for factory {1}".format( + "Error resolving behavior {} for factory {}".format( behavior_name, fti.getId() ) ) @@ -278,7 +277,7 @@ def modified(self, fti): @implementer(ISchemaInvalidatedEvent) -class SchemaInvalidatedEvent(object): +class SchemaInvalidatedEvent: def __init__(self, portal_type): self.portal_type = portal_type @@ -292,7 +291,7 @@ def invalidate_schema(event): # here starts the code dealing wih dynamic schemas. -class SchemaNameEncoder(object): +class SchemaNameEncoder: """Schema name encoding""" key = ( @@ -358,7 +357,7 @@ def splitSchemaName(schemaName): # Dynamic module factory @implementer(IDynamicObjectFactory) -class SchemaModuleFactory(object): +class SchemaModuleFactory: """Create dynamic schema interfaces on the fly""" lock = RLock() @@ -422,7 +421,7 @@ def __call__(self, name, module): @implementer(ISchemaPolicy) -class DexteritySchemaPolicy(object): +class DexteritySchemaPolicy: """Determines how and where imported dynamic interfaces are created. Note that these schemata are never used directly. Rather, they are merged into a schema with a proper name and module, either dynamically or diff --git a/plone/dexterity/tests/__init__.py b/plone/dexterity/tests/__init__.py index 40a96af..e69de29 100644 --- a/plone/dexterity/tests/__init__.py +++ b/plone/dexterity/tests/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/plone/dexterity/tests/case.py b/plone/dexterity/tests/case.py index 05d2417..bb8c503 100644 --- a/plone/dexterity/tests/case.py +++ b/plone/dexterity/tests/case.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import gc import six import unittest @@ -10,7 +9,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class MockTestCase(unittest.TestCase): @@ -88,7 +87,7 @@ def patch_global(self, orig, mock=None, **kw): return mock -class Dummy(object): +class Dummy: """Dummy object with arbitrary attributes""" def __init__(self, **kw): @@ -120,6 +119,6 @@ def _global_replace(remove, install): """Replace object 'remove' with object 'install' on all dictionaries.""" for referrer in gc.get_referrers(remove): if type(referrer) is dict: - for key, value in list(six.iteritems(referrer)): + for key, value in list(referrer.items()): if value is remove: referrer[key] = install diff --git a/plone/dexterity/tests/schemata.py b/plone/dexterity/tests/schemata.py index 7473382..13db211 100644 --- a/plone/dexterity/tests/schemata.py +++ b/plone/dexterity/tests/schemata.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.supermodel.interfaces import FILENAME_KEY from zope import schema from zope.interface import Interface diff --git a/plone/dexterity/tests/test_behavior.py b/plone/dexterity/tests/test_behavior.py index 660dc98..ee45d91 100644 --- a/plone/dexterity/tests/test_behavior.py +++ b/plone/dexterity/tests/test_behavior.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.behavior.interfaces import IBehavior from plone.dexterity.behavior import DexterityBehaviorAssignable diff --git a/plone/dexterity/tests/test_content.py b/plone/dexterity/tests/test_content.py index 8648900..c385718 100644 --- a/plone/dexterity/tests/test_content.py +++ b/plone/dexterity/tests/test_content.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from datetime import date from datetime import datetime @@ -34,12 +33,12 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock try: from unittest.mock import patch except ImportError: - from mock import patch + from unittest.mock import patch class TestContent(MockTestCase): @@ -50,7 +49,7 @@ def setUp(self): provideAdapter(AttributeAnnotations) def test_provided_by_item(self): - class FauxDataManager(object): + class FauxDataManager: def setstate(self, obj): pass @@ -106,7 +105,7 @@ def test_provided_by_subclass(self): class MyItem(Item): pass - class FauxDataManager(object): + class FauxDataManager: def setstate(self, obj): pass @@ -211,7 +210,7 @@ class IMarkerCustom(Interface): pass # Fake data manager - class FauxDataManager(object): + class FauxDataManager: def setstate(self, obj): pass @@ -304,7 +303,7 @@ class MyItem(Item): pass # Fake data manager - class FauxDataManager(object): + class FauxDataManager: def setstate(self, obj): pass @@ -461,7 +460,7 @@ def test_getattr_consults_schema_item_default_factory_with_context(self): @provider(IContextAwareDefaultFactory) def defaultFactory(context): - return "{0:s}_{1:s}".format(context.id, context.portal_type) + return f"{context.id:s}_{context.portal_type:s}" class ISchema(Interface): foo = zope.schema.TextLine(title="foo", defaultFactory=defaultFactory) @@ -561,15 +560,7 @@ def test_name_and_id_in_sync(self): def test_name_unicode_id_str(self): i = Item() - if six.PY2: - try: - i.__name__ = b"\xc3\xb8".decode("utf-8") - except UnicodeEncodeError: - pass - else: - self.fail() - else: - i.__name__ = b"\xc3\xb8".decode("utf-8") + i.__name__ = b"\xc3\xb8".decode("utf-8") i.__name__ = "o" @@ -577,7 +568,7 @@ def test_name_unicode_id_str(self): self.assertEqual("o", i.id) self.assertEqual("o", i.getId()) - self.assertTrue(isinstance(i.__name__, six.text_type)) + self.assertTrue(isinstance(i.__name__, str)) self.assertTrue(isinstance(i.id, str)) self.assertTrue(isinstance(i.getId(), str)) @@ -747,7 +738,7 @@ def test_item_Type(self): i = Item() def mock_getTypeInfo(): - class TypeInfo(object): + class TypeInfo: def Title(self): return "Foo" @@ -892,7 +883,7 @@ def test_field_default_independence(self): # Ensure that fields using the default value aren't being assigned # shallow copies. - class FauxDataManager(object): + class FauxDataManager: def setstate(self, obj): pass @@ -961,7 +952,7 @@ def test_container_manage_delObjects(self): item.__class__.__ac_permissions__ = perms_before def test_iconstraintypes_adapter(self): - class DummyConstrainTypes(object): + class DummyConstrainTypes: def __init__(self, context): self.context = context diff --git a/plone/dexterity/tests/test_content_integration.py b/plone/dexterity/tests/test_content_integration.py index 9291798..b095769 100644 --- a/plone/dexterity/tests/test_content_integration.py +++ b/plone/dexterity/tests/test_content_integration.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.testing.zca import UNIT_TESTING import unittest diff --git a/plone/dexterity/tests/test_exportimport.py b/plone/dexterity/tests/test_exportimport.py index 97cd983..78f6fbe 100644 --- a/plone/dexterity/tests/test_exportimport.py +++ b/plone/dexterity/tests/test_exportimport.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import unittest diff --git a/plone/dexterity/tests/test_factory.py b/plone/dexterity/tests/test_factory.py index ee9bd17..137520e 100644 --- a/plone/dexterity/tests/test_factory.py +++ b/plone/dexterity/tests/test_factory.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.dexterity.factory import DexterityFactory from plone.dexterity.fti import DexterityFTI @@ -9,7 +8,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class IDummy(Interface): diff --git a/plone/dexterity/tests/test_fti.py b/plone/dexterity/tests/test_fti.py index 1810b8b..92fcc90 100644 --- a/plone/dexterity/tests/test_fti.py +++ b/plone/dexterity/tests/test_fti.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.dexterity.factory import DexterityFactory from plone.dexterity.fti import DexterityFTI @@ -35,14 +34,14 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock -class TestClass(object): +class TestClass: meta_type = "Test Class" -class TestClass2(object): +class TestClass2: meta_type = "Test Class 2" diff --git a/plone/dexterity/tests/test_primary.py b/plone/dexterity/tests/test_primary.py index e3e831c..ec1dceb 100644 --- a/plone/dexterity/tests/test_primary.py +++ b/plone/dexterity/tests/test_primary.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.dexterity.content import Item from plone.dexterity.fti import DexterityFTI @@ -13,7 +12,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class PrimaryFieldInfoTestCase(MockTestCase): diff --git a/plone/dexterity/tests/test_schema.py b/plone/dexterity/tests/test_schema.py index a4a9b60..6aec347 100644 --- a/plone/dexterity/tests/test_schema.py +++ b/plone/dexterity/tests/test_schema.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.dexterity import schema from plone.dexterity.fti import DexterityFTI @@ -18,7 +17,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class TestSchemaModuleFactory(MockTestCase): diff --git a/plone/dexterity/tests/test_schema_cache.py b/plone/dexterity/tests/test_schema_cache.py index 286482a..def78a9 100644 --- a/plone/dexterity/tests/test_schema_cache.py +++ b/plone/dexterity/tests/test_schema_cache.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.dexterity.fti import DexterityFTI from plone.dexterity.interfaces import IDexterityFTI @@ -11,12 +10,12 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock try: from unittest.mock import patch except ImportError: - from mock import patch + from unittest.mock import patch class TestSchemaCache(MockTestCase): diff --git a/plone/dexterity/tests/test_security.py b/plone/dexterity/tests/test_security.py index 5c468d3..b6a5a84 100644 --- a/plone/dexterity/tests/test_security.py +++ b/plone/dexterity/tests/test_security.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.autoform.interfaces import READ_PERMISSIONS_KEY from plone.dexterity.content import Container @@ -19,7 +18,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class TestAttributeProtection(MockTestCase): diff --git a/plone/dexterity/tests/test_synchronize.py b/plone/dexterity/tests/test_synchronize.py index 48f946b..aa3db2d 100644 --- a/plone/dexterity/tests/test_synchronize.py +++ b/plone/dexterity/tests/test_synchronize.py @@ -4,7 +4,7 @@ import unittest -class StupidStack(object): +class StupidStack: _elements = [] # not thread safe _lock = Lock() diff --git a/plone/dexterity/tests/test_utils.py b/plone/dexterity/tests/test_utils.py index 0b6ff3c..da0469f 100644 --- a/plone/dexterity/tests/test_utils.py +++ b/plone/dexterity/tests/test_utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from plone.dexterity import utils from plone.dexterity.fti import DexterityFTI @@ -7,7 +6,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class TestUtils(MockTestCase): diff --git a/plone/dexterity/tests/test_views.py b/plone/dexterity/tests/test_views.py index b6373a5..d3063de 100644 --- a/plone/dexterity/tests/test_views.py +++ b/plone/dexterity/tests/test_views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .case import MockTestCase from AccessControl import Unauthorized from plone.autoform.interfaces import IFormFieldProvider @@ -43,7 +42,7 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock class TestRequest(TestRequestBase): @@ -76,7 +75,7 @@ class IBehaviorThree(Interface): @implementer(IBehaviorAssignable) @adapter(Interface) -class NoBehaviorAssignable(object): +class NoBehaviorAssignable: # We will use this simple class to check that registering our own # IBehaviorAssignable adapter has an effect. @@ -168,7 +167,7 @@ def test_add(self): # Name chooser @implementer(INameChooser) - class NameChooser(object): + class NameChooser: def __init__(self, context): pass @@ -252,7 +251,7 @@ def test_label(self): addform.portal_type = "testtype" label = addform.label - self.assertEqual("Add ${name}", six.text_type(label)) + self.assertEqual("Add ${name}", str(label)) self.assertEqual("Test title", label.mapping["name"]) def test_schema_lookup_add(self): @@ -403,7 +402,7 @@ def test_fires_add_cancelled_event(self): # mock status message @implementer(IStatusMessage) - class StatusMessage(object): + class StatusMessage: def __init__(self, request): pass @@ -451,7 +450,7 @@ def test_label(self): editview.portal_type = "testtype" label = editview.label - self.assertEqual("Edit ${name}", six.text_type(label)) + self.assertEqual("Edit ${name}", str(label)) self.assertEqual("Test title", label.mapping["name"]) def test_schema_lookup_edit(self): @@ -552,7 +551,7 @@ def test_fires_edit_cancelled_event(self): # mock status message @implementer(IStatusMessage) - class StatusMessage(object): + class StatusMessage: def __init__(self, request): pass @@ -582,7 +581,7 @@ def test_fires_edit_finished_event(self): # mock status message @implementer(IStatusMessage) - class StatusMessage(object): + class StatusMessage: def __init__(self, request): pass diff --git a/plone/dexterity/tests/test_webdav.py b/plone/dexterity/tests/test_webdav.py index fd6a9ef..0e6609b 100644 --- a/plone/dexterity/tests/test_webdav.py +++ b/plone/dexterity/tests/test_webdav.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.dexterity.bbb import HAS_WEBDAV from .case import MockTestCase @@ -51,13 +50,9 @@ try: from unittest.mock import Mock except ImportError: - from mock import Mock + from unittest.mock import Mock - if six.PY2: - # cope with upstream library changes in rendering the XML prolog - XML_PROLOG = b'' - else: - XML_PROLOG = b'' + XML_PROLOG = b'' @provider(IFormFieldProvider) class ITestBehavior(Interface): @@ -78,7 +73,7 @@ def test_get_size_no_adapter(self): self.assertEqual(0, item.get_size()) def test_get_size_wrong_adapter(self): - class SizedAdapter(object): + class SizedAdapter: def __init__(self, context): self.context = context @@ -94,7 +89,7 @@ def sizeForDisplay(self): self.assertEqual(0, item.get_size()) def test_get_size_right_adapter(self): - class SizedAdapter(object): + class SizedAdapter: def __init__(self, context): self.context = context @@ -116,7 +111,7 @@ def test_content_type_no_adapter(self): self.assertEqual(None, item.Format()) def test_content_type_simple_adapter(self): - class ReadFileAdapter(object): + class ReadFileAdapter: def __init__(self, context): self.context = context @@ -135,7 +130,7 @@ def test_get_no_adapter(self): self.assertEqual("", item.manage_DAVget()) def test_get_simple_adapter(self): - class ReadFileAdapter(object): + class ReadFileAdapter: def __init__(self, context): self.context = context @@ -162,7 +157,7 @@ def read(self, size=None): self.assertEqual("10", request.response.getHeader("Content-Length")) def test_get_minimal_adapter(self): - class ReadFileAdapter(object): + class ReadFileAdapter: def __init__(self, context): self.context = context @@ -188,7 +183,7 @@ def read(self, size=None): def test_get_streaming(self): @implementer(IStreamIterator) - class ReadFileAdapter(object): + class ReadFileAdapter: def __init__(self, context): self.context = context @@ -232,7 +227,7 @@ def test_put_no_body(self): self.assertRaises(MethodNotAllowed, item.PUT) def test_put_no_content_type_header(self): - class WriteFile(object): + class WriteFile: def __init__(self, context): self.context = context self._written = "" @@ -266,7 +261,7 @@ def factory(context): self.assertEqual(True, adapterInstance._closed) def test_put_with_content_type_header_no_charset(self): - class WriteFile(object): + class WriteFile: def __init__(self, context): self.context = context self._written = "" @@ -309,7 +304,7 @@ def handler(event): self.assertEqual(1, len(events)) def test_put_with_content_type_header_and_charset(self): - class WriteFile(object): + class WriteFile: def __init__(self, context): self.context = context self._written = "" @@ -361,7 +356,7 @@ def test_mkcol_no_adapter(self): def test_mkcol_simple_adapter(self): created = [] - class DirectoryFactory(object): + class DirectoryFactory: def __init__(self, context): self.context = context @@ -381,7 +376,7 @@ def test_put_factory_no_adapter(self): def test_put_factory_simple_adapter(self): instance = object() - class FileFactory(object): + class FileFactory: def __init__(self, context): self.context = context @@ -1017,11 +1012,11 @@ class ITestAdditional(Interface): alsoProvides(ITestAdditional["stuff"], IPrimaryField) alsoProvides(ITestAdditional, IFormFieldProvider) - class MockBehavior(object): + class MockBehavior: def __init__(self, iface): self.interface = iface - class MockBehaviorAssignable(object): + class MockBehaviorAssignable: def __init__(self, context): self.context = context diff --git a/plone/dexterity/utils.py b/plone/dexterity/utils.py index 745a394..e9a76e6 100644 --- a/plone/dexterity/utils.py +++ b/plone/dexterity/utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from AccessControl import Unauthorized from Acquisition import aq_base from Acquisition import aq_inner @@ -55,8 +54,7 @@ def iterSchemataForType(portal_type): main_schema = SCHEMA_CACHE.get(portal_type) if main_schema: yield main_schema - for schema in getAdditionalSchemata(portal_type=portal_type): - yield schema + yield from getAdditionalSchemata(portal_type=portal_type) def iterSchemata(context): @@ -66,8 +64,7 @@ def iterSchemata(context): main_schema = SCHEMA_CACHE.get(context.portal_type) if main_schema: yield main_schema - for schema in getAdditionalSchemata(context=context): - yield schema + yield from getAdditionalSchemata(context=context) def getAdditionalSchemata(context=None, portal_type=None): @@ -189,13 +186,13 @@ def createContentInContainer(container, portal_type, checkConstraints=True, **kw def safe_utf8(st): - if isinstance(st, six.text_type): + if isinstance(st, str): st = st.encode("utf8") return st def safe_unicode(st): - if isinstance(st, six.binary_type): + if isinstance(st, bytes): st = st.decode("utf8") return st diff --git a/setup.py b/setup.py index cb6e82f..1e8b084 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from setuptools import find_packages from setuptools import setup