Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a95fa9

Browse files
authored
gh-91219: Add an index_pages default list and parameter to SimpleHTTPRequestHandler (GH-31985)
* Add an index_pages default list to SimpleHTTPRequestHandler and anoptional constructor parameter that allows the default indexes pageslist to be overridden. This makes it easy to set a new index page namewithout having to override send_head.
1 parent4e796f5 commit9a95fa9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

‎Lib/http/server.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
642642
643643
"""
644644

645+
index_pages= ["index.html","index.htm"]
645646
server_version="SimpleHTTP/"+__version__
646647
extensions_map=_encodings_map_default= {
647648
'.gz':'application/gzip',
@@ -650,9 +651,11 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
650651
'.xz':'application/x-xz',
651652
}
652653

653-
def__init__(self,*args,directory=None,**kwargs):
654+
def__init__(self,*args,directory=None,index_pages=None,**kwargs):
654655
ifdirectoryisNone:
655656
directory=os.getcwd()
657+
ifindex_pagesisnotNone:
658+
self.index_pages=index_pages
656659
self.directory=os.fspath(directory)
657660
super().__init__(*args,**kwargs)
658661

@@ -696,7 +699,7 @@ def send_head(self):
696699
self.send_header("Content-Length","0")
697700
self.end_headers()
698701
returnNone
699-
forindexin"index.html","index.htm":
702+
forindexinself.index_pages:
700703
index=os.path.join(path,index)
701704
ifos.path.exists(index):
702705
path=index
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an index_pages parameter to support using non-default index page names.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp