Skip to content

Commit

Permalink
Drop support for Python 2.7 up to 3.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Feb 9, 2023
1 parent b7377cd commit 812697c
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ with-macos = false
with-windows = false

[coverage]
fail-under = 89
fail-under = 88

[tox]
use-flake8 = true
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

def read_file(*args):
path = os.path.join(*args)
with open(path, 'r') as f:
with open(path) as f:
return f.read() + '\n\n'


setup(
name='zc.sourcefactory',
version='2.0.dev0',
author='Zope Corporation and Contributors',
author_email='zope-dev@zope.org',
author_email='zope-dev@zope.dev',
url='https://github.com/zopefoundation/zc.sourcefactory',
keywords='zope vocabulary source factory',
description='An easy way to create custom Zope sources.',
Expand Down Expand Up @@ -66,6 +66,7 @@ def read_file(*args):
packages=find_packages('src'),
package_dir={'': 'src'},
include_package_data=True,
python_requires='>=3.7',
install_requires=[
'ZODB',
'persistent',
Expand Down
16 changes: 8 additions & 8 deletions src/zc/sourcefactory/browser/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For each value we get a factored term:

Unicode values are allowed as well:

>>> terms.getTerm(u'\xd3')
>>> terms.getTerm('\xd3')
<zc.sourcefactory.browser.source.FactoredTerm object at 0x...>

Our terms are ITitledTokenizedTerm-compatible:
Expand All @@ -57,14 +57,14 @@ In the most simple case, the title of a term is the string representation of
the object:

>>> terms.getTerm('a').title
u'a'
'a'

If an adapter from the value to IDCDescriptiveProperties exists, the title
will be retrieved from this adapter:

>>> import persistent
>>> class MyObject(persistent.Persistent):
... custom_title = u'My custom title'
... custom_title = 'My custom title'
... _p_oid = 12
>>> class DCDescriptivePropertiesAdapter(object):
... def __init__(self, context):
Expand All @@ -75,7 +75,7 @@ will be retrieved from this adapter:
>>> provideAdapter(DCDescriptivePropertiesAdapter, [MyObject],
... IDCDescriptiveProperties)
>>> terms.getTerm(MyObject()).title
u'My custom title'
'My custom title'

Extended use: provide your own titles
=====================================
Expand All @@ -95,9 +95,9 @@ determine the title for a value:
>>> o2 = MyObject()
>>> o2.custom_title = u"Object two"
>>> terms2.getTerm(o1).title
u'Custom title Object one'
'Custom title Object one'
>>> terms2.getTerm(o2).title
u'Custom title Object two'
'Custom title Object two'


Extended use: provide your own tokens
Expand Down Expand Up @@ -153,7 +153,7 @@ Contextual sources
Let's start with an object that we can use as the context:

>>> zip_to_city = {'06112': 'Halle',
... '06844': 'Dessau'}
... '06844': 'Dessa'}
>>> import zc.sourcefactory.contextual
>>> class DemoContextualSource(
... zc.sourcefactory.contextual.BasicContextualSourceFactory):
Expand Down Expand Up @@ -183,7 +183,7 @@ For each value we get a factored term with the right title from the context:
>>> terms.getTerm('06844')
<zc.sourcefactory.browser.source.FactoredTerm object at 0x...>
>>> terms.getTerm('06844').title
'Dessau'
'Dessa'
>>> terms.getTerm('06844').token
'token-06844'

Expand Down
2 changes: 1 addition & 1 deletion src/zc/sourcefactory/browser/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@zope.component.adapter(zc.sourcefactory.mapping.ValueMappingSource,
zope.publisher.interfaces.browser.IBrowserRequest)
@zope.interface.implementer(zope.browser.interfaces.ITerms)
class MappedTerms(object):
class MappedTerms:
"""A terms implementation that knows how to handle a source that was
created through a source factory.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/zc/sourcefactory/browser/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@zope.component.adapter(zc.sourcefactory.source.FactoredSource,
zope.publisher.interfaces.browser.IBrowserRequest)
@zope.interface.implementer(zope.browser.interfaces.ITerms)
class FactoredTerms(object):
class FactoredTerms:
"""A terms implementation that knows how to handle a source that was
created through a source factory.
"""
Expand Down Expand Up @@ -64,7 +64,7 @@ def getValue(self, token):


@zope.interface.implementer(zope.schema.interfaces.ITitledTokenizedTerm)
class FactoredTerm(object):
class FactoredTerm:
"""A title tokenized term."""

def __init__(self, value, title, token):
Expand Down
5 changes: 2 additions & 3 deletions src/zc/sourcefactory/browser/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import doctest
import unittest

from zc.sourcefactory.tests import checker
from zc.sourcefactory.tests import setUp
from zc.sourcefactory.tests import tearDown

Expand All @@ -25,8 +24,8 @@ def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
'token.txt', setUp=setUp, tearDown=tearDown,
checker=checker, optionflags=doctest.ELLIPSIS),
optionflags=doctest.ELLIPSIS),
doctest.DocFileSuite(
'README.txt', setUp=setUp, tearDown=tearDown,
checker=checker, optionflags=doctest.ELLIPSIS),
optionflags=doctest.ELLIPSIS),
))
14 changes: 2 additions & 12 deletions src/zc/sourcefactory/browser/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""Various token adapters.
"""
import hashlib
import sys

import persistent.interfaces
import ZODB.interfaces
Expand All @@ -26,15 +25,6 @@
import zc.sourcefactory.interfaces


try:
unicode
except NameError:
# Py3: Define unicode
unicode = str

PY3 = sys.version_info[0] == 3


@zope.component.adapter(bytes)
@zope.interface.implementer(zc.sourcefactory.interfaces.IToken)
def fromString(value):
Expand All @@ -45,7 +35,7 @@ def fromString(value):
return hashlib.md5(value).hexdigest()


@zope.component.adapter(unicode)
@zope.component.adapter(str)
@zope.interface.implementer(zc.sourcefactory.interfaces.IToken)
def fromUnicode(value):
value = value.encode("utf-8")
Expand Down Expand Up @@ -86,4 +76,4 @@ def fromPersistent(value):
@zope.interface.implementer(zc.sourcefactory.interfaces.IToken)
def fromInterface(value):
# Interface are identified by their module path and name
return "%s.%s" % (value.__module__, value.__name__)
return "{}.{}".format(value.__module__, value.__name__)
12 changes: 6 additions & 6 deletions src/zc/sourcefactory/browser/token.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Unicode
distutils will have a encoding error in preparing upload to pypi:

>>> zc.sourcefactory.browser.token.fromUnicode(
... u'somestring with umlauts \u00F6\u00E4\u00FC')
... 'somestring with umlauts \u00F6\u00E4\u00FC')
'45dadc304e0d6ae7f4864368bad74951'

