summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2017-08-03 08:20:16 -0500
committerJason Madden <jamadden@gmail.com>2017-08-03 08:31:34 -0500
commit1427723cc0c68aae829bc5a53962840939570ee8 (patch)
tree500ac46dcacd183f6d387e044f72f34bb52a93ea /src
parentdc5f6fdd7675f9ab81ad583c4a3d5742a154e3de (diff)
downloadzope-contenttype-py36.tar.gz
Add Python 3.6, drop Python 3.3.py36
- Badges - Add coverage environment and coveralls - 100% coverage - Some simplifications to help that, including using print_function for simpler parity on Py2/Py3, and not rewriting the _token_match function at runtime (presumably this was to delay compiling a regex at import time, but other regexes are already being compiled now at import time, so the hit is minor)
Diffstat (limited to 'src')
-rw-r--r--src/zope/__init__.py2
-rw-r--r--src/zope/contenttype/__init__.py10
-rw-r--r--src/zope/contenttype/parse.py5
-rw-r--r--src/zope/contenttype/tests/testContentTypes.py16
-rw-r--r--src/zope/contenttype/tests/test_parse.py12
5 files changed, 19 insertions, 26 deletions
diff --git a/src/zope/__init__.py b/src/zope/__init__.py
index de40ea7..2cdb0e4 100644
--- a/src/zope/__init__.py
+++ b/src/zope/__init__.py
@@ -1 +1 @@
-__import__('pkg_resources').declare_namespace(__name__)
+__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
diff --git a/src/zope/contenttype/__init__.py b/src/zope/contenttype/__init__.py
index 0724a56..9208bbd 100644
--- a/src/zope/contenttype/__init__.py
+++ b/src/zope/contenttype/__init__.py
@@ -12,6 +12,7 @@
##############################################################################
"""A utility module for content-type handling.
"""
+from __future__ import print_function
import re
import os.path
import mimetypes
@@ -71,7 +72,7 @@ def guess_content_type(name='', body=b'', default=None):
else:
type = default or 'text/x-unknown-content-type'
- return type.lower(), enc and enc.lower() or None
+ return type.lower(), enc.lower() if enc else None
def add_files(filenames):
@@ -104,15 +105,12 @@ def add_files(filenames):
here = os.path.dirname(os.path.abspath(__file__))
add_files([os.path.join(here, "mime.types")])
-# Python 2/3 compatibility for testing.
-def _print(s): # pragma: NO COVER
- print(s)
def main():
items = mimetypes.types_map.items()
items = sorted(items)
for item in items:
- _print("%s:\t%s" % item)
+ print("%s:\t%s" % item)
-if __name__ == '__main__': #pragma: nocover
+if __name__ == '__main__':
main()
diff --git a/src/zope/contenttype/parse.py b/src/zope/contenttype/parse.py
index 27fde81..0436cc4 100644
--- a/src/zope/contenttype/parse.py
+++ b/src/zope/contenttype/parse.py
@@ -87,16 +87,13 @@ def _parse_params(string):
_quoted_string_match = re.compile('"(?:\\\\.|[^"\n\r\\\\])*"', re.DOTALL).match
+_token_match = re.compile("[^][ \t\n\r()<>@,;:\"/?=\\\\]+$").match
def _check_token(string):
if _token_match(string) is None:
raise ValueError('"%s" is not a valid token' % string)
return string
-def _token_match(string):
- global _token_match
- _token_match = re.compile("[^][ \t\n\r()<>@,;:\"/?=\\\\]+$").match
- return _token_match(string)
def _unescape(string):
assert string[0] == '"'
diff --git a/src/zope/contenttype/tests/testContentTypes.py b/src/zope/contenttype/tests/testContentTypes.py
index a9dad82..6afeb53 100644
--- a/src/zope/contenttype/tests/testContentTypes.py
+++ b/src/zope/contenttype/tests/testContentTypes.py
@@ -13,6 +13,7 @@
##############################################################################
"""Tests of the contenttypes extension mechanism.
"""
+from __future__ import print_function
import unittest
class ContentTypesTestCase(unittest.TestCase):
@@ -39,21 +40,22 @@ class ContentTypesTestCase(unittest.TestCase):
def test_main(self):
import zope.contenttype
- _print = zope.contenttype._print
- zope.contenttype._print = lambda s: None
+ result = []
+ zope.contenttype.print = result.append
zope.contenttype.main()
- zope.contenttype._print = _print
+ del zope.contenttype.print
+ self.assertTrue(result)
def test_guess_content_type(self):
from zope.contenttype import add_files
from zope.contenttype import guess_content_type
filename = self._getFilename('mime.types-1')
add_files([filename])
- ctype, encoding = guess_content_type(body=b'text file')
+ ctype, _encoding = guess_content_type(body=b'text file')
self.assertEqual(ctype, "text/plain")
- ctype, encoding = guess_content_type(body=b'\001binary')
+ ctype, _encoding = guess_content_type(body=b'\001binary')
self.assertEqual(ctype, "application/octet-stream")
- ctype, encoding = guess_content_type()
+ ctype, _encoding = guess_content_type()
self.assertEqual(ctype, "text/x-unknown-content-type")
@@ -114,4 +116,4 @@ class ContentTypesTestCase(unittest.TestCase):
def test_suite():
- return unittest.makeSuite(ContentTypesTestCase)
+ return unittest.defaultTestLoader.loadTestsFromName(__name__)
diff --git a/src/zope/contenttype/tests/test_parse.py b/src/zope/contenttype/tests/test_parse.py
index 04490af..2be7f83 100644
--- a/src/zope/contenttype/tests/test_parse.py
+++ b/src/zope/contenttype/tests/test_parse.py
@@ -163,18 +163,18 @@ class JoinTestCase(unittest.TestCase):
# multiple parameters given as a list maintain order:
self.assertEqual(
self._callFUT(("text", "plain",
- [("charset", "UTF-8"), ("format", "flowed")])),
+ [("charset", "UTF-8"), ("format", "flowed")])),
"text/plain;charset=UTF-8;format=flowed")
self.assertEqual(
self._callFUT(("text", "plain",
- [("format", "flowed"), ("charset", "UTF-8")])),
+ [("format", "flowed"), ("charset", "UTF-8")])),
"text/plain;format=flowed;charset=UTF-8")
def test_multi_params_dict_sorted_order(self):
# multiple parameters given as a dict are sorted by param name:
self.assertEqual(
self._callFUT(("text", "plain",
- {"charset": "UTF-8", "format": "flowed"})),
+ {"charset": "UTF-8", "format": "flowed"})),
"text/plain;charset=UTF-8;format=flowed")
def test_params_list_quoted(self):
@@ -205,8 +205,4 @@ class JoinTestCase(unittest.TestCase):
def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(ParseOrderedTestCase),
- unittest.makeSuite(ParseTestCase),
- unittest.makeSuite(JoinTestCase),
- ))
+ return unittest.defaultTestLoader.loadTestsFromName(__name__)