Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(19)

Side by Side Diff: Doc/library/http.server.rst

Issue 26404: socketserver context manager
Patch Set: Created 4 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Doc/library/socketserver.rst » ('j') | Doc/library/socketserver.rst » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`http.server` --- HTTP servers 1 :mod:`http.server` --- HTTP servers
2 =================================== 2 ===================================
3 3
4 .. module:: http.server 4 .. module:: http.server
5 :synopsis: HTTP server and request handlers. 5 :synopsis: HTTP server and request handlers.
6 6
7 7
8 .. index:: 8 .. index::
9 pair: WWW; server 9 pair: WWW; server
10 pair: HTTP; protocol 10 pair: HTTP; protocol
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 manner in order to create a very basic webserver serving files relative to 368 manner in order to create a very basic webserver serving files relative to
369 the current directory:: 369 the current directory::
370 370
371 import http.server 371 import http.server
372 import socketserver 372 import socketserver
373 373
374 PORT = 8000 374 PORT = 8000
375 375
376 Handler = http.server.SimpleHTTPRequestHandler 376 Handler = http.server.SimpleHTTPRequestHandler
377 377
378 httpd = socketserver.TCPServer(("", PORT), Handler) 378 with socketserver.TCPServer(("", PORT), Handler) as httpd:
379 379 print("serving at port", PORT)
380 print("serving at port", PORT) 380 httpd.serve_forever()
381 httpd.serve_forever()
382 381
383 .. _http-server-cli: 382 .. _http-server-cli:
384 383
385 :mod:`http.server` can also be invoked directly using the :option:`-m` 384 :mod:`http.server` can also be invoked directly using the :option:`-m`
386 switch of the interpreter with a ``port number`` argument. Similar to 385 switch of the interpreter with a ``port number`` argument. Similar to
387 the previous example, this serves files relative to the current directory:: 386 the previous example, this serves files relative to the current directory::
388 387
389 python -m http.server 8000 388 python -m http.server 8000
390 389
391 By default, server binds itself to all interfaces. The option ``-b/--bind`` 390 By default, server binds itself to all interfaces. The option ``-b/--bind``
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 to POST to a non-CGI url. 435 to POST to a non-CGI url.
437 436
438 Note that CGI scripts will be run with UID of user nobody, for security 437 Note that CGI scripts will be run with UID of user nobody, for security
439 reasons. Problems with the CGI script will be translated to error 403. 438 reasons. Problems with the CGI script will be translated to error 403.
440 439
441 :class:`CGIHTTPRequestHandler` can be enabled in the command line by passing 440 :class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
442 the ``--cgi`` option:: 441 the ``--cgi`` option::
443 442
444 python -m http.server --cgi 8000 443 python -m http.server --cgi 8000
445 444
OLDNEW
« no previous file with comments | « no previous file | Doc/library/socketserver.rst » ('j') | Doc/library/socketserver.rst » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+