From 44dff85f4a121463fa13bc7c3d34549f0eb99bb7 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 2 Apr 2024 17:02:02 +0200 Subject: [PATCH] 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."""