]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
closes bpo-46736: SimpleHTTPRequestHandler now uses HTML5. (GH-31533)
authorDong-hee Na <donghee.na92@gmail.com>
Wed, 23 Feb 2022 17:59:32 +0000 (02:59 +0900)
committerGitHub <noreply@github.com>
Wed, 23 Feb 2022 17:59:32 +0000 (09:59 -0800)
Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
Lib/http/server.py
Misc/NEWS.d/next/Library/2022-02-24-01-49-38.bpo-46736.NJcoWO.rst [new file with mode: 0644]

index 194a503c45f7524d26e590399e4b4d0c148b0584..a6100d4829751e04d9fc4b4ee4ca3a536c4f8688 100644 (file)
@@ -109,11 +109,10 @@ from http import HTTPStatus
 
 # Default error message template
 DEFAULT_ERROR_MESSAGE = """\
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
-        "http://www.w3.org/TR/html4/strict.dtd">
-<html>
+<!DOCTYPE HTML>
+<html lang="en">
     <head>
-        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+        <meta charset="utf-8">
         <title>Error response</title>
     </head>
     <body>
@@ -777,14 +776,13 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
             displaypath = urllib.parse.unquote(path)
         displaypath = html.escape(displaypath, quote=False)
         enc = sys.getfilesystemencoding()
-        title = 'Directory listing for %s' % displaypath
-        r.append('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
-                 '"http://www.w3.org/TR/html4/strict.dtd">')
-        r.append('<html>\n<head>')
-        r.append('<meta http-equiv="Content-Type" '
-                 'content="text/html; charset=%s">' % enc)
-        r.append('<title>%s</title>\n</head>' % title)
-        r.append('<body>\n<h1>%s</h1>' % title)
+        title = f'Directory listing for {displaypath}'
+        r.append('<!DOCTYPE HTML>')
+        r.append('<html lang="en">')
+        r.append('<head>')
+        r.append(f'<meta charset="{enc}">')
+        r.append(f'<title>{title}</title>\n</head>')
+        r.append(f'<body>\n<h1>{title}</h1>')
         r.append('<hr>\n<ul>')
         for name in list:
             fullname = os.path.join(path, name)
diff --git a/Misc/NEWS.d/next/Library/2022-02-24-01-49-38.bpo-46736.NJcoWO.rst b/Misc/NEWS.d/next/Library/2022-02-24-01-49-38.bpo-46736.NJcoWO.rst
new file mode 100644 (file)
index 0000000..fca7780
--- /dev/null
@@ -0,0 +1,2 @@
+:class:`~http.server.SimpleHTTPRequestHandler` now uses HTML5 grammar. Patch
+by Dong-hee Na.