Skip to content

Commit 0bb40a4

Browse files
closes bpo-46736: SimpleHTTPRequestHandler now uses HTML5. (GH-31533)
Co-authored-by: Oleg Iarygin <[email protected]>
1 parent 9bbdde2 commit 0bb40a4

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Lib/http/server.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@
109109

110110
# Default error message template
111111
DEFAULT_ERROR_MESSAGE = """\
112-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
113-
"http://www.w3.org/TR/html4/strict.dtd">
114-
<html>
112+
<!DOCTYPE HTML>
113+
<html lang="en">
115114
<head>
116-
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
115+
<meta charset="utf-8">
117116
<title>Error response</title>
118117
</head>
119118
<body>
@@ -777,14 +776,13 @@ def list_directory(self, path):
777776
displaypath = urllib.parse.unquote(path)
778777
displaypath = html.escape(displaypath, quote=False)
779778
enc = sys.getfilesystemencoding()
780-
title = 'Directory listing for %s' % displaypath
781-
r.append('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
782-
'"http://www.w3.org/TR/html4/strict.dtd">')
783-
r.append('<html>\n<head>')
784-
r.append('<meta http-equiv="Content-Type" '
785-
'content="text/html; charset=%s">' % enc)
786-
r.append('<title>%s</title>\n</head>' % title)
787-
r.append('<body>\n<h1>%s</h1>' % title)
779+
title = f'Directory listing for {displaypath}'
780+
r.append('<!DOCTYPE HTML>')
781+
r.append('<html lang="en">')
782+
r.append('<head>')
783+
r.append(f'<meta charset="{enc}">')
784+
r.append(f'<title>{title}</title>\n</head>')
785+
r.append(f'<body>\n<h1>{title}</h1>')
788786
r.append('<hr>\n<ul>')
789787
for name in list:
790788
fullname = os.path.join(path, name)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:class:`~http.server.SimpleHTTPRequestHandler` now uses HTML5 grammar. Patch
2+
by Dong-hee Na.

0 commit comments

Comments
 (0)