Integer
Expand All @@ -48,7 +48,7 @@ be added to the database of it's __parent__:
>>> p1 = PersistentDummy()
>>> p1.__parent__ = root
>>> zc.sourcefactory.browser.token.fromPersistent(p1)
u'0x01'
'0x01'

If an object has no parent, we fail:

Expand All @@ -69,18 +69,18 @@ attribute:
>>> p3p._p_jar
Traceback (most recent call last):
...
ForbiddenAttribute: ('_p_jar', <builtins.PersistentDummy object at 0x...>)
zope.security.interfaces.ForbiddenAttribute: ('_p_jar', <builtins.PersistentDummy object at 0x...>)

>>> zc.sourcefactory.browser.token.fromPersistent(p3p)
u'0x02'
'0x02'


As a side-effect `p3` now has an _p_oid assigned. When an object already has
an OID the connection is not queried, so a __parent__ would not be necessary:

>>> del p3.__parent__
>>> zc.sourcefactory.browser.token.fromPersistent(p3p)
u'0x02'
'0x02'


Interfaces
Expand All @@ -90,4 +90,4 @@ Interfaces
>>> class I(Interface):
... pass
>>> zc.sourcefactory.browser.token.fromInterface(I)
'__builtin__.I'
'builtins.I'
4 changes: 2 additions & 2 deletions src/zc/sourcefactory/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@zope.interface.implementer(zc.sourcefactory.interfaces.ISourceFactory)
class BasicSourceFactory(object):
class BasicSourceFactory:
"""Abstract base class for a source factory.
Implementors must provide an implementation for `getValues`.
Expand Down Expand Up @@ -56,7 +56,7 @@ def __new__(cls, *args, **kw):


@zope.interface.implementer(zope.schema.interfaces.IContextSourceBinder)
class FactoredContextualSourceBinder(object):
class FactoredContextualSourceBinder:
"""A context source binder for factored sources."""

def __init__(self, factory, source_class):
Expand Down
4 changes: 2 additions & 2 deletions src/zc/sourcefactory/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@zope.interface.implementer(zope.schema.interfaces.IContextSourceBinder)
class ValueMappingSourceContextBinder(object):
class ValueMappingSourceContextBinder:

def __init__(self, base, map):
self.base = base
Expand All @@ -33,7 +33,7 @@ def __call__(self, context):


@zope.interface.implementer(zope.schema.interfaces.IIterableSource)
class ValueMappingSource(object):
class ValueMappingSource:

def __init__(self, base, map):
self.base = base
Expand Down
2 changes: 1 addition & 1 deletion src/zc/sourcefactory/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@zope.interface.implementer(zope.schema.interfaces.IContextSourceBinder)
class NamedSource(object):
class NamedSource:
"""Factory for named sources.
This is a generic thin wrapper to look up sources by name.
Expand Down
22 changes: 8 additions & 14 deletions src/zc/sourcefactory/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@
import zc.sourcefactory.interfaces


