summaryrefslogtreecommitdiffstats
path: root/Lib/wsgiref
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-05 06:56:51 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-05 06:56:51 (GMT)
commitff5cd4576f7be50ef245124971078d80786e19cb (patch)
tree8b6f4d8b2283702b427eaeef8a1959b36b504d44 /Lib/wsgiref
parent1b749c5ef6a319bb1b2fe679c7379ed61c907f7b (diff)
parented0425c60abe1b746b1ca5b4039984d2ad6583c4 (diff)
downloadcpython-ff5cd4576f7be50ef245124971078d80786e19cb.zip
cpython-ff5cd4576f7be50ef245124971078d80786e19cb.tar.gz
cpython-ff5cd4576f7be50ef245124971078d80786e19cb.tar.bz2
Issue #24291: Merge wsgi partial write fix from 3.5
Diffstat (limited to 'Lib/wsgiref')
-rw-r--r--Lib/wsgiref/handlers.py12
-rw-r--r--Lib/wsgiref/simple_server.py17
2 files changed, 23 insertions, 6 deletions
diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py
index acb3547..f4300b8 100644
--- a/Lib/wsgiref/handlers.py
+++ b/Lib/wsgiref/handlers.py
@@ -450,7 +450,17 @@ class SimpleHandler(BaseHandler):
self.environ.update(self.base_env)
def _write(self,data):
- self.stdout.write(data)
+ result = self.stdout.write(data)
+ if result is None or result == len(data):
+ return
+ from warnings import warn
+ warn("SimpleHandler.stdout.write() should not do partial writes",
+ DeprecationWarning)
+ while True:
+ data = data[result:]
+ if not data:
+ break
+ result = self.stdout.write(data)
def _flush(self):
self.stdout.flush()
diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py
index f71563a..da74d7b 100644
--- a/Lib/wsgiref/simple_server.py
+++ b/Lib/wsgiref/simple_server.py
@@ -11,6 +11,7 @@ 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
@@ -126,11 +127,17 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):
if not self.parse_request(): # An error code has been sent, just exit
return
- 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())
+ # 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()