From 5ac266066d3c576039b225e8d3b23e8505ae4f86 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 2 Apr 2024 16:46:02 +0200 Subject: [PATCH 1/4] black --- src/collective/taxonomy/jsonimpl.py | 1 - .../taxonomy/restapi/serializers/taxonomy.py | 1 + .../taxonomy/restapi/services/taxonomy/update.py | 1 + src/collective/taxonomy/tests/test_controlpanel.py | 12 ++++++------ src/collective/taxonomy/tests/test_indexer.py | 1 - src/collective/taxonomy/tests/test_json.py | 2 -- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/collective/taxonomy/jsonimpl.py b/src/collective/taxonomy/jsonimpl.py index 36e60fe..065afb6 100644 --- a/src/collective/taxonomy/jsonimpl.py +++ b/src/collective/taxonomy/jsonimpl.py @@ -97,7 +97,6 @@ def get_resource_url(self): class ImportJson(BrowserView): - """Update taxonomy using json data.""" def __call__(self): diff --git a/src/collective/taxonomy/restapi/serializers/taxonomy.py b/src/collective/taxonomy/restapi/serializers/taxonomy.py index c97ed3c..6e4de6f 100644 --- a/src/collective/taxonomy/restapi/serializers/taxonomy.py +++ b/src/collective/taxonomy/restapi/serializers/taxonomy.py @@ -1,5 +1,6 @@ """ RestAPI Taxonomy serializer """ + from collective.taxonomy import PATH_SEPARATOR from collective.taxonomy.interfaces import ITaxonomy from plone.api import portal diff --git a/src/collective/taxonomy/restapi/services/taxonomy/update.py b/src/collective/taxonomy/restapi/services/taxonomy/update.py index 9be9d7e..c500c5c 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/update.py +++ b/src/collective/taxonomy/restapi/services/taxonomy/update.py @@ -1,5 +1,6 @@ """ RestAPI PATCH """ + from BTrees.OOBTree import OOBTree from collective.taxonomy import PATH_SEPARATOR from collective.taxonomy.controlpanel import TaxonomyEditFormAdapter diff --git a/src/collective/taxonomy/tests/test_controlpanel.py b/src/collective/taxonomy/tests/test_controlpanel.py index 2d406e4..ac05d57 100644 --- a/src/collective/taxonomy/tests/test_controlpanel.py +++ b/src/collective/taxonomy/tests/test_controlpanel.py @@ -45,9 +45,9 @@ def test_add_vocabulary(self): self.assertIn('id="TaxonomySettings"', self.browser.contents) self.browser.getControl("Add").click() self.browser.getControl(name="form.widgets.taxonomy").value = "foobar" - self.browser.getControl( - name="form.widgets.field_title" - ).value = "Foo Bar Vocabulary" + self.browser.getControl(name="form.widgets.field_title").value = ( + "Foo Bar Vocabulary" + ) self.browser.getControl(name="form.widgets.default_language:list").value = [ "en" ] @@ -64,9 +64,9 @@ def test_edit_vocabulary(self): self.browser.getForm(id="TaxonomySettings").submit( name="form.buttons.edit-taxonomy" ) - self.browser.getControl( - name="form.widgets.field_title" - ).value = "Edited Test Vocabulary" + self.browser.getControl(name="form.widgets.field_title").value = ( + "Edited Test Vocabulary" + ) self.browser.getForm(id="form").submit("Save") self.assertIn( 'Edited Test Vocabulary', self.browser.contents diff --git a/src/collective/taxonomy/tests/test_indexer.py b/src/collective/taxonomy/tests/test_indexer.py index 01a06f5..c1c12b7 100644 --- a/src/collective/taxonomy/tests/test_indexer.py +++ b/src/collective/taxonomy/tests/test_indexer.py @@ -19,7 +19,6 @@ class TestIndexer(unittest.TestCase): - """Test JSON views.""" layer = INTEGRATION_TESTING diff --git a/src/collective/taxonomy/tests/test_json.py b/src/collective/taxonomy/tests/test_json.py index c55ccf6..ba7341b 100644 --- a/src/collective/taxonomy/tests/test_json.py +++ b/src/collective/taxonomy/tests/test_json.py @@ -11,7 +11,6 @@ class TestJson(unittest.TestCase): - """Test JSON views.""" layer = INTEGRATION_TESTING @@ -107,7 +106,6 @@ def test_generate_json(self): @unittest.skipIf(six.PY2, "Those tests run just for Python 3") class TestEditDataJson(unittest.TestCase): - """Test Edit Data JSON view.""" layer = INTEGRATION_TESTING From f6703430183d93f242c546ef20dc0d08269b8285 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 2 Apr 2024 16:48:26 +0200 Subject: [PATCH 2/4] Let zpretty fix stuff. --- src/collective/taxonomy/configure.zcml | 6 +++--- .../taxonomy/restapi/services/taxonomy/configure.zcml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/collective/taxonomy/configure.zcml b/src/collective/taxonomy/configure.zcml index daf1080..f549809 100644 --- a/src/collective/taxonomy/configure.zcml +++ b/src/collective/taxonomy/configure.zcml @@ -98,13 +98,13 @@ - - + + /> From 8f18ac537469ca13f6165f82961916cf53881648 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 2 Apr 2024 16:50:26 +0200 Subject: [PATCH 3/4] pyupgrade --- src/collective/taxonomy/__init__.py | 2 -- src/collective/taxonomy/behavior.py | 7 +++---- src/collective/taxonomy/browser.py | 2 +- src/collective/taxonomy/collectionfilter.py | 2 +- src/collective/taxonomy/controlpanel.py | 19 +++++++++---------- src/collective/taxonomy/exportimport.py | 10 +++------- src/collective/taxonomy/generated.py | 2 +- src/collective/taxonomy/indexer.py | 8 +++----- src/collective/taxonomy/interfaces.py | 1 - src/collective/taxonomy/jsonimpl.py | 1 - src/collective/taxonomy/restapi/__init__.py | 1 - .../taxonomy/restapi/serializers/__init__.py | 1 - .../taxonomy/restapi/serializers/taxonomy.py | 2 +- .../taxonomy/restapi/services/__init__.py | 1 - .../restapi/services/controlpanel/__init__.py | 1 - .../services/controlpanel/controlpanel.py | 1 - .../restapi/services/taxonomy/__init__.py | 1 - .../taxonomy/restapi/services/taxonomy/add.py | 1 - .../restapi/services/taxonomy/delete.py | 1 - .../taxonomy/restapi/services/taxonomy/get.py | 1 - .../restapi/services/taxonomy/schema.py | 1 - src/collective/taxonomy/restapi/utils.py | 1 - src/collective/taxonomy/testing.py | 1 - .../taxonomy/tests/test_behavior.py | 1 - .../taxonomy/tests/test_controlpanel.py | 3 +-- .../tests/test_controlpanel_restapi.py | 1 - src/collective/taxonomy/tests/test_indexer.py | 1 - src/collective/taxonomy/tests/test_json.py | 5 ++--- src/collective/taxonomy/tests/test_setup.py | 4 ++-- .../taxonomy/tests/test_taxonomy_endpoint.py | 3 +-- .../taxonomy/tests/test_traverser.py | 1 - src/collective/taxonomy/tests/test_utility.py | 1 - src/collective/taxonomy/utility.py | 3 +-- src/collective/taxonomy/vdex.py | 7 +++---- src/collective/taxonomy/vocabulary.py | 11 +++++------ src/collective/taxonomy/widget.py | 5 ++--- 36 files changed, 39 insertions(+), 75 deletions(-) diff --git a/src/collective/taxonomy/__init__.py b/src/collective/taxonomy/__init__.py index 832c1ef..336acb8 100644 --- a/src/collective/taxonomy/__init__.py +++ b/src/collective/taxonomy/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - PATH_SEPARATOR = "\u241F" LEGACY_PATH_SEPARATOR = "/" PRETTY_PATH_SEPARATOR = " ยป " diff --git a/src/collective/taxonomy/behavior.py b/src/collective/taxonomy/behavior.py index a2e0590..2322214 100644 --- a/src/collective/taxonomy/behavior.py +++ b/src/collective/taxonomy/behavior.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy import generated from collective.taxonomy.i18n import CollectiveTaxonomyMessageFactory as _ from collective.taxonomy.indexer import TaxonomyIndexer @@ -107,7 +106,7 @@ def removeIndex(self): catalog.delIndex(self.field_name) except CatalogError: logging.info( - "Could not delete index {0} .. something is not right.".format( + "Could not delete index {} .. something is not right.".format( self.field_name ) ) @@ -152,7 +151,7 @@ def addIndex(self): catalog.addIndex(self.field_name, idx_object) except CatalogError: logging.info( - "Index {0} already exists, we hope it is proper configured".format( + "Index {} already exists, we hope it is proper configured".format( self.field_name ) # noqa: E501 ) @@ -163,7 +162,7 @@ def addMetadata(self): catalog.addColumn(self.field_name) except CatalogError: logging.info( - "Column {0} already exists".format(self.field_name) + "Column {} already exists".format(self.field_name) ) # noqa: E501 def unregisterInterface(self): diff --git a/src/collective/taxonomy/browser.py b/src/collective/taxonomy/browser.py index b2ae276..5b50097 100644 --- a/src/collective/taxonomy/browser.py +++ b/src/collective/taxonomy/browser.py @@ -53,7 +53,7 @@ def translate(self, msgid, domain="", target_language=None): class VocabularyTuplesView(BrowserView): def __init__(self, context, request, vocabulary): - super(VocabularyTuplesView, self).__init__(context, request) + super().__init__(context, request) self.vocabulary = vocabulary def __call__(self, target_language=None): diff --git a/src/collective/taxonomy/collectionfilter.py b/src/collective/taxonomy/collectionfilter.py index eaf13f2..55120a7 100644 --- a/src/collective/taxonomy/collectionfilter.py +++ b/src/collective/taxonomy/collectionfilter.py @@ -41,7 +41,7 @@ def groupby_modifier(groupby): behavior = sm.queryUtility(IBehavior, name=taxonomy[1].getGeneratedName()) taxonomy_field_prefix = behavior.field_prefix taxonomy_shortname = taxonomy[1].getShortName() - taxonomy_index_name = "{0}{1}".format(taxonomy_field_prefix, taxonomy_shortname) + taxonomy_index_name = "{}{}".format(taxonomy_field_prefix, taxonomy_shortname) groupby._groupby[taxonomy_index_name] = { "index": taxonomy_index_name, "metadata": taxonomy_index_name, diff --git a/src/collective/taxonomy/controlpanel.py b/src/collective/taxonomy/controlpanel.py index 99b60c5..87c5739 100644 --- a/src/collective/taxonomy/controlpanel.py +++ b/src/collective/taxonomy/controlpanel.py @@ -1,17 +1,16 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.exportimport import TaxonomyImportExportAdapter from collective.taxonomy.factory import registerTaxonomy from collective.taxonomy.i18n import CollectiveTaxonomyMessageFactory as _ from collective.taxonomy.interfaces import ITaxonomy from collective.taxonomy.interfaces import ITaxonomyForm from collective.taxonomy.interfaces import ITaxonomySettings +from io import BytesIO from plone import api from plone.app.registry.browser import controlpanel from plone.behavior.interfaces import IBehavior from plone.memoize import view from Products.CMFPlone.interfaces import IPloneSiteRoot from Products.Five.browser import BrowserView -from six import BytesIO from z3c.form import button from z3c.form import field from z3c.form import form @@ -40,7 +39,7 @@ class TaxonomySettingsControlPanelForm(controlpanel.RegistryEditForm): description = _("Taxonomy settings") def updateFields(self): - super(TaxonomySettingsControlPanelForm, self).updateFields() + super().updateFields() self.fields["taxonomies"].widgetFactory = CheckBoxFieldWidget def updateActions(self): @@ -64,7 +63,7 @@ def handle_edit_taxonomy_action(self, action): data, errors = self.extractData() if len(data.get("taxonomies", [])) > 0: self.request.RESPONSE.redirect( - "{0}/@@taxonomy-edit?form.widgets.taxonomy={1}".format( + "{}/@@taxonomy-edit?form.widgets.taxonomy={}".format( self.context.portal_url(), data.get("taxonomies")[0] ) ) @@ -81,7 +80,7 @@ def handle_edit_taxonomy_data_action(self, action): data, errors = self.extractData() if len(data.get("taxonomies", [])) > 0: self.request.RESPONSE.redirect( - "{0}/@@taxonomy-edit-data?taxonomy={1}".format( + "{}/@@taxonomy-edit-data?taxonomy={}".format( self.context.portal_url(), data.get("taxonomies")[0] ) ) @@ -123,7 +122,7 @@ def handle_export_action(self, action): if len(taxonomies) > 0: return self.request.RESPONSE.redirect( - "{0}/@@taxonomy-export?taxonomies={1}".format( + "{}/@@taxonomy-export?taxonomies={}".format( self.context.portal_url(), ",".join(taxonomies) ) ) # noqa @@ -218,7 +217,7 @@ def handleAdd(self, action): def handleCancel(self, action): api.portal.show_message(_("Add cancelled"), request=self.request) self.request.response.redirect( - "{0}/@@taxonomy-settings".format(self.context.absolute_url()) + "{}/@@taxonomy-settings".format(self.context.absolute_url()) ) @@ -256,20 +255,20 @@ def handleApply(self, action): api.portal.show_message(_("Changes saved"), request=self.request) self.request.response.redirect( - "{0}/@@taxonomy-settings".format(self.context.absolute_url()) + "{}/@@taxonomy-settings".format(self.context.absolute_url()) ) @button.buttonAndHandler(_("Cancel"), name="cancel") def handleCancel(self, action): api.portal.show_message(_("Edit cancelled"), request=self.request) self.request.response.redirect( - "{0}/@@taxonomy-settings".format(self.context.absolute_url()) + "{}/@@taxonomy-settings".format(self.context.absolute_url()) ) @adapter(IPloneSiteRoot) @implementer(ITaxonomyForm) -class TaxonomyEditFormAdapter(object): +class TaxonomyEditFormAdapter: purge = False def __init__(self, context, name=None): diff --git a/src/collective/taxonomy/exportimport.py b/src/collective/taxonomy/exportimport.py index e65e7c4..8f138c4 100644 --- a/src/collective/taxonomy/exportimport.py +++ b/src/collective/taxonomy/exportimport.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.factory import registerTaxonomy from collective.taxonomy.interfaces import ITaxonomy from collective.taxonomy.vdex import ExportVdex @@ -7,8 +6,8 @@ from io import StringIO from lxml.etree import fromstring from plone.behavior.interfaces import IBehavior -from six.moves import configparser +import configparser import six @@ -113,10 +112,7 @@ def exportTaxonomy(context): if value: config.set("taxonomy", name, str(value).lower()) - if six.PY3: - filehandle = StringIO() - else: - filehandle = BytesIO() + filehandle = StringIO() config.write(filehandle) context.writeDataFile( "taxonomies/" + short_name + ".cfg", filehandle.getvalue(), "text/plain" @@ -124,7 +120,7 @@ def exportTaxonomy(context): context.writeDataFile("taxonomies/" + short_name + ".xml", body, "text/xml") -class TaxonomyImportExportAdapter(object): +class TaxonomyImportExportAdapter: IMSVDEX_NS = "http://www.imsglobal.org/xsd/imsvdex_v1p0" def __init__(self, context): diff --git a/src/collective/taxonomy/generated.py b/src/collective/taxonomy/generated.py index 76c6cae..b9e94f7 100644 --- a/src/collective/taxonomy/generated.py +++ b/src/collective/taxonomy/generated.py @@ -8,7 +8,7 @@ import sys -class Wrapper(object): +class Wrapper: __name__ = __name__ lock = RLock() diff --git a/src/collective/taxonomy/indexer.py b/src/collective/taxonomy/indexer.py index ff281d9..1295df6 100644 --- a/src/collective/taxonomy/indexer.py +++ b/src/collective/taxonomy/indexer.py @@ -17,7 +17,7 @@ logger = logging.getLogger("collective.taxonomy") -class TaxonomyIndexerWrapper(object): +class TaxonomyIndexerWrapper: def __init__(self, field_name, utility_name, context, catalog): self.context = context self.catalog = catalog @@ -42,9 +42,7 @@ def __call__(self): found = [] stored_element = getattr(self.context, self.field_name) - if not isinstance(stored_element, Iterable) or isinstance( - stored_element, six.string_types - ): + if not isinstance(stored_element, Iterable) or isinstance(stored_element, str): stored_element = [stored_element] for language, data in utility.data.items(): @@ -73,7 +71,7 @@ def __call__(self): @adapter(IDexterityContent, IZCatalog) @implementer(IIndexer) -class TaxonomyIndexer(object): +class TaxonomyIndexer: __name__ = "TaxonomyIndexer" def __init__(self, field_name, utility_name): diff --git a/src/collective/taxonomy/interfaces.py b/src/collective/taxonomy/interfaces.py index b019f51..a881e34 100644 --- a/src/collective/taxonomy/interfaces.py +++ b/src/collective/taxonomy/interfaces.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .i18n import CollectiveTaxonomyMessageFactory as _ from plone import api from plone.namedfile.field import NamedBlobFile diff --git a/src/collective/taxonomy/jsonimpl.py b/src/collective/taxonomy/jsonimpl.py index 065afb6..2655d1b 100644 --- a/src/collective/taxonomy/jsonimpl.py +++ b/src/collective/taxonomy/jsonimpl.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from BTrees.OOBTree import OOBTree from collective.taxonomy import PATH_SEPARATOR from collective.taxonomy.i18n import CollectiveTaxonomyMessageFactory as _ diff --git a/src/collective/taxonomy/restapi/__init__.py b/src/collective/taxonomy/restapi/__init__.py index 40a96af..e69de29 100644 --- a/src/collective/taxonomy/restapi/__init__.py +++ b/src/collective/taxonomy/restapi/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/src/collective/taxonomy/restapi/serializers/__init__.py b/src/collective/taxonomy/restapi/serializers/__init__.py index 40a96af..e69de29 100644 --- a/src/collective/taxonomy/restapi/serializers/__init__.py +++ b/src/collective/taxonomy/restapi/serializers/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/src/collective/taxonomy/restapi/serializers/taxonomy.py b/src/collective/taxonomy/restapi/serializers/taxonomy.py index 6e4de6f..2945a0a 100644 --- a/src/collective/taxonomy/restapi/serializers/taxonomy.py +++ b/src/collective/taxonomy/restapi/serializers/taxonomy.py @@ -12,7 +12,7 @@ @implementer(ISerializeToJson) @adapter(ITaxonomy, Interface) -class TaxonomySerializer(object): +class TaxonomySerializer: """Taxnomy serializer""" def __init__(self, context, request): diff --git a/src/collective/taxonomy/restapi/services/__init__.py b/src/collective/taxonomy/restapi/services/__init__.py index 40a96af..e69de29 100644 --- a/src/collective/taxonomy/restapi/services/__init__.py +++ b/src/collective/taxonomy/restapi/services/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/src/collective/taxonomy/restapi/services/controlpanel/__init__.py b/src/collective/taxonomy/restapi/services/controlpanel/__init__.py index 40a96af..e69de29 100644 --- a/src/collective/taxonomy/restapi/services/controlpanel/__init__.py +++ b/src/collective/taxonomy/restapi/services/controlpanel/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/src/collective/taxonomy/restapi/services/controlpanel/controlpanel.py b/src/collective/taxonomy/restapi/services/controlpanel/controlpanel.py index 6aec6f9..9d7d421 100644 --- a/src/collective/taxonomy/restapi/services/controlpanel/controlpanel.py +++ b/src/collective/taxonomy/restapi/services/controlpanel/controlpanel.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.i18n import CollectiveTaxonomyMessageFactory as _ from collective.taxonomy.interfaces import IBrowserLayer from collective.taxonomy.interfaces import ITaxonomyControlPanel diff --git a/src/collective/taxonomy/restapi/services/taxonomy/__init__.py b/src/collective/taxonomy/restapi/services/taxonomy/__init__.py index 40a96af..e69de29 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/__init__.py +++ b/src/collective/taxonomy/restapi/services/taxonomy/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/src/collective/taxonomy/restapi/services/taxonomy/add.py b/src/collective/taxonomy/restapi/services/taxonomy/add.py index 91e8b71..22aeaff 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/add.py +++ b/src/collective/taxonomy/restapi/services/taxonomy/add.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.exportimport import TaxonomyImportExportAdapter from collective.taxonomy.factory import registerTaxonomy from collective.taxonomy.interfaces import ITaxonomyForm diff --git a/src/collective/taxonomy/restapi/services/taxonomy/delete.py b/src/collective/taxonomy/restapi/services/taxonomy/delete.py index 3c2cdfb..646d0e6 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/delete.py +++ b/src/collective/taxonomy/restapi/services/taxonomy/delete.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.i18n import CollectiveTaxonomyMessageFactory as _ from collective.taxonomy.interfaces import ITaxonomy from plone.restapi.services import Service diff --git a/src/collective/taxonomy/restapi/services/taxonomy/get.py b/src/collective/taxonomy/restapi/services/taxonomy/get.py index 1a62c7a..e533a77 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/get.py +++ b/src/collective/taxonomy/restapi/services/taxonomy/get.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomy from collective.taxonomy.restapi.utils import get_all_taxonomies from collective.taxonomy.vdex import TreeExport diff --git a/src/collective/taxonomy/restapi/services/taxonomy/schema.py b/src/collective/taxonomy/restapi/services/taxonomy/schema.py index 81d9fc0..930aa27 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/schema.py +++ b/src/collective/taxonomy/restapi/services/taxonomy/schema.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomyForm from plone.restapi.serializer.controlpanels import get_jsonschema_for_controlpanel from plone.restapi.serializer.converters import json_compatible diff --git a/src/collective/taxonomy/restapi/utils.py b/src/collective/taxonomy/restapi/utils.py index ed9d053..2ebcd72 100644 --- a/src/collective/taxonomy/restapi/utils.py +++ b/src/collective/taxonomy/restapi/utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomy from plone.restapi.interfaces import ISerializeToJson from zope.component import getMultiAdapter diff --git a/src/collective/taxonomy/testing.py b/src/collective/taxonomy/testing.py index 55c40b8..99310bb 100644 --- a/src/collective/taxonomy/testing.py +++ b/src/collective/taxonomy/testing.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE from plone.app.testing import applyProfile from plone.app.testing import FunctionalTesting diff --git a/src/collective/taxonomy/tests/test_behavior.py b/src/collective/taxonomy/tests/test_behavior.py index 7dc737f..fcb6deb 100644 --- a/src/collective/taxonomy/tests/test_behavior.py +++ b/src/collective/taxonomy/tests/test_behavior.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomy from collective.taxonomy.testing import INTEGRATION_TESTING from plone import api diff --git a/src/collective/taxonomy/tests/test_controlpanel.py b/src/collective/taxonomy/tests/test_controlpanel.py index ac05d57..cd015b8 100644 --- a/src/collective/taxonomy/tests/test_controlpanel.py +++ b/src/collective/taxonomy/tests/test_controlpanel.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.testing import FUNCTIONAL_TESTING from plone import api from plone.app.testing import applyProfile @@ -29,7 +28,7 @@ def setUp(self): self.browser.handleErrors = False self.browser.addHeader( "Authorization", - "Basic {0}:{1}".format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD), + "Basic {}:{}".format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD), ) commit() diff --git a/src/collective/taxonomy/tests/test_controlpanel_restapi.py b/src/collective/taxonomy/tests/test_controlpanel_restapi.py index 1d2dd17..27429bb 100644 --- a/src/collective/taxonomy/tests/test_controlpanel_restapi.py +++ b/src/collective/taxonomy/tests/test_controlpanel_restapi.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.testing import FUNCTIONAL_TESTING from plone.app.testing import applyProfile from plone.app.testing import setRoles diff --git a/src/collective/taxonomy/tests/test_indexer.py b/src/collective/taxonomy/tests/test_indexer.py index c1c12b7..dc7e1af 100644 --- a/src/collective/taxonomy/tests/test_indexer.py +++ b/src/collective/taxonomy/tests/test_indexer.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomy from collective.taxonomy.testing import INTEGRATION_TESTING from plone import api diff --git a/src/collective/taxonomy/tests/test_json.py b/src/collective/taxonomy/tests/test_json.py index ba7341b..4996148 100644 --- a/src/collective/taxonomy/tests/test_json.py +++ b/src/collective/taxonomy/tests/test_json.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.testing import INTEGRATION_TESTING from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID @@ -16,7 +15,7 @@ class TestJson(unittest.TestCase): layer = INTEGRATION_TESTING def setUp(self): - super(TestJson, self).setUp() + super().setUp() self.portal = self.layer["portal"] self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) @@ -111,7 +110,7 @@ class TestEditDataJson(unittest.TestCase): layer = INTEGRATION_TESTING def setUp(self): - super(TestEditDataJson, self).setUp() + super().setUp() self.portal = self.layer["portal"] self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) diff --git a/src/collective/taxonomy/tests/test_setup.py b/src/collective/taxonomy/tests/test_setup.py index 888afeb..8adba46 100644 --- a/src/collective/taxonomy/tests/test_setup.py +++ b/src/collective/taxonomy/tests/test_setup.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- """Setup tests for this package.""" + from collective.taxonomy.testing import INTEGRATION_TESTING from plone import api from plone.app.testing import setRoles @@ -16,7 +16,7 @@ except Exception: # Quick shim for 5.1 api change - class get_installer(object): + class get_installer: def __init__(self, portal, request): self.installer = getToolByName(portal, "portal_quickinstaller") diff --git a/src/collective/taxonomy/tests/test_taxonomy_endpoint.py b/src/collective/taxonomy/tests/test_taxonomy_endpoint.py index 25b1562..302a4da 100644 --- a/src/collective/taxonomy/tests/test_taxonomy_endpoint.py +++ b/src/collective/taxonomy/tests/test_taxonomy_endpoint.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.testing import FUNCTIONAL_TESTING from plone.app.testing import applyProfile from plone.app.testing import setRoles @@ -170,4 +169,4 @@ def test_get_AddTaxonomy_Schema(self): fields = [x.get("fields") for x in response["fieldsets"]] self.assertIn("field_title", fields[0]) self.assertIn("taxonomy", fields[0]) - self.assertNotEquals(response["properties"], {}) + self.assertNotEqual(response["properties"], {}) diff --git a/src/collective/taxonomy/tests/test_traverser.py b/src/collective/taxonomy/tests/test_traverser.py index 8945e90..7524d14 100644 --- a/src/collective/taxonomy/tests/test_traverser.py +++ b/src/collective/taxonomy/tests/test_traverser.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.browser import VocabularyTuplesView from collective.taxonomy.testing import INTEGRATION_TESTING from collective.taxonomy.vocabulary import Vocabulary diff --git a/src/collective/taxonomy/tests/test_utility.py b/src/collective/taxonomy/tests/test_utility.py index 7d22ddc..0085511 100644 --- a/src/collective/taxonomy/tests/test_utility.py +++ b/src/collective/taxonomy/tests/test_utility.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomy from collective.taxonomy.testing import INTEGRATION_TESTING from zope.component import queryUtility diff --git a/src/collective/taxonomy/utility.py b/src/collective/taxonomy/utility.py index 5f8f4bd..94eea8c 100644 --- a/src/collective/taxonomy/utility.py +++ b/src/collective/taxonomy/utility.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from BTrees.IOBTree import IOBTree from BTrees.OOBTree import OOBTree from collective.taxonomy import generated @@ -267,7 +266,7 @@ def fix(path): seen = set() for key, value in items: if key in seen: - logger.warning("Duplicate key entry: %r" % (key,)) + logger.warning("Duplicate key entry: {!r}".format(key)) seen.add(key) update = key in tree diff --git a/src/collective/taxonomy/vdex.py b/src/collective/taxonomy/vdex.py index 5fcb4a1..fb89fe3 100644 --- a/src/collective/taxonomy/vdex.py +++ b/src/collective/taxonomy/vdex.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collections import OrderedDict from collective.taxonomy import PATH_SEPARATOR from lxml import etree @@ -8,7 +7,7 @@ LANG_SEPARATOR = "|" -class ImportVdex(object): +class ImportVdex: """Helper class for import""" def __init__(self, tree, ns): @@ -42,7 +41,7 @@ def recurse(self, tree, available_languages=set(), parent_language=None): for node in tree.findall("./{%s}term" % self.ns): identifier = node.find("./{%s}termIdentifier" % self.ns) langstrings = node.findall( - "./{%s}caption/{%s}langstring" % (self.ns, self.ns) + "./{{{}}}caption/{{{}}}langstring".format(self.ns, self.ns) ) for i in langstrings: if not parent_language or parent_language == i.attrib["language"]: @@ -62,7 +61,7 @@ def recurse(self, tree, available_languages=set(), parent_language=None): return result -class TreeExport(object): +class TreeExport: def __init__(self, taxonomy): self.taxonomy = taxonomy diff --git a/src/collective/taxonomy/vocabulary.py b/src/collective/taxonomy/vocabulary.py index 3635ad7..05eaa34 100644 --- a/src/collective/taxonomy/vocabulary.py +++ b/src/collective/taxonomy/vocabulary.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collections import OrderedDict from collective.taxonomy import LEGACY_PATH_SEPARATOR from collective.taxonomy import NODE @@ -22,11 +21,11 @@ class Node(OrderedDict): def __init__(self, term): self.term = term - super(Node, self).__init__() + super().__init__() @implementer(IVocabularyFactory) -class TaxonomyVocabulary(object): +class TaxonomyVocabulary: # Vocabulary for generating a list of existing taxonomies def __call__(self, adapter): @@ -41,7 +40,7 @@ def __call__(self, adapter): @implementer(IVocabularyTokenized) -class Vocabulary(object): +class Vocabulary: """Vocabulary, generated by the ITaxonomy utility""" def __init__(self, name, data, inv_data, order, version): @@ -172,7 +171,7 @@ def add(path, value): @implementer(IVocabularyFactory) -class PermissionsVocabulary(object): +class PermissionsVocabulary: def __call__(self, context): result = [] sm = getSite().getSiteManager() @@ -189,7 +188,7 @@ def __call__(self, context): @implementer(IVocabularyFactory) -class LanguagesVocabulary(object): +class LanguagesVocabulary: """Languages vocabulary.""" def __call__(self, context): diff --git a/src/collective/taxonomy/widget.py b/src/collective/taxonomy/widget.py index f7d06b2..f068b92 100644 --- a/src/collective/taxonomy/widget.py +++ b/src/collective/taxonomy/widget.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from collective.taxonomy.interfaces import ITaxonomySelectWidget from plone.memoize import ram from z3c.form import interfaces @@ -14,7 +13,7 @@ def _items_cachekey(fun, self): # try to get modified time of taxonomy utility try: mtime = self.terms.terms.data._p_mtime - key = "{0}-{1}".format(self.field.__name__, mtime) + key = "{}-{}".format(self.field.__name__, mtime) return key except AttributeError: # XXX: this happens with newly created taxonomies @@ -31,7 +30,7 @@ def _get_items(self): def update(self): """See z3c.form.interfaces.IWidget.""" - super(TaxonomySelectWidget, self).update() + super().update() self.items = self._get_items() self.selectedItems = [ self.getItem(self.terms.getTermByToken(token), count) From 44dff85f4a121463fa13bc7c3d34549f0eb99bb7 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 2 Apr 2024 17:02:02 +0200 Subject: [PATCH 4/4] Get rid of 'six' dependency. Use plone.base instead of Products.CMFPlone. --- setup.py | 2 +- src/collective/taxonomy/behavior.py | 18 +++++++++--------- src/collective/taxonomy/browser.py | 2 +- src/collective/taxonomy/controlpanel.py | 2 +- src/collective/taxonomy/exportimport.py | 6 +++--- src/collective/taxonomy/indexer.py | 3 +-- .../restapi/services/taxonomy/configure.zcml | 10 +++++----- src/collective/taxonomy/tests/test_json.py | 2 -- src/collective/taxonomy/tests/test_setup.py | 19 +------------------ 9 files changed, 22 insertions(+), 42 deletions(-) diff --git a/setup.py b/setup.py index a42bdc1..4e2a2d8 100644 --- a/setup.py +++ b/setup.py @@ -49,13 +49,13 @@ def read(*pathnames): python_requires=">=3.8", install_requires=[ "setuptools", + "plone.base", "plone.supermodel", "plone.api >= 1.5", "plone.app.registry", "plone.app.dexterity", "plone.synchronize", "lxml", - "six >= 1.12", ], extras_require={ "dev": [ diff --git a/src/collective/taxonomy/behavior.py b/src/collective/taxonomy/behavior.py index 2322214..85aabd0 100644 --- a/src/collective/taxonomy/behavior.py +++ b/src/collective/taxonomy/behavior.py @@ -6,6 +6,7 @@ from plone.autoform.interfaces import IFormFieldProvider from plone.autoform.interfaces import WIDGETS_KEY from plone.autoform.interfaces import WRITE_PERMISSIONS_KEY +from plone.base.utils import safe_text from plone.behavior.interfaces import IBehavior from plone.dexterity.interfaces import IDexterityContent from plone.indexer.interfaces import IIndexer @@ -17,7 +18,6 @@ from plone.supermodel.model import Schema from plone.supermodel.model import SchemaClass from Products.CMFCore.utils import getToolByName -from Products.CMFPlone.utils import safe_unicode from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex from Products.ZCatalog.Catalog import CatalogError from Products.ZCatalog.interfaces import IZCatalog @@ -118,9 +118,9 @@ def activateSearchable(self): def add(name, value): registry.records[prefix + "." + name] = value - add("title", Record(field.TextLine(), safe_unicode(self.field_title))) + add("title", Record(field.TextLine(), safe_text(self.field_title))) add("enabled", Record(field.Bool(), True)) - add("group", Record(field.TextLine(), safe_unicode("Taxonomy"))) + add("group", Record(field.TextLine(), safe_text("Taxonomy"))) add( "operations", Record( @@ -129,11 +129,11 @@ def add(name, value): ), ) add( - "vocabulary", Record(field.TextLine(), safe_unicode(self.vocabulary_name)) + "vocabulary", Record(field.TextLine(), safe_text(self.vocabulary_name)) ) # noqa: E501 add("fetch_vocabulary", Record(field.Bool(), True)) add("sortable", Record(field.Bool(), False)) - add("description", Record(field.Text(), safe_unicode(""))) + add("description", Record(field.Text(), safe_text(""))) def addIndex(self): context = getSite() @@ -194,15 +194,15 @@ def generateInterface(self): if hasattr(self, "is_single_select") and self.is_single_select: select_field = schema.Choice( - title=_(safe_unicode(self.field_title)), - description=_(safe_unicode(self.field_description)), + title=_(safe_text(self.field_title)), + description=_(safe_text(self.field_description)), required=self.is_required, vocabulary=self.vocabulary_name, ) else: select_field = schema.List( - title=_(safe_unicode(self.field_title)), - description=_(safe_unicode(self.field_description)), + title=_(safe_text(self.field_title)), + description=_(safe_text(self.field_description)), required=self.is_required, min_length=self.is_required and 1 or 0, value_type=schema.Choice( diff --git a/src/collective/taxonomy/browser.py b/src/collective/taxonomy/browser.py index 5b50097..89cfa0a 100644 --- a/src/collective/taxonomy/browser.py +++ b/src/collective/taxonomy/browser.py @@ -2,8 +2,8 @@ from plone import api from plone.app.contenttypes.browser.collection import CollectionView from plone.app.vocabularies.metadatafields import get_field_label +from plone.base.utils import safe_callable from plone.behavior.interfaces import IBehavior -from Products.CMFPlone.utils import safe_callable from Products.Five.browser import BrowserView from zope.component import getSiteManager from zope.component import queryUtility diff --git a/src/collective/taxonomy/controlpanel.py b/src/collective/taxonomy/controlpanel.py index 87c5739..2aa4bc3 100644 --- a/src/collective/taxonomy/controlpanel.py +++ b/src/collective/taxonomy/controlpanel.py @@ -7,9 +7,9 @@ from io import BytesIO from plone import api from plone.app.registry.browser import controlpanel +from plone.base.interfaces import IPloneSiteRoot from plone.behavior.interfaces import IBehavior from plone.memoize import view -from Products.CMFPlone.interfaces import IPloneSiteRoot from Products.Five.browser import BrowserView from z3c.form import button from z3c.form import field diff --git a/src/collective/taxonomy/exportimport.py b/src/collective/taxonomy/exportimport.py index 8f138c4..e0b98a3 100644 --- a/src/collective/taxonomy/exportimport.py +++ b/src/collective/taxonomy/exportimport.py @@ -5,10 +5,10 @@ from io import BytesIO from io import StringIO from lxml.etree import fromstring +from plone.base.utils import safe_text from plone.behavior.interfaces import IBehavior import configparser -import six def parseConfigFile(data): @@ -94,7 +94,7 @@ def exportTaxonomy(context): for name in ["title", "description", "default_language"]: value = getattr(taxonomy, name, None) if value: - config.set("taxonomy", name, six.ensure_text(value)) + config.set("taxonomy", name, safe_text(value)) for name in [ "field_title", @@ -105,7 +105,7 @@ def exportTaxonomy(context): ]: value = getattr(behavior, name, None) if value is not None: - config.set("taxonomy", name, six.ensure_text(value)) + config.set("taxonomy", name, safe_text(value)) for name in ["is_single_select", "is_required"]: value = getattr(behavior, name, None) diff --git a/src/collective/taxonomy/indexer.py b/src/collective/taxonomy/indexer.py index 1295df6..008cc01 100644 --- a/src/collective/taxonomy/indexer.py +++ b/src/collective/taxonomy/indexer.py @@ -3,15 +3,14 @@ from collections.abc import Iterable from collective.taxonomy.interfaces import ITaxonomy from plone import api +from plone.base.interfaces import IPloneSiteRoot from plone.dexterity.interfaces import IDexterityContent from plone.indexer.interfaces import IIndexer -from Products.CMFPlone.interfaces import IPloneSiteRoot from Products.ZCatalog.interfaces import IZCatalog from zope.component import adapter from zope.interface import implementer import logging -import six logger = logging.getLogger("collective.taxonomy") diff --git a/src/collective/taxonomy/restapi/services/taxonomy/configure.zcml b/src/collective/taxonomy/restapi/services/taxonomy/configure.zcml index 24d67bd..4d2f161 100644 --- a/src/collective/taxonomy/restapi/services/taxonomy/configure.zcml +++ b/src/collective/taxonomy/restapi/services/taxonomy/configure.zcml @@ -7,7 +7,7 @@ method="GET" accept="application/json,application/schema+json" factory=".get.TaxonomyGet" - for="Products.CMFPlone.interfaces.IPloneSiteRoot" + for="plone.base.interfaces.IPloneSiteRoot" permission="zope2.View" name="@taxonomy" /> @@ -16,7 +16,7 @@ method="GET" accept="application/json" factory=".schema.TaxonomyGetSchema" - for="Products.CMFPlone.interfaces.IPloneSiteRoot" + for="plone.base.interfaces.IPloneSiteRoot" permission="zope2.View" name="@taxonomySchema" /> @@ -24,7 +24,7 @@ @@ -32,7 +32,7 @@ @@ -40,7 +40,7 @@ diff --git a/src/collective/taxonomy/tests/test_json.py b/src/collective/taxonomy/tests/test_json.py index 4996148..0213f1f 100644 --- a/src/collective/taxonomy/tests/test_json.py +++ b/src/collective/taxonomy/tests/test_json.py @@ -5,7 +5,6 @@ from plone.app.testing.interfaces import TEST_USER_NAME import json -import six import unittest @@ -103,7 +102,6 @@ def test_generate_json(self): ) -@unittest.skipIf(six.PY2, "Those tests run just for Python 3") class TestEditDataJson(unittest.TestCase): """Test Edit Data JSON view.""" diff --git a/src/collective/taxonomy/tests/test_setup.py b/src/collective/taxonomy/tests/test_setup.py index 8adba46..4697e17 100644 --- a/src/collective/taxonomy/tests/test_setup.py +++ b/src/collective/taxonomy/tests/test_setup.py @@ -4,29 +4,12 @@ from plone import api from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID +from plone.base.utils import get_installer from Products.CMFCore.utils import getToolByName import unittest -no_get_installer = False - -try: - from Products.CMFPlone.utils import get_installer -except Exception: - # Quick shim for 5.1 api change - - class get_installer: - def __init__(self, portal, request): - self.installer = getToolByName(portal, "portal_quickinstaller") - - def is_product_installed(self, name): - return self.installer.isProductInstalled(name) - - def uninstall_product(self, name): - return self.installer.uninstallProducts([name]) - - class TestSetup(unittest.TestCase): """Test that collective.taxonomy is properly installed."""