Skip to content

Commit

Permalink
Get rid of 'six' dependency. Use plone.base instead of Products.CMFPl…
Browse files Browse the repository at this point in the history
…one.
  • Loading branch information
mauritsvanrees committed Apr 2, 2024
1 parent 8f18ac5 commit 44dff85
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 42 deletions.
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
18 changes: 9 additions & 9 deletions src/collective/taxonomy/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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(
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 @@ -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
2 changes: 1 addition & 1 deletion src/collective/taxonomy/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/collective/taxonomy/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/collective/taxonomy/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions src/collective/taxonomy/restapi/services/taxonomy/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
Expand All @@ -16,31 +16,31 @@
method="GET"
accept="application/json"
factory=".schema.TaxonomyGetSchema"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
permission="zope2.View"
name="@taxonomySchema"
/>

<plone:service
method="POST"
factory=".add.TaxonomyPost"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
permission="cmf.ManagePortal"
name="@taxonomy"
/>

<plone:service
method="DELETE"
factory=".delete.TaxonomyDelete"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
permission="cmf.ManagePortal"
name="@taxonomy"
/>

<plone:service
method="PATCH"
factory=".update.TaxonomyPatch"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
permission="cmf.ManagePortal"
name="@taxonomy"
/>
Expand Down
2 changes: 0 additions & 2 deletions src/collective/taxonomy/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from plone.app.testing.interfaces import TEST_USER_NAME

import json
import six
import unittest


Expand Down Expand Up @@ -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."""

Expand Down
19 changes: 1 addition & 18 deletions src/collective/taxonomy/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit 44dff85

Please sign in to comment.