FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-76007: Deprecate `__version__` attribute in `wsgiref.simple_server` by hugovk · Pull Request #142675 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) .rst  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions Doc/deprecations/pending-removal-in-3.20.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff 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 Down Expand 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 Down Expand 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff 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 Down Expand 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 Down Expand 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate ``__version__`` from :mod:`wsgiref.simple_server`. Patch by Hugo
van Kemenade.
Loading

Back | FazBrowse Home | New Git URL