https://github.com/python/cpython/commit/9684f40b9f51816fd326f1b4957ea5fb5b5922c8
commit: 9684f40b9f51816fd326f1b4957ea5fb5b5922c8
branch: main
author: Yorik Hansen <[email protected]>
committer: hugovk <[email protected]>
date: 2024-09-03T09:32:11+03:00
summary:

gh-123430: Add dark mode support to pages generated by http.server (#123475)

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst
M Doc/whatsnew/3.14.rst
M Lib/http/server.py

diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 4817c5258052e1..233d7ce0399cd6 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -151,6 +151,14 @@ Added support for converting any objects that have the
 (Contributed by Serhiy Storchaka in :gh:`82017`.)
 
 
+http
+----
+
+Directory lists and error pages generated by the :mod:`http.server`
+module allow the browser to apply its default dark mode.
+(Contributed by Yorik Hansen in :gh:`123430`.)
+
+
 json
 ----
 
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 2d010649e56b51..a6f7aecc78763f 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -114,6 +114,11 @@
 <html lang="en">
     <head>
         <meta charset="utf-8">
+        <style type="text/css">
+            :root {
+                color-scheme: light dark;
+            }
+        </style>
         <title>Error response</title>
     </head>
     <body>
@@ -804,6 +809,7 @@ def list_directory(self, path):
         r.append('<html lang="en">')
         r.append('<head>')
         r.append(f'<meta charset="{enc}">')
+        r.append('<style type="text/css">\n:root {\ncolor-scheme: light 
dark;\n}\n</style>')
         r.append(f'<title>{title}</title>\n</head>')
         r.append(f'<body>\n<h1>{title}</h1>')
         r.append('<hr>\n<ul>')
diff --git 
a/Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst 
b/Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst
new file mode 100644
index 00000000000000..0afdad7917fa8f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst
@@ -0,0 +1 @@
+Pages generated by the :mod:`http.server` module allow the browser to apply 
its default dark mode.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to