[Python-checkins] cpython (merge 3.5 -> default): Issue #26717: Merge wsgiref fix from 3.5

martin.panter python-checkins at python.org
Sat Apr 16 23:04:41 EDT 2016


https://hg.python.org/cpython/rev/815a4ac67e68
changeset:   101032:815a4ac67e68
parent:      101029:3e93ac5a7afa
parent:      101031:1f2cfcd5a83f
user:        Martin Panter <vadmium+py at gmail.com>
date:        Sun Apr 17 02:36:50 2016 +0000
summary:
  Issue #26717: Merge wsgiref fix from 3.5

files:
  Lib/test/test_wsgiref.py     |  24 ++++++++++++++++++++++++
  Lib/wsgiref/simple_server.py |   2 +-
  Misc/ACKS                    |   1 +
  Misc/NEWS                    |   3 +++
  4 files changed, 29 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -1,3 +1,4 @@
+from unittest import mock
 from unittest import TestCase
 from wsgiref.util import setup_testing_defaults
 from wsgiref.headers import Headers
@@ -221,6 +222,29 @@
                 b"data",
                 out)
 
+    def test_cp1252_url(self):
+        def app(e, s):
+            s("200 OK", [
+                ("Content-Type", "text/plain"),
+                ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"),
+                ])
+            # PEP3333 says environ variables are decoded as latin1.
+            # Encode as latin1 to get original bytes
+            return [e["PATH_INFO"].encode("latin1")]
+
+        out, err = run_amock(
+            validator(app), data=b"GET /\x80%80 HTTP/1.0")
+        self.assertEqual(
+            [
+                b"HTTP/1.0 200 OK",
+                mock.ANY,
+                b"Content-Type: text/plain",
+                b"Date: Wed, 24 Dec 2008 13:29:32 GMT",
+                b"",
+                b"/\x80\x80",
+            ],
+            out.splitlines())
+
 
 class UtilityTests(TestCase):
 
diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py
--- a/Lib/wsgiref/simple_server.py
+++ b/Lib/wsgiref/simple_server.py
@@ -82,7 +82,7 @@
         else:
             path,query = self.path,''
 
-        env['PATH_INFO'] = urllib.parse.unquote_to_bytes(path).decode('iso-8859-1')
+        env['PATH_INFO'] = urllib.parse.unquote(path, 'iso-8859-1')
         env['QUERY_STRING'] = query
 
         host = self.address_string()
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1385,6 +1385,7 @@
 Paul Sokolovsky
 Evgeny Sologubov
 Cody Somerville
+Anthony Sottile
 Edoardo Spadolini
 Geoffrey Spear
 Clay Spence
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -245,6 +245,9 @@
 Library
 -------
 
+- Issue #26717: Stop encoding Latin-1-ized WSGI paths with UTF-8.  Patch by
+  Anthony Sottile.
+
 - Issue #26782: Add STARTUPINFO to subprocess.__all__ on Windows.
 
 - Issue #26404: Add context manager to socketserver.  Patch by Aviv Palivoda.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list