Skip to content

Commit

Permalink
pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Apr 2, 2024
1 parent f670343 commit 8f18ac5
Show file tree
Hide file tree
Showing 36 changed files with 39 additions and 75 deletions.
2 changes: 0 additions & 2 deletions src/collective/taxonomy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

PATH_SEPARATOR = "\u241F"
LEGACY_PATH_SEPARATOR = "/"
PRETTY_PATH_SEPARATOR = " » "
Expand Down
7 changes: 3 additions & 4 deletions src/collective/taxonomy/behavior.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)
)
Expand Down Expand Up @@ -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
)
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/taxonomy/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/taxonomy/collectionfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 9 additions & 10 deletions src/collective/taxonomy/controlpanel.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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]
)
)
Expand All @@ -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]
)
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
)


Expand Down Expand Up @@ -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):
Expand Down
10 changes: 3 additions & 7 deletions src/collective/taxonomy/exportimport.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down Expand Up @@ -113,18 +112,15 @@ 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"
)
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):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/taxonomy/generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys


class Wrapper(object):
class Wrapper:
__name__ = __name__

lock = RLock()
Expand Down
8 changes: 3 additions & 5 deletions src/collective/taxonomy/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from .i18n import CollectiveTaxonomyMessageFactory as _
from plone import api
from plone.namedfile.field import NamedBlobFile
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/jsonimpl.py
Original file line number Diff line number Diff line change
@@ -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 _
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/restapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion src/collective/taxonomy/restapi/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
2 changes: 1 addition & 1 deletion src/collective/taxonomy/restapi/serializers/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@implementer(ISerializeToJson)
@adapter(ITaxonomy, Interface)
class TaxonomySerializer(object):
class TaxonomySerializer:
"""Taxnomy serializer"""

def __init__(self, context, request):
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/restapi/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion src/collective/taxonomy/restapi/services/taxonomy/add.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/restapi/services/taxonomy/get.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/restapi/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from collective.taxonomy.interfaces import ITaxonomy
from plone.restapi.interfaces import ISerializeToJson
from zope.component import getMultiAdapter
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/testing.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/tests/test_behavior.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from collective.taxonomy.interfaces import ITaxonomy
from collective.taxonomy.testing import INTEGRATION_TESTING
from plone import api
Expand Down
3 changes: 1 addition & 2 deletions src/collective/taxonomy/tests/test_controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from collective.taxonomy.testing import FUNCTIONAL_TESTING
from plone import api
from plone.app.testing import applyProfile
Expand Down Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/tests/test_controlpanel_restapi.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/tests/test_indexer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from collective.taxonomy.interfaces import ITaxonomy
from collective.taxonomy.testing import INTEGRATION_TESTING
from plone import api
Expand Down
5 changes: 2 additions & 3 deletions src/collective/taxonomy/tests/test_json.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"])
Expand Down Expand Up @@ -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"])
Expand Down
4 changes: 2 additions & 2 deletions src/collective/taxonomy/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

Expand Down
3 changes: 1 addition & 2 deletions src/collective/taxonomy/tests/test_taxonomy_endpoint.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"], {})
1 change: 0 additions & 1 deletion src/collective/taxonomy/tests/test_traverser.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/collective/taxonomy/tests/test_utility.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/collective/taxonomy/utility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from BTrees.IOBTree import IOBTree
from BTrees.OOBTree import OOBTree
from collective.taxonomy import generated
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 8f18ac5

Please sign in to comment.