Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/deprecations/pending-removal-in-3.20.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@ Pending removal in Python 3.20
- :mod:`tabnanny`
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`wsgiref.simple_server`
- :mod:`zlib`

(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
1 change: 1 addition & 0 deletions Doc/whatsnew/3.15.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -1039,6 +1039,7 @@ New deprecations
- :mod:`tabnanny`
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`wsgiref.simple_server`
- :mod:`zlib`

(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
Expand Down
16 changes: 14 additions & 2 deletions Lib/test/test_wsgiref.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ def check_hello(self, out, has_length=True):
sys.version.split()[0])
self.assertEqual(out,
("HTTP/1.0 200 OK\r\n"
"Server: WSGIServer/0.2 " + pyver +"\r\n"
"Server: WSGIServer " + pyver +"\r\n"
"Content-Type: text/plain\r\n"
"Date: Mon, 05 Jun 2006 18:49:54 GMT\r\n" +
(has_length and "Content-Length: 13\r\n" or "") +
Expand DownExpand Up@@ -206,7 +206,7 @@ def app(e, s):
pyver = py + b"/" + ver
self.assertEqual(
b"HTTP/1.0 200 OK\r\n"
b"Server: WSGIServer/0.2 "+ pyver + b"\r\n"
b"Server: WSGIServer " + pyver + b"\r\n"
b"Content-Type: text/plain; charset=utf-8\r\n"
b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n"
b"\r\n"
Expand DownExpand Up@@ -840,5 +840,17 @@ def write(self, b):
self.assertIsNotNone(h.environ)


class TestModule(unittest.TestCase):
def test_deprecated__version__(self):
from wsgiref import simple_server

with self.assertWarnsRegex(
DeprecationWarning,
"'__version__' is deprecated and slated for removal in Python 3.20",
) as cm:
getattr(simple_server, "__version__")
self.assertEqual(cm.filename, __file__)


if __name__ == "__main__":
unittest.main()
14 changes: 11 additions & 3 deletions Lib/wsgiref/simple_server.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,11 +16,10 @@
from wsgiref.handlers import SimpleHandler
from platform import python_implementation

__version__ = "0.2"
__all__ = ['WSGIServer', 'WSGIRequestHandler', 'demo_app', 'make_server']


server_version = "WSGIServer/" + __version__
server_version = "WSGIServer"
sys_version = python_implementation() + "/" + sys.version.split()[0]
software_version = server_version + ' ' + sys_version

Expand DownExpand Up@@ -70,7 +69,7 @@ def set_app(self,application):

class WSGIRequestHandler(BaseHTTPRequestHandler):

server_version = "WSGIServer/" + __version__
server_version = "WSGIServer"

def get_environ(self):
env = self.server.base_environ.copy()
Expand DownExpand Up@@ -152,6 +151,15 @@ def make_server(
return server


def __getattr__(name):
if name == "__version__":
from warnings import _deprecated

_deprecated("__version__", remove=(3, 20))
return "0.2" # Do not change
raise AttributeError(f"module{__name__!r} has no attribute{name!r}")


if __name__ == '__main__':
with make_server('', 8000, demo_app) as httpd:
sa = httpd.socket.getsockname()
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Deprecate ``__version__`` from :mod:`wsgiref.simple_server`. Patch by Hugo
van Kemenade.
Loading