Commit 483a0042 authored by Jason Madden's avatar Jason Madden

Merge pull request #712 from Awingu/fix_unquote_encoding

Use latin-1 as decoding in unquote for conformance with PEP 3333
parents 0b482ca5 fc2d14a0
...@@ -16,6 +16,7 @@ import sys ...@@ -16,6 +16,7 @@ import sys
import time import time
import traceback import traceback
from datetime import datetime from datetime import datetime
try: try:
from urllib import unquote from urllib import unquote
except ImportError: except ImportError:
...@@ -26,6 +27,12 @@ import gevent ...@@ -26,6 +27,12 @@ import gevent
from gevent.server import StreamServer from gevent.server import StreamServer
from gevent.hub import GreenletExit, PY3, reraise from gevent.hub import GreenletExit, PY3, reraise
from functools import partial
if PY3:
unquote_latin1 = partial(unquote, encoding='latin-1')
else:
unquote_latin1 = unquote
_no_undoc_members = True # Don't put undocumented things into sphinx _no_undoc_members = True # Don't put undocumented things into sphinx
__all__ = [ __all__ = [
...@@ -949,7 +956,7 @@ class WSGIHandler(object): ...@@ -949,7 +956,7 @@ class WSGIHandler(object):
path, query = self.path.split('?', 1) path, query = self.path.split('?', 1)
else: else:
path, query = self.path, '' path, query = self.path, ''
env['PATH_INFO'] = unquote(path) env['PATH_INFO'] = unquote_latin1(path)
env['QUERY_STRING'] = query env['QUERY_STRING'] = query
if self.headers.typeheader is not None: if self.headers.typeheader is not None:
......
...@@ -731,7 +731,7 @@ class TestInternational(TestCase): ...@@ -731,7 +731,7 @@ class TestInternational(TestCase):
if not PY3: if not PY3:
self.assertEqual(environ['PATH_INFO'], '/\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82') self.assertEqual(environ['PATH_INFO'], '/\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82')
else: else:
self.assertEqual(environ['PATH_INFO'], '/\u043f\u0440\u0438\u0432\u0435\u0442') self.assertEqual(environ['PATH_INFO'], '/\u043f\u0440\u0438\u0432\u0435\u0442'.encode('utf-8').decode('latin-1'))
self.assertEqual(environ['QUERY_STRING'], '%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81=%D0%BE%D1%82%D0%B2%D0%B5%D1%82') self.assertEqual(environ['QUERY_STRING'], '%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81=%D0%BE%D1%82%D0%B2%D0%B5%D1%82')
start_response("200 PASSED", [('Content-Type', 'text/plain')]) start_response("200 PASSED", [('Content-Type', 'text/plain')])
return [] return []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment