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 6, 2023
1 parent e10efa0 commit 4d51360
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 80 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read(filepath):
namespace_packages=['zc'],
url='https://github.com/zopefoundation/zc.form',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
author_email='zope-dev@zope.dev',
include_package_data=True,
description=(
'Extra browser widgets and alternative approaches for zope.formlib.'),
Expand Down Expand Up @@ -66,10 +66,10 @@ def read(filepath):
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope :: 3',
],
python_requires='>=3.7',
install_requires=[
'pytz',
'setuptools',
'six',
'zc.sourcefactory',
'zope.browserpage',
'zope.cachedescriptors',
Expand Down
2 changes: 1 addition & 1 deletion src/zc/form/browser/combinationwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def widgets(self):
return res

def setPrefix(self, prefix):
super(CombinationWidget, self).setPrefix(prefix)
super().setPrefix(prefix)
for w in self.widgets:
w.setPrefix(self.name + ".")

Expand Down
17 changes: 4 additions & 13 deletions src/zc/form/browser/exceptionviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Views for exceptions used by the Schema product
"""Views for exceptions used by the Schema product."""

$Id: exceptionviews.py 3629 2005-10-06 21:01:27Z gary $
"""

import six
from html import escape

from zope import component
from zope import i18n
Expand All @@ -28,14 +25,8 @@
from zope.schema.interfaces import ValidationError


if six.PY3:
from html import escape
else: # pragma: no cover
from cgi import escape


@interface.implementer(IWidgetInputErrorView)
class AbstractErrorView(object):
class AbstractErrorView:
"""Base error view."""

def __init__(self, context, request):
Expand All @@ -45,7 +36,7 @@ def snippet(self):
"""Convert an invariant error to an html snippet."""
msg = self.context.args[0]
msg = i18n.translate(msg, context=self.request, default=msg)
return u'<span class="error">%s</span>' % escape(six.text_type(msg))
return '<span class="error">%s</span>' % escape(str(msg))


@component.adapter(ValidationError, IBrowserRequest)
Expand Down
2 changes: 1 addition & 1 deletion src/zc/form/browser/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def beforeRender(self):
whether or not the form is actually rendered: check self.halt_rendering
if you need to perform different behavior in this circumstance."""

def __call__(template_usage=u'', *args, **kw):
def __call__(template_usage='', *args, **kw):
"""a dispatcher to button actions and renderer of the form.
__call__ searches the request for each of the ids in the buttons
Expand Down
12 changes: 4 additions & 8 deletions src/zc/form/browser/mruwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#
##############################################################################
"""source input widget with most recently used (MRU) value support"""
import html

import persistent.list
import zc.resourcelibrary
import zope.annotation.interfaces
Expand All @@ -22,12 +24,6 @@
from zope.formlib.source import SourceInputWidget


try:
from html import escape as html_escape
except ImportError: # PY2
from cgi import escape as html_escape


class MruSourceInputWidget(SourceInputWidget):
ANNOTATION_KEY = 'zc.form.browser.mruwidget'

Expand Down Expand Up @@ -127,9 +123,9 @@ def __call__(self):
else:
selected = ''
result.append(' <option value="%s"%s>%s</option>'
% (html_escape(mru_term.token),
% (html.escape(mru_term.token),
selected,
html_escape(mru_term.title)))
html.escape(mru_term.title)))

result.append('</select>')

Expand Down
2 changes: 1 addition & 1 deletion src/zc/form/browser/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import zope.pagetemplate.pagetemplatefile


class DummyMacros(object):
class DummyMacros:
"""Dummy standard macros to make zope.formlib pagetemplates happy."""

def __getitem__(self, key):
Expand Down
8 changes: 4 additions & 4 deletions src/zc/form/browser/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@


@interface.implementer(zope.schema.interfaces.ISource)
class AvailableColors(object):
class AvailableColors:

def __contains__(self, value):
return value in colors


@interface.implementer(zope.schema.interfaces.ITitledTokenizedTerm)
class Term(object):
class Term:

def __init__(self, title, token):
self.title = title
Expand All @@ -46,7 +46,7 @@ def __init__(self, title, token):
@component.adapter(zope.schema.interfaces.ISource,
zope.publisher.interfaces.browser.IBrowserRequest)
@interface.implementer(zope.browser.interfaces.ITerms)
class ColorTerms(object):
class ColorTerms:
"""Term and value support needed by query widgets."""

def __init__(self, source, request):
Expand All @@ -67,7 +67,7 @@ def getValue(self, token):
@component.adapter(zope.schema.interfaces.ISource,
zope.publisher.interfaces.browser.IBrowserRequest)
@interface.implementer(zope.formlib.interfaces.ISourceQueryView)
class SimpleColorSourceQueryView(object):
class SimpleColorSourceQueryView:

def __init__(self, source, request):
self.context = source
Expand Down
47 changes: 20 additions & 27 deletions src/zc/form/browser/tests/test_unittest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
Expand Down Expand Up @@ -44,14 +43,8 @@
class TestUnionWidget(
zope.component.testing.PlacelessSetup, unittest.TestCase):

assertRegex = getattr(unittest.TestCase, 'assertRegex',
unittest.TestCase.assertRegexpMatches) # PY2

assertNotRegex = getattr(unittest.TestCase, 'assertNotRegex',
unittest.TestCase.assertNotRegexpMatches) # PY2

def setUp(self):
super(TestUnionWidget, self).setUp()
super().setUp()
# XXX cheating: should not rely on these. :-/
component.provideAdapter(
TextWidget, (ITextLine, IBrowserRequest), IInputWidget)
Expand All @@ -67,9 +60,9 @@ def setUp(self):
def test_render(self):
request = TestRequest()
field = Union(
(TextLine(title=u"Name", min_length=5),
Int(title=u"Age", min=0)),
title=u"Simple Identifier",
(TextLine(title="Name", min_length=5),
Int(title="Age", min=0)),
title="Simple Identifier",
__name__='identifier')
widget = UnionWidget(field, request)
widget.setPrefix('field')
Expand All @@ -88,9 +81,9 @@ def test_render(self):
self.assertNotRegex(output, r'''id=["']field.identifier-02['"]''')
self.assertNotRegex(output, r'''checked\s*=\s*['"]checked['"]''')
field = Union(
(TextLine(title=u"Name", min_length=5),
Int(title=u"Age", min=0)),
title=u"Simple Identifier",
(TextLine(title="Name", min_length=5),
Int(title="Age", min=0)),
title="Simple Identifier",
__name__='identifier',
required=False)
widget = UnionWidget(field, request)
Expand All @@ -106,12 +99,12 @@ def test_use_default_for_not_selected(self):
# value of None
field = Union(
(zc.form.field.TextLine(
title=u"New Password", missing_value=u'',
default_getter=lambda x: u'secret password'),
title="New Password", missing_value='',
default_getter=lambda x: 'secret password'),
zc.form.field.Option(
title=u"No Change", value='no change')),
title=u"Change Password",
missing_value=u'',
title="No Change", value='no change')),
title="Change Password",
missing_value='',
use_default_for_not_selected=True,
__name__='identifier')
widget = UnionWidget(field, request)
Expand All @@ -137,16 +130,16 @@ def test_evaluate(self):
request = TestRequest()
request.form.update({
'field.identifier-marker': 'x',
'field.identifier.unioned_00': u'Foo Bar',
'field.identifier.unioned_00': 'Foo Bar',
'field.identifier': '0'})
field = Union(
(TextLine(title=u"Name", min_length=5),
Int(title=u"Age", min=0)),
title=u"Simple Identifier",
(TextLine(title="Name", min_length=5),
Int(title="Age", min=0)),
title="Simple Identifier",
__name__='identifier')
widget = UnionWidget(field, request)
widget.setPrefix('field')
self.assertEqual(widget.loadValueFromRequest(), u'Foo Bar')
self.assertEqual(widget.loadValueFromRequest(), 'Foo Bar')


class TestInterfaces(unittest.TestCase):
Expand All @@ -169,14 +162,14 @@ def test_exceptionviews__ValidationErrorView__1(self):

def test_exceptionviews__ValidationErrorView__2(self):
"""It converts also unicode an html snippet."""
err = ValidationError(u"Fälscher!")
err = ValidationError("Fälscher!")
view = ValidationErrorView(err, None)
self.assertEqual(
view.snippet(), u'<span class="error">Fälscher!</span>')
view.snippet(), '<span class="error">Fälscher!</span>')

def test_exceptionviews__ValidationErrorView__3(self):
"""It quotes HTML characters correctly."""
err = ValidationError(u"The <error> & me.")
err = ValidationError("The <error> & me.")
view = ValidationErrorView(err, None)
self.assertEqual(
view.snippet(),
Expand Down
6 changes: 3 additions & 3 deletions src/zc/form/browser/tzwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
class TimeZoneWidget(zc.form.browser.mruwidget.MruSourceInputWidget):

def getMostRecentlyUsedTerms(self):
mru = super(TimeZoneWidget, self).getMostRecentlyUsedTerms()
mru = super().getMostRecentlyUsedTerms()
# add ones from locale
territory = self.request.locale.id.territory
if territory:
Expand All @@ -55,7 +55,7 @@ def getMostRecentlyUsedTerms(self):
except KeyError:
pass
else:
already = set(term.token for term in mru)
already = {term.token for term in mru}
additional = sorted(t for t in choices if t not in already)
mru.extend(zc.form.interfaces.Term(t.replace('_', ' '), t)
for t in additional)
Expand All @@ -65,7 +65,7 @@ def getMostRecentlyUsedTerms(self):
@component.adapter(zc.form.interfaces.AvailableTimeZones,
zope.publisher.interfaces.browser.IBrowserRequest)
@interface.implementer(zope.formlib.interfaces.ISourceQueryView)
class TimeZoneQueryView(object):
class TimeZoneQueryView:

def __init__(self, source, request):
self.context = source
Expand Down
8 changes: 3 additions & 5 deletions src/zc/form/browser/unionwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
##############################################################################
"""Union widget"""

import six

from zope import component
from zope.browserpage import ViewPageTemplateFile
from zope.formlib import namedtemplate
Expand All @@ -33,7 +31,7 @@ def __call__(self):
return None


class NotChosenWidget(object):
class NotChosenWidget:
error = name = None
required = False

Expand Down Expand Up @@ -117,15 +115,15 @@ def render(self, value):
widget.setPrefix(self.name)
choices.append(
{'selected': selected, 'identifier': identifier,
'widget': widget, 'value': six.text_type(ix)})
'widget': widget, 'value': str(ix)})
if not field.required:
ix += 1
selected = chosen_field is None
identifier = "%s-%02d" % (self.name, ix)
widget = NotChosenWidget(self.no_value_label, self.no_value_hint)
choices.append(
{'selected': selected, 'identifier': identifier,
'widget': widget, 'value': six.text_type(ix)})
'widget': widget, 'value': str(ix)})
return self.template(choices=choices)


Expand Down
6 changes: 3 additions & 3 deletions src/zc/form/browser/widgetapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(self, field, vocabulary, request):
# only allow this to happen for a bound field
assert field.context is not None
self.vocabulary = vocabulary
super(BaseVocabularyWidget, self).__init__(field, request)
super().__init__(field, request)

# Helpers used by the vocabulary widget machinery;
# these should not be overridden.
Expand Down Expand Up @@ -196,7 +196,7 @@ def loadValueFromRequest(self):
value = self.queryview.performAction(value)
return value
"""
return super(BaseVocabularyWidget, self).loadValueFromRequest()
return super().loadValueFromRequest()

# Convenience method:

Expand Down Expand Up @@ -280,7 +280,7 @@ class BaseVocabularyListDisplay(BaseVocabularyMultiDisplay):
containerElementType = "ol"


class BaseQueryView(object):
class BaseQueryView:

name = None
widget = None
Expand Down

0 comments on commit 4d51360

Please sign in to comment.