Skip to content

Commit

Permalink
Configuring for pure-python
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Sep 25, 2024
1 parent 578c35a commit f928d03
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 107 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
7.1 (unreleased)
================

- Drop support for Python 3.7.

- Add support for Python 3.12.

- Fix test suite to use proper line endings (\r\n) in raw multipart/form-data
HTTP requests, because multipart 1.0.0 is stricter about line endings.
Fixes `issue <https://github.com/zopefoundation/zope.publisher/issues/74>`_.
Expand Down
57 changes: 31 additions & 26 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# zope.app.apidoc documentation build configuration file, created by
# sphinx-quickstart on Tue Sep 13 15:00:43 2016.
Expand All @@ -21,7 +20,10 @@
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys

import pkg_resources


sys.path.append(os.path.abspath('../src'))
rqmt = pkg_resources.require('zope.publisher')[0]

Expand Down Expand Up @@ -59,9 +61,9 @@
master_doc = 'index'

# General information about the project.
project = u'zope.publisher'
copyright = u'2017, Zope Community'
author = u'Zope Community'
project = 'zope.publisher'
copyright = '2017, Zope Community'
author = 'Zope Community'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -156,8 +158,8 @@
# html_logo = None

# The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# the docs. This file should be a Windows icon file (.ico) being 16x16 or
# 32x32 pixels large.
#
# html_favicon = None

Expand Down Expand Up @@ -249,29 +251,29 @@
# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'zopepublisher.tex', u'zope.publisher Documentation',
u'Zope Community', 'manual'),
(master_doc, 'zopepublisher.tex', 'zope.publisher Documentation',
'Zope Community', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -312,7 +314,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'zopepublisher', u'zope.publisher Documentation',
(master_doc, 'zopepublisher', 'zope.publisher Documentation',
[author], 1)
]

Expand All @@ -327,7 +329,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'zopepublisher', u'zope.publisher Documentation',
(master_doc, 'zopepublisher', 'zope.publisher Documentation',
author, 'zopepublisher', 'One line description of project.',
'Miscellaneous'),
]
Expand Down Expand Up @@ -360,10 +362,13 @@
'https://zopesite.readthedocs.io/en/latest/': None,
}

extlinks = {'issue': ('https://github.com/zopefoundation/zope.publisher/issues/%s',
'issue #'),
'pr': ('https://github.com/zopefoundation/zope.publisher/pull/%s',
'pull request #')}
extlinks = {
'issue': (
'https://github.com/zopefoundation/zope.publisher/issues/%s',
'issue #'),
'pr': (
'https://github.com/zopefoundation/zope.publisher/pull/%s',
'pull request #')}

autodoc_default_flags = ['members', 'show-inheritance']
autoclass_content = 'both'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def read(*rnames):
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
Expand Down Expand Up @@ -95,5 +95,5 @@ def read(*rnames):
entry_points=entry_points,
include_package_data=True,
zip_safe=False,
python_requires='>=3.7',
python_requires='>=3.8',
)
30 changes: 15 additions & 15 deletions src/zope/publisher/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ def field2boolean(v):


type_converters = {
'float': field2float,
'int': field2int,
'long': field2long,
'string': field2string,
'float': field2float,
'int': field2int,
'long': field2long,
'string': field2string,
'required': field2required,
'tokens': field2tokens,
'lines': field2lines,
'text': field2text,
'boolean': field2boolean,
'tokens': field2tokens,
'lines': field2lines,
'text': field2text,
'boolean': field2boolean,
}

