mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
gh-76007: Deprecate __version__ attribute in http.server (#142658)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
This commit is contained in:
parent
e02a35c365
commit
170dac291e
6 changed files with 26 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ Pending removal in Python 3.20
|
|||
- :mod:`csv`
|
||||
- :mod:`!ctypes.macholib`
|
||||
- :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
|
||||
- :mod:`http.server`
|
||||
- :mod:`imaplib`
|
||||
- :mod:`ipaddress`
|
||||
- :mod:`json`
|
||||
|
|
|
|||
|
|
@ -1026,6 +1026,7 @@ New deprecations
|
|||
- :mod:`csv`
|
||||
- :mod:`!ctypes.macholib`
|
||||
- :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
|
||||
- :mod:`http.server`
|
||||
- :mod:`imaplib`
|
||||
- :mod:`ipaddress`
|
||||
- :mod:`json`
|
||||
|
|
|
|||
|
|
@ -61,8 +61,6 @@ XXX To do:
|
|||
# (Actually, the latter is only true if you know the server configuration
|
||||
# at the time the request was made!)
|
||||
|
||||
__version__ = "0.6"
|
||||
|
||||
__all__ = [
|
||||
"HTTPServer", "ThreadingHTTPServer",
|
||||
"HTTPSServer", "ThreadingHTTPSServer",
|
||||
|
|
@ -280,7 +278,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
|
|||
# The server software version. You may want to override this.
|
||||
# The format is multiple whitespace-separated strings,
|
||||
# where each string is of the form name[/version].
|
||||
server_version = "BaseHTTP/" + __version__
|
||||
server_version = "BaseHTTP"
|
||||
|
||||
error_message_format = DEFAULT_ERROR_MESSAGE
|
||||
error_content_type = DEFAULT_ERROR_CONTENT_TYPE
|
||||
|
|
@ -690,7 +688,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
|||
|
||||
"""
|
||||
|
||||
server_version = "SimpleHTTP/" + __version__
|
||||
server_version = "SimpleHTTP"
|
||||
index_pages = ("index.html", "index.htm")
|
||||
extensions_map = _encodings_map_default = {
|
||||
'.gz': 'application/gzip',
|
||||
|
|
@ -1080,5 +1078,14 @@ def _main(args=None):
|
|||
)
|
||||
|
||||
|
||||
def __getattr__(name):
|
||||
if name == "__version__":
|
||||
from warnings import _deprecated
|
||||
|
||||
_deprecated("__version__", remove=(3, 20))
|
||||
return "0.6" # Do not change
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
_main()
|
||||
|
|
|
|||
|
|
@ -1560,6 +1560,16 @@ class CommandLineRunTimeTestCase(unittest.TestCase):
|
|||
self.assertEqual(res, self.served_data)
|
||||
|
||||
|
||||
class TestModule(unittest.TestCase):
|
||||
def test_deprecated__version__(self):
|
||||
with self.assertWarnsRegex(
|
||||
DeprecationWarning,
|
||||
"'__version__' is deprecated and slated for removal in Python 3.20",
|
||||
) as cm:
|
||||
getattr(http.server, "__version__")
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
|
||||
def setUpModule():
|
||||
unittest.addModuleCleanup(os.chdir, os.getcwd())
|
||||
|
||||
|
|
|
|||
|
|
@ -583,7 +583,7 @@ would raise an error.
|
|||
.. nonce: peEgcr
|
||||
.. section: Library
|
||||
|
||||
Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.
|
||||
Deprecate ``__version__`` from :mod:`imaplib`. Patch by Hugo van Kemenade.
|
||||
|
||||
..
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Deprecate ``__version__`` from :mod:`http.server`. Patch by Hugo van
|
||||
Kemenade.
|
||||
Loading…
Add table
Add a link
Reference in a new issue