@@ -2162,7 +2162,7 @@ def onerror(modname):
2162
2162
2163
2163
# --------------------------------------- enhanced Web browser interface
2164
2164
2165
- def _start_server (urlhandler , port ):
2165
+ def _start_server (urlhandler , hostname , port ):
2166
2166
"""Start an HTTP server thread on a specific port.
2167
2167
2168
2168
Start an HTML/text server thread, so HTML or text documents can be
@@ -2247,8 +2247,8 @@ def log_message(self, *args):
2247
2247
2248
2248
class DocServer (http .server .HTTPServer ):
2249
2249
2250
- def __init__ (self , port , callback ):
2251
- self .host = 'localhost'
2250
+ def __init__ (self , host , port , callback ):
2251
+ self .host = host
2252
2252
self .address = (self .host , port )
2253
2253
self .callback = callback
2254
2254
self .base .__init__ (self , self .address , self .handler )
@@ -2268,8 +2268,9 @@ def server_activate(self):
2268
2268
2269
2269
class ServerThread (threading .Thread ):
2270
2270
2271
- def __init__ (self , urlhandler , port ):
2271
+ def __init__ (self , urlhandler , host , port ):
2272
2272
self .urlhandler = urlhandler
2273
+ self .host = host
2273
2274
self .port = int (port )
2274
2275
threading .Thread .__init__ (self )
2275
2276
self .serving = False
@@ -2282,7 +2283,7 @@ def run(self):
2282
2283
DocServer .handler = DocHandler
2283
2284
DocHandler .MessageClass = email .message .Message
2284
2285
DocHandler .urlhandler = staticmethod (self .urlhandler )
2285
- docsvr = DocServer (self .port , self .ready )
2286
+ docsvr = DocServer (self .host , self . port , self .ready )
2286
2287
self .docserver = docsvr
2287
2288
docsvr .serve_until_quit ()
2288
2289
except Exception as e :
@@ -2300,7 +2301,7 @@ def stop(self):
2300
2301
self .serving = False
2301
2302
self .url = None
2302
2303
2303
- thread = ServerThread (urlhandler , port )
2304
+ thread = ServerThread (urlhandler , hostname , port )
2304
2305
thread .start ()
2305
2306
# Wait until thread.serving is True to make sure we are
2306
2307
# really up before returning.
@@ -2564,14 +2565,14 @@ def get_html_page(url):
2564
2565
raise TypeError ('unknown content type %r for url %s' % (content_type , url ))
2565
2566
2566
2567
2567
- def browse (port = 0 , * , open_browser = True ):
2568
+ def browse (port = 0 , * , open_browser = True , hostname = 'localhost' ):
2568
2569
"""Start the enhanced pydoc Web server and open a Web browser.
2569
2570
2570
2571
Use port '0' to start the server on an arbitrary port.
2571
2572
Set open_browser to False to suppress opening a browser.
2572
2573
"""
2573
2574
import webbrowser
2574
- serverthread = _start_server (_url_handler , port )
2575
+ serverthread = _start_server (_url_handler , hostname , port )
2575
2576
if serverthread .error :
2576
2577
print (serverthread .error )
2577
2578
return
@@ -2618,11 +2619,12 @@ class BadUsage(Exception): pass
2618
2619
sys .path .insert (0 , '.' )
2619
2620
2620
2621
try :
2621
- opts , args = getopt .getopt (sys .argv [1 :], 'bk:p:w' )
2622
+ opts , args = getopt .getopt (sys .argv [1 :], 'bk:h: p:w' )
2622
2623
writing = False
2623
2624
start_server = False
2624
2625
open_browser = False
2625
- port = None
2626
+ port = 0
2627
+ hostname = 'localhost'
2626
2628
for opt , val in opts :
2627
2629
if opt == '-b' :
2628
2630
start_server = True
@@ -2635,11 +2637,12 @@ class BadUsage(Exception): pass
2635
2637
port = val
2636
2638
if opt == '-w' :
2637
2639
writing = True
2640
+ if opt == '-h' :
2641
+ start_server = True
2642
+ hostname = val
2638
2643
2639
2644
if start_server :
2640
- if port is None :
2641
- port = 0
2642
- browse (port , open_browser = open_browser )
2645
+ browse (port , hostname = hostname , open_browser = open_browser )
2643
2646
return
2644
2647
2645
2648
if not args : raise BadUsage
@@ -2675,6 +2678,9 @@ class BadUsage(Exception): pass
2675
2678
{cmd} -k <keyword>
2676
2679
Search for a keyword in the synopsis lines of all available modules.
2677
2680
2681
+ {cmd} -h <hostname>
2682
+ Start an HTTP server with the given hostname.(default: localhost)
2683
+
2678
2684
{cmd} -p <port>
2679
2685
Start an HTTP server on the given port on the local machine. Port
2680
2686
number 0 can be used to get an arbitrary unused port.
0 commit comments