get_converter = type_converters.get
Expand Down Expand Up @@ -230,7 +230,7 @@ def __repr__(self):
items = list(self.__dict__.items())
items.sort()
return ("{"
+ ", ".join(["{}: {!r}".format(key, value)
+ ", ".join([f"{key}: {value!r}"
for key, value in items]) + "}")


Expand Down Expand Up @@ -689,7 +689,7 @@ def __init__(self, aFieldStorage):
if isinstance(filename, bytes):
filename = filename.decode('UTF-8')
# fix for IE full paths
filename = filename[filename.rfind('\\')+1:].strip()
filename = filename[filename.rfind('\\') + 1:].strip()
self.filename = filename

def release(self):
Expand All @@ -711,10 +711,10 @@ def __init__(self, body_instream=None, environ=None, form=None,
skin=None, **kw):

_testEnv = {
'SERVER_URL': 'http://127.0.0.1',
'HTTP_HOST': '127.0.0.1',
'CONTENT_LENGTH': '0',
'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
'SERVER_URL': 'http://127.0.0.1',
'HTTP_HOST': '127.0.0.1',
'CONTENT_LENGTH': '0',
'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
}

if environ is not None:
Expand Down Expand Up @@ -846,7 +846,7 @@ def isHTML(str):
return True
if s.startswith('<!--'):
idx = s.find('<html')
return idx > 0 and (s[idx+5:idx+6] in ' >')
return idx > 0 and (s[idx + 5:idx + 6] in ' >')
else:
return False

Expand Down
10 changes: 5 additions & 5 deletions src/zope/publisher/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def __deduceServerURL(self):
else:
host = hostname

return '{}://{}'.format(protocol, host)
return f'{protocol}://{host}'

def _parseCookies(self, text, result=None):
"""Parse 'text' and return found cookies as 'result' dictionary."""
Expand Down Expand Up @@ -609,8 +609,8 @@ def getApplicationURL(self, depth=0, path_only=False):

def setApplicationServer(self, host, proto='http', port=None):
if port and str(port) != DEFAULT_PORTS.get(proto):
host = '{}:{}'.format(host, port)
self._app_server = '{}://{}'.format(proto, host)
host = f'{host}:{port}'
self._app_server = f'{proto}://{host}'
zope.event.notify(HTTPVirtualHostChangedEvent(self))

def shiftNameToApplication(self):
Expand Down Expand Up @@ -862,7 +862,7 @@ def _implicitResult(self, body):
if (major, minor) != ('application', 'json'):
# The RFC says this is UTF-8, and the type has no params.
params['charset'] = encoding
content_type = "{}/{}".format(major, minor)
content_type = f"{major}/{minor}"
if params:
content_type += ";"
content_type += ";".join(k + "=" + v
Expand Down Expand Up @@ -996,7 +996,7 @@ def extract_host(url):
if ':' not in host:
port = DEFAULT_PORTS.get(scheme)
if port:
host = '{}:{}'.format(host, port)
host = f'{host}:{port}'
return host


Expand Down
2 changes: 1 addition & 1 deletion src/zope/publisher/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __str__(self):
ob = repr(self.ob)
except: # noqa: E722 do not use bare 'except'
ob = 'unprintable object'
return 'Object: {}, name: {!r}'.format(ob, self.name)
return f'Object: {ob}, name: {self.name!r}'


class IDebugError(ITraversalException):
Expand Down
2 changes: 1 addition & 1 deletion src/zope/publisher/interfaces/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,4 @@ def __init__(self, object, request):
self.request = request

def __str__(self):
return "{!r}, {!r}".format(self.object, self.request)
return f"{self.object!r}, {self.request!r}"
2 changes: 1 addition & 1 deletion src/zope/publisher/tests/basetestiapplicationrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ def testGetAndDefaultInMapping(self):

# Now make sure that request.get can actually deal with return
# self back to us correctly:
self.assertTrue(request.get('REQUEST') is request)
self.assertIs(request.get('REQUEST'), request)
6 changes: 3 additions & 3 deletions src/zope/publisher/tests/basetestipublicationrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def testHoldCloseAndGetResponse(self):
rcresource2 = getrefcount(resource2)
request.hold(resource2)

self.assertTrue(getrefcount(resource, 1) > rcresource)
self.assertTrue(getrefcount(resource2, 1) > rcresource2)
self.assertGreater(getrefcount(resource, 1), rcresource)
self.assertGreater(getrefcount(resource2, 1), rcresource2)
self.assertFalse(resource2.released)

request.close()

self.assertTrue(resource2.released)
# Responses are not unreferenced during close()
self.assertTrue(getrefcount(response) >= rcresponse)
self.assertGreaterEqual(getrefcount(response), rcresponse)
self.assertEqual(getrefcount(resource), rcresource)
self.assertEqual(getrefcount(resource2), rcresource2)

Expand Down
2 changes: 1 addition & 1 deletion src/zope/publisher/tests/test_baserequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ISomeSkin(Interface):
retried = request.retry()

# the requests are not the same
self.assertTrue(request is not retried)
self.assertIsNot(request, retried)
# the requests both provide the default skin
self.assertTrue(ISomeSkin.providedBy(request))
self.assertTrue(ISomeSkin.providedBy(retried))
30 changes: 15 additions & 15 deletions src/zope/publisher/tests/test_browserrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ def __init__(self, *args, **kw):
class BrowserTests(HTTPTests):

_testEnv = {
'PATH_INFO': '/folder/item',
'QUERY_STRING': 'a=5&b:int=6',
'SERVER_URL': 'http://foobar.com',
'HTTP_HOST': 'foobar.com',
'CONTENT_LENGTH': '0',
'HTTP_AUTHORIZATION': 'Should be in accessible',
'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
'HTTP_OFF_THE_WALL': "Spam 'n eggs",
'PATH_INFO': '/folder/item',
'QUERY_STRING': 'a=5&b:int=6',
'SERVER_URL': 'http://foobar.com',
'HTTP_HOST': 'foobar.com',
'CONTENT_LENGTH': '0',
'HTTP_AUTHORIZATION': 'Should be in accessible',
'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
'HTTP_OFF_THE_WALL': "Spam 'n eggs",
'HTTP_ACCEPT_CHARSET': 'ISO-8859-1, UTF-8;q=0.66, UTF-16;q=0.33',
}

Expand Down Expand Up @@ -325,7 +325,7 @@ def testFormMultipartUTF8(self):
])
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("汉语/漢語", request.form['street'])

def testFormMultipartFilenameUTF8(self):
Expand Down Expand Up @@ -403,7 +403,7 @@ def testFormURLEncodedUTF8(self):
b'&street=\xe6\xb1\x89\xe8\xaf\xad/\xe6\xbc\xa2\xe8\xaa\x9e')
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("汉语/漢語", request.form['street'])

def testFormURLEncodedUTF8ContentType(self):
Expand All @@ -416,7 +416,7 @@ def testFormURLEncodedUTF8ContentType(self):
b'&street=\xe6\xb1\x89\xe8\xaf\xad/\xe6\xbc\xa2\xe8\xaa\x9e')
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("汉语/漢語", request.form['street'])

def testFormQueryStringUTF8(self):
Expand All @@ -426,7 +426,7 @@ def testFormQueryStringUTF8(self):
extra = {'QUERY_STRING': query_string}
request = self._createRequest(extra)
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("汉语/漢語", request.form['street'])

def testFormURLEncodedLatin1(self):
Expand All @@ -438,7 +438,7 @@ def testFormURLEncodedLatin1(self):
body = b'a=5&b:int=6&street=K\xf6hlerstra\xdfe'
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("K\xf6hlerstra\xdfe", request.form['street'])

def testFormURLEncodedLatin7(self):
Expand All @@ -450,7 +450,7 @@ def testFormURLEncodedLatin7(self):
body = 'a=5&b:int=6&street=Ąžuolyno'.encode('iso-8859-13')
request = self._createRequest(extra, body)
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("Ąžuolyno", request.form['street'])

def testFormNoEncodingUsesUTF8(self):
Expand All @@ -464,7 +464,7 @@ def testFormNoEncodingUsesUTF8(self):
# many mainstream browsers do not send HTTP_ACCEPT_CHARSET
del request._environ['HTTP_ACCEPT_CHARSET']
publish(request)
self.assertTrue(isinstance(request.form["street"], str))
self.assertIsInstance(request.form["street"], str)
self.assertEqual("K\xf6hlerstra\xdfe", request.form['street'])

def testFormAcceptsStarButNotUTF8(self):
Expand Down
Loading

0 comments on commit f928d03

Please sign in to comment.