summaryrefslogtreecommitdiff
path: root/Lib/wsgiref/simple_server.py
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2016-12-27 12:30:42 +0800
committerXiang Zhang <angwerzx@126.com>2016-12-27 12:30:42 +0800
commit7f36c4940810c3afd6bd9f0e6e890d4789299abd (patch)
tree68aefb2b7ac66be96c1a54dddeda17e2c71a3932 /Lib/wsgiref/simple_server.py
parent7a548444dfb1b80a1442a7cb4c17818dd49d18ac (diff)
parent4de2d1ba0aab6070885e47b7a9724d2623ba6cc6 (diff)
downloadcpython-7f36c4940810c3afd6bd9f0e6e890d4789299abd.tar.gz
Issue #29078: Merge 3.5.
Diffstat (limited to 'Lib/wsgiref/simple_server.py')
-rw-r--r--Lib/wsgiref/simple_server.py30
1 files changed, 11 insertions, 19 deletions
diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py
index 7fddbe822c..f71563a5ae 100644
--- a/Lib/wsgiref/simple_server.py
+++ b/Lib/wsgiref/simple_server.py
@@ -11,7 +11,6 @@ module. See also the BaseHTTPServer module docs for other API information.
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
-from io import BufferedWriter
import sys
import urllib.parse
from wsgiref.handlers import SimpleHandler
@@ -127,17 +126,11 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):
if not self.parse_request(): # An error code has been sent, just exit
return
- # Avoid passing the raw file object wfile, which can do partial
- # writes (Issue 24291)
- stdout = BufferedWriter(self.wfile)
- try:
- handler = ServerHandler(
- self.rfile, stdout, self.get_stderr(), self.get_environ()
- )
- handler.request_handler = self # backpointer for logging
- handler.run(self.server.get_app())
- finally:
- stdout.detach()
+ handler = ServerHandler(
+ self.rfile, self.wfile, self.get_stderr(), self.get_environ()
+ )
+ handler.request_handler = self # backpointer for logging
+ handler.run(self.server.get_app())
@@ -163,10 +156,9 @@ def make_server(
if __name__ == '__main__':
- httpd = make_server('', 8000, demo_app)
- sa = httpd.socket.getsockname()
- print("Serving HTTP on", sa[0], "port", sa[1], "...")
- import webbrowser
- webbrowser.open('http://localhost:8000/xyz?abc')
- httpd.handle_request() # serve one request, then exit
- httpd.server_close()
+ with make_server('', 8000, demo_app) as httpd:
+ sa = httpd.socket.getsockname()
+ print("Serving HTTP on", sa[0], "port", sa[1], "...")
+ import webbrowser
+ webbrowser.open('http://localhost:8000/xyz?abc')
+ httpd.handle_request() # serve one request, then exit