try:
unicode
except NameError:
# PY3: Define unicode
unicode = str

# Term policies


@zope.interface.implementer(zc.sourcefactory.interfaces.ITermPolicy)
class BasicTermPolicy(object):
class BasicTermPolicy:
"""A basic term policy.
createTerm creates a FactoredTerm object.
Expand All @@ -59,7 +53,7 @@ def getTitle(self, value):
elif isinstance(value, bytes):
title = value.decode()
else:
title = unicode(value)
title = str(value)
return title


Expand All @@ -73,17 +67,17 @@ class BasicContextualTermPolicy(BasicTermPolicy):
"""

def createTerm(self, context, source, value, title, token, request):
return super(BasicContextualTermPolicy, self).createTerm(
return super().createTerm(
source, value, title, token, request)

def getTitle(self, context, value):
return super(BasicContextualTermPolicy, self).getTitle(value)
return super().getTitle(value)


# Token policies

@zope.interface.implementer(zc.sourcefactory.interfaces.ITokenPolicy)
class BasicTokenPolicy(object):
class BasicTokenPolicy:
"""A basic token policy.
getToken adapts the value to IToken
Expand Down Expand Up @@ -118,11 +112,11 @@ def getValue(self, context, source, token):
raise KeyError("No value with token '%s'" % token)

def getToken(self, context, value):
return super(BasicContextualTokenPolicy, self).getToken(value)
return super().getToken(value)


@zope.interface.implementer(zc.sourcefactory.interfaces.ITokenPolicy)
class IntIdTokenPolicy(object):
class IntIdTokenPolicy:
"""A token policy based on intids."""

def getValue(self, source, token):
Expand Down Expand Up @@ -150,7 +144,7 @@ def intids(self):
# Value policies

@zope.interface.implementer(zc.sourcefactory.interfaces.IValuePolicy)
class BasicValuePolicy(object):
class BasicValuePolicy:
"""An abstract basic value policy.
`getValues()` is not implemented.
Expand Down
2 changes: 1 addition & 1 deletion src/zc/sourcefactory/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


@zope.interface.implementer(zc.sourcefactory.interfaces.IFactoredSource)
class FactoredSource(object):
class FactoredSource:
"""An iterable source that was created from a source factory."""

factory = None
Expand Down
Loading

0 comments on commit 812697c

Please sign in to comment.