Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI, run pyupgrade, get rid of six #154

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
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
25 changes: 12 additions & 13 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 All @@ -7,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
Expand All @@ -18,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
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 All @@ -119,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(
Expand All @@ -130,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()
Expand All @@ -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 Expand Up @@ -195,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(
Expand Down
4 changes: 2 additions & 2 deletions src/collective/taxonomy/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down 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
6 changes: 3 additions & 3 deletions src/collective/taxonomy/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@

<browser:page
name="tabular_view"
template="listing_tabular.pt"
menu="plone_displayviews"
title="Tabular view"
for="plone.app.contenttypes.behaviors.collection.ISyndicatableCollection"
class=".browser.TaxonomyCollectionView"
template="listing_tabular.pt"
permission="zope2.View"
layer=".interfaces.IBrowserLayer"
menu="plone_displayviews"
title="Tabular view"
/>

<adapter
Expand Down
21 changes: 10 additions & 11 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.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 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
16 changes: 6 additions & 10 deletions src/collective/taxonomy/exportimport.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
from collective.taxonomy.factory import registerTaxonomy
from collective.taxonomy.interfaces import ITaxonomy
from collective.taxonomy.vdex import ExportVdex
from collective.taxonomy.vdex import ImportVdex
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
from six.moves import configparser

import six
import configparser


def parseConfigFile(data):
Expand Down Expand Up @@ -95,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",
Expand All @@ -106,25 +105,22 @@ 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)
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
11 changes: 4 additions & 7 deletions src/collective/taxonomy/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
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")


class TaxonomyIndexerWrapper(object):
class TaxonomyIndexerWrapper:
def __init__(self, field_name, utility_name, context, catalog):
self.context = context
self.catalog = catalog
Expand All @@ -42,9 +41,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 +70,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
2 changes: 0 additions & 2 deletions 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 Expand Up @@ -97,7 +96,6 @@ def get_resource_url(self):


class ImportJson(BrowserView):

"""Update taxonomy using json data."""

def __call__(self):
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 -*-
3 changes: 2 additions & 1 deletion src/collective/taxonomy/restapi/serializers/taxonomy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" RestAPI Taxonomy serializer
"""

from collective.taxonomy import PATH_SEPARATOR
from collective.taxonomy.interfaces import ITaxonomy
from plone.api import portal
Expand All @@ -11,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 -*-
Loading
Loading