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 10, 2023
1 parent 54c7372 commit a468d6b
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 109 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

- Drop support for Python 2.7, 3.5, 3.6.

- Drop support for deprecated ``python setup.py test``.


2.5.1 (2021-04-15)
==================
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
##############################################################################
# This package is developed by the Zope Toolkit project, documented here:
# http://docs.zope.org/zopetoolkit
# https://zopetoolkit.readthedocs.io/
# When developing and releasing this package, please follow the documented
# Zope Toolkit policies as described by this documentation.
##############################################################################
Expand Down Expand Up @@ -44,7 +44,7 @@ def read(*rnames):
setup(name='zope.mimetype',
version='3.0.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
author_email='zope-dev@zope.dev',
description="A simple package for working with MIME content types",
long_description=(
read('README.rst')
Expand Down Expand Up @@ -76,6 +76,7 @@ def read(*rnames):
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
python_requires='>=3.7',
extras_require={
'test': TEST_REQUIRES,
'browser': BROWSER_REQUIRES,
Expand All @@ -97,8 +98,6 @@ def read(*rnames):
'zope.schema',
'zope.security',
],
tests_require=TEST_REQUIRES,
test_suite='zope.mimetype.tests',
include_package_data=True,
zip_safe=False,
)
9 changes: 4 additions & 5 deletions src/zope/mimetype/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from __future__ import absolute_import

import codecs
import os
Expand All @@ -25,7 +24,7 @@


@interface.implementer(ICodec)
class Codec(object):
class Codec:

def __init__(self, name, title):
self.name = name
Expand All @@ -43,7 +42,7 @@ def addCodec(name, title=None):


@interface.implementer(ICharset)
class Charset(object):
class Charset:

def __init__(self, name, encoding):
self.name = name
Expand Down Expand Up @@ -82,9 +81,9 @@ def initialize(_context):
_aliases = {} # alias -> codec name
here = os.path.dirname(os.path.abspath(__file__))
fn = os.path.join(here, FILENAME)
f = open(fn, "r")
f = open(fn)

class Codec(object):
class Codec:
preferred_alias = None

def __init__(self, name):
Expand Down
12 changes: 6 additions & 6 deletions src/zope/mimetype/codec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ Preferred charsets are registered as utilities for
>>> preferred.name
'iso8859-1'
>>> sorted(component.getUtilitiesFor(ICodecPreferredCharset))
[(u'iso8859-1', <zope.mimetype.codec.Charset ...>),
(u'utf-8', <zope.mimetype.codec.Charset ...>)]
[('iso8859-1', <zope.mimetype.codec.Charset ...>),
('utf-8', <zope.mimetype.codec.Charset ...>)]

We can look up a codec by the name of its charset:

Expand All @@ -76,7 +76,7 @@ We can look up a codec by the name of its charset:
Or we can look up all codecs:

>>> sorted(component.getUtilitiesFor(ICharsetCodec))
[(u'iso8859-1', <zope.mimetype.codec.Codec ...>),
(u'latin1', <zope.mimetype.codec.Codec ...>),
(u'test', <zope.mimetype.codec.Codec ...>),
(u'utf-8', <zope.mimetype.codec.Codec ...>)]
[('iso8859-1', <zope.mimetype.codec.Codec ...>),
('latin1', <zope.mimetype.codec.Codec ...>),
('test', <zope.mimetype.codec.Codec ...>),
('utf-8', <zope.mimetype.codec.Codec ...>)]
2 changes: 1 addition & 1 deletion src/zope/mimetype/contentinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@zope.interface.implementer(zope.mimetype.interfaces.IContentInfo)
@zope.component.adapter(zope.interface.Interface)
class ContentInfo(object):
class ContentInfo:
"""Basic IContentInfo that provides information from an IContentTypeAware.
"""

Expand Down
6 changes: 3 additions & 3 deletions src/zope/mimetype/contentinfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ store some UTF-8 data in a variable::

>>> utf8_data = b"\xAB\xBB".decode("iso-8859-1").encode("utf-8")
>>> utf8_data
'\xc2\xab\xc2\xbb'
b'\xc2\xab\xc2\xbb'

We want to be able to decode the data using the `IContentInfo`
object. Let's try getting the corresponding `ICodec` object using
Expand Down Expand Up @@ -146,14 +146,14 @@ Now that that's been initialized, let's try getting the codec again::
'utf-8'

>>> codec.decode(utf8_data)
(u'\xab\xbb', 4)
('\xab\xbb', 4)

We can now check that the ``decode()`` method of the `IContentInfo` will
decode the entire data, returning the Unicode representation of the
text::

>>> ci.decode(utf8_data)
u'\xab\xbb'
'\xab\xbb'

Another possibilty, of course, is that you have content that you know
is encoded text of some sort, but you don't actually know what
Expand Down
2 changes: 1 addition & 1 deletion src/zope/mimetype/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class ContentTypeChangedEvent(zope.interface.interfaces.ObjectEvent):

def __init__(self, object, oldContentType, newContentType):
super(ContentTypeChangedEvent, self).__init__(object)
super().__init__(object)
self.newContentType = newContentType
self.oldContentType = oldContentType

Expand Down
8 changes: 4 additions & 4 deletions src/zope/mimetype/event.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ on the event set to `None`::
>>> event.changeContentType(obj, ITextPlain)
changed content type interface:
from: None
to: <InterfaceClass __builtin__.ITextPlain>
to: <InterfaceClass builtins.ITextPlain>

Calling the `~.changeContentType()` function again with the same "new"
content type interface causes no change, so the event is not fired
Expand All @@ -89,13 +89,13 @@ Providing a new interface does cause the event to be fired again::

>>> event.changeContentType(obj, IOctetStream)
changed content type interface:
from: <InterfaceClass __builtin__.ITextPlain>
to: <InterfaceClass __builtin__.IOctetStream>
from: <InterfaceClass builtins.ITextPlain>
to: <InterfaceClass builtins.IOctetStream>

Similarly, removing the content type interface triggers the event as
well::

>>> event.changeContentType(obj, None)
changed content type interface:
from: <InterfaceClass __builtin__.IOctetStream>
from: <InterfaceClass builtins.IOctetStream>
to: None
2 changes: 1 addition & 1 deletion src/zope/mimetype/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# http://www.faqs.org/rfcs/rfc2045.html
_token_re = r"[!#$%&'*+\-.\d^_`a-z{|}~]+"
_token_rx = re.compile("%s$" % _token_re)
_mime_type_rx = re.compile("%s/%s$" % (_token_re, _token_re))
_mime_type_rx = re.compile("{}/{}$".format(_token_re, _token_re))


# These helpers are used to define constraints for specific schema
Expand Down
10 changes: 5 additions & 5 deletions src/zope/mimetype/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# Base classes

class UtilitySource(object):
class UtilitySource:
"""Source of utilities providing a specific interface."""

def __init__(self):
Expand Down Expand Up @@ -61,7 +61,7 @@ def __len__(self):


@zope.interface.implementer(ITerms)
class Terms(object):
class Terms:
"""Utility to provide terms for content type interfaces."""

def __init__(self, source, request):
Expand Down Expand Up @@ -106,14 +106,14 @@ def _createTerm(self, value):


@zope.interface.implementer(zope.mimetype.interfaces.IContentTypeTerm)
class ContentTypeTerm(object):
class ContentTypeTerm:

def __init__(self, interface):
self.value = interface

@property
def token(self):
return "%s.%s" % (self.value.__module__, self.value.__name__)
return "{}.{}".format(self.value.__module__, self.value.__name__)

@property
def title(self):
Expand Down Expand Up @@ -160,7 +160,7 @@ def _createTerm(self, value):


@zope.interface.implementer(zope.mimetype.interfaces.ICodecTerm)
class CodecTerm(object):
class CodecTerm:

def __init__(self, codec):
self.value = codec
Expand Down
2 changes: 1 addition & 1 deletion src/zope/mimetype/source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The term also provides the title based on the "title" tagged value
from the interface::

>>> t.title
u'Type One'
'Type One'

Each interface provides a list of MIME types with which the interface
is associated. The term object provides access to this list::
Expand Down
4 changes: 2 additions & 2 deletions src/zope/mimetype/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ISampleContentTypeOne(zope.interface.Interface):
"""This is a sample content type interface."""


ISampleContentTypeOne.setTaggedValue("title", u"Type One")
ISampleContentTypeOne.setTaggedValue("title", "Type One")
ISampleContentTypeOne.setTaggedValue("extensions", [])
ISampleContentTypeOne.setTaggedValue("mimeTypes", ["type/one", "type/foo"])

Expand All @@ -36,7 +36,7 @@ class ISampleContentTypeTwo(zope.interface.Interface):
"""This is a sample content type interface."""


ISampleContentTypeTwo.setTaggedValue("title", u"Type Two")
ISampleContentTypeTwo.setTaggedValue("title", "Type Two")
ISampleContentTypeTwo.setTaggedValue("mimeTypes", [".ct2", ".ct3"])
ISampleContentTypeTwo.setTaggedValue("mimeTypes", ["type/two"])

Expand Down
3 changes: 0 additions & 3 deletions src/zope/mimetype/tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
Tests for codec.py.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import unittest

Expand Down
7 changes: 2 additions & 5 deletions src/zope/mimetype/tests/test_contentinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
Tests for contentinfo.py
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import unittest

Expand All @@ -38,11 +35,11 @@ def test_codec_cant_decode_all(self):
from zope.mimetype.interfaces import IContentTypeAware

@interface.implementer(IContentTypeAware)
class Content(object):
class Content:
mimeType = 'text/plain'
parameters = ()

class Codec(object):
class Codec:
def decode(self, s):
return '', 0

Expand Down
47 changes: 8 additions & 39 deletions src/zope/mimetype/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,11 @@
##############################################################################
"""Test harness for `zope.mimetype` doctests..
"""
from __future__ import print_function

import doctest
import re
import unittest

from zope.component import testing
from zope.testing import renormalizing


checker = renormalizing.RENormalizing([
# Python 3 unicode removed the "u".
(re.compile("u('.*?')"),
r"\1"),
(re.compile('u(".*?")'),
r"\1"),
# Python 3 bytes adds the "b".
(re.compile("b('.*?')"),
r"\1"),
(re.compile('b(".*?")'),
r"\1"),
# Python 3 renames builtins.
(re.compile("__builtin__"),
r"builtins"),
])


def optional_test_suite_setUp(required_module):
Expand All @@ -57,44 +37,33 @@ def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
'../retrieving_mime_types.rst',
setUp=testing.setUp, tearDown=testing.tearDown,
checker=checker),
setUp=testing.setUp, tearDown=testing.tearDown),
doctest.DocFileSuite(
'../event.rst',
setUp=testing.setUp, tearDown=testing.tearDown,
globs={'print_function': print_function},
checker=checker),
setUp=testing.setUp, tearDown=testing.tearDown),
doctest.DocFileSuite(
'../source.rst',
setUp=optional_test_suite_setUp('zope.browser'),
tearDown=testing.tearDown,
checker=checker),
tearDown=testing.tearDown),
doctest.DocFileSuite(
'../constraints.rst',
checker=checker),
'../constraints.rst'),
doctest.DocFileSuite(
'../contentinfo.rst',
setUp=testing.setUp, tearDown=testing.tearDown,
checker=checker),
setUp=testing.setUp, tearDown=testing.tearDown),
doctest.DocFileSuite(
'../typegetter.rst',
checker=checker),
'../typegetter.rst'),
doctest.DocFileSuite(
'../utils.rst',
checker=checker),
'../utils.rst'),
doctest.DocFileSuite(
'../widget.rst',
setUp=optional_test_suite_setUp('zope.publisher'),
tearDown=testing.tearDown,
checker=checker),
tearDown=testing.tearDown),
doctest.DocFileSuite(
'../codec.rst',
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
checker=checker,
),
doctest.DocFileSuite(
'../configure.rst',
setUp=testing.setUp, tearDown=testing.tearDown,
checker=checker
),
))
Loading

0 comments on commit a468d6b

Please sign in to comment.