Skip to content

Commit

Permalink
Merge branch 'py3' into py3-dev
Browse files Browse the repository at this point in the history
Conflicts:
	werkzeug/testsuite/routing.py
  • Loading branch information
puzzlet committed Sep 2, 2012
2 parents e85820c + e732a1e commit ba14976
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion werkzeug/routing.py
Expand Up @@ -1192,9 +1192,10 @@ def bind_to_environ(self, environ, server_name=None, subdomain=None):
subdomain = '<invalid>'
else:
subdomain = '.'.join([_f for _f in cur_server_name[:offset] if _f])
path_info = environ.get('PATH_INFO', '').encode('latin1')
return Map.bind(self, server_name, environ.get('SCRIPT_NAME'),
subdomain, environ['wsgi.url_scheme'],
environ['REQUEST_METHOD'], environ.get('PATH_INFO'),
environ['REQUEST_METHOD'], path_info,
query_args=environ.get('QUERY_STRING', ''))

def update(self):
Expand Down
3 changes: 2 additions & 1 deletion werkzeug/serving.py
Expand Up @@ -84,7 +84,8 @@ def shutdown_server():
'SERVER_SOFTWARE': self.server_version,
'REQUEST_METHOD': self.command,
'SCRIPT_NAME': '',
'PATH_INFO': unquote(path_info),
# NOTE: PEP 3333 for Python 3
'PATH_INFO': unquote(path_info, encoding='latin1'),
'QUERY_STRING': query,
'CONTENT_TYPE': self.headers.get('Content-Type', ''),
'CONTENT_LENGTH': self.headers.get('Content-Length', ''),
Expand Down
3 changes: 1 addition & 2 deletions werkzeug/test.py
Expand Up @@ -541,8 +541,7 @@ def get_environ(self):

def _path_encode(x):
x = _unquote(x)
if isinstance(x, bytes):
x = x.decode(self.charset)
x = x.decode('latin1') # NOTE: PEP 3333 for Python 3
return x

result.update({
Expand Down
10 changes: 10 additions & 0 deletions werkzeug/testsuite/routing.py
Expand Up @@ -639,6 +639,16 @@ def test_unicode_rules(self):
url = a.build('foobar', {}, force_external=True)
self.assert_equal(url, 'http://xn--n3h.example.com/foo+bar/')

def test_pep3333_routing(self):
m = r.Map([
r.Rule('/foo/<bar>', endpoint='foo')
])
env = create_environ('/foo/bäär', 'http://☃.example.com')
a = m.bind_to_environ(env)
endpoint, values = a.match()
self.assert_equal(endpoint, 'foo')
self.assert_equal(values, {'bar': 'bäär'})


def suite():
suite = unittest.TestSuite()
Expand Down
9 changes: 9 additions & 0 deletions werkzeug/testsuite/wsgi.py
Expand Up @@ -243,6 +243,15 @@ def test_lines_longer_buffer_size(self):
lines = list(wsgi.make_line_iter(BytesIO(data), limit=len(data), buffer_size=4))
self.assert_equal(lines, [b'1234567890\n', b'1234567890\n'])

def test_pep3333_path_info(self):
env = create_environ('/föö-bar', 'http://☃.example.com')
self.assert_equal(env['PATH_INFO'], '/föö-bar'.encode('utf-8').decode('latin1'))
self.assert_equal(wsgi.get_current_url(env), 'http://xn--n3h.example.com/f%C3%B6%C3%B6-bar')

env = create_environ('/f%C3%B6%C3%B6-bar', 'http://☃.example.com')
self.assert_equal(env['PATH_INFO'], '/föö-bar'.encode('utf-8').decode('latin1'))
self.assert_equal(wsgi.get_current_url(env), 'http://xn--n3h.example.com/f%C3%B6%C3%B6-bar')


def suite():
suite = unittest.TestSuite()
Expand Down
4 changes: 2 additions & 2 deletions werkzeug/wsgi.py
Expand Up @@ -63,11 +63,11 @@ def get_current_url(environ, root_only=False, strip_querystring=False,
cat = tmp.append
if host_only:
return ''.join(tmp) + '/'
cat(urllib.parse.quote(environ.get('SCRIPT_NAME', '').rstrip('/')))
cat(urllib.parse.quote(environ.get('SCRIPT_NAME', '').rstrip('/'), encoding='latin1'))
if root_only:
cat('/')
else:
cat(urllib.parse.quote('/' + environ.get('PATH_INFO', '').lstrip('/')))
cat(urllib.parse.quote('/' + environ.get('PATH_INFO', '').lstrip('/'), encoding='latin1'))
if not strip_querystring:
qs = environ.get('QUERY_STRING')
if qs:
Expand Down

0 comments on commit ba14976

Please sign in to comment.