Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Navigator tests on Py2.6

  • Loading branch information...
commit 6eee86dadf92dc6e397e7ec7484623b1469d31b6 1 parent c2375d2
Simon Sapin authored
5 weasyprint/compat.py
View
@@ -19,7 +19,8 @@
if sys.version_info[0] >= 3:
# Python 3
from urllib.parse import (
- urljoin, urlsplit, quote, unquote, unquote_to_bytes, parse_qs)
+ urljoin, urlsplit, quote, unquote, unquote_to_bytes, parse_qs,
+ urlencode)
from urllib.request import urlopen, Request, pathname2url
from array import array
@@ -48,7 +49,7 @@ def parse_email(data):
# Python 2
from urlparse import urljoin, urlsplit, parse_qs
from urllib2 import urlopen, Request
- from urllib import pathname2url, quote, unquote
+ from urllib import pathname2url, quote, unquote, urlencode
from array import array as _array
from itertools import izip
3  weasyprint/navigator.py
View
@@ -150,12 +150,13 @@ def make_response(body, status='200 OK',
return make_response(render_template(url))
elif path == '/':
- args = parse_qs(environ.get('QUERY_STRING', ''))
+ args = parse_qs(environ.get('QUERY_STRING') or '')
url = normalize_url(args.get('url', [''])[0])
return make_response(render_template(url))
return make_response(b'<h1>Not Found</h1>', status='404 Not Found')
+
def run(port=5000):
host = '127.0.0.1'
try:
9 weasyprint/tests/test_api.py
View
@@ -26,7 +26,7 @@
from .testing_utils import (
resource_filename, assert_no_logs, TEST_UA_STYLESHEET)
-from ..compat import urljoin, quote
+from ..compat import urljoin, urlencode
from .. import HTML, CSS
from .. import __main__
from .. import navigator
@@ -373,11 +373,12 @@ def test_unicode_filenames():
assert read_file(unicode_filename) == png_bytes
-def wsgi_client(path_info, query_string=None):
+def wsgi_client(path_info, qs_args=None):
start_response_calls = []
def start_response(status, headers):
start_response_calls.append((status, headers))
- environ = {'PATH_INFO': path_info, 'QUERY_STRING': query_string}
+ environ = {'PATH_INFO': path_info,
+ 'QUERY_STRING': urlencode(qs_args or {})}
response = b''.join(navigator.app(environ, start_response))
assert len(start_response_calls) == 1
status, headers = start_response_calls[0]
@@ -411,7 +412,7 @@ def test_navigator():
for status, headers, body in [
wsgi_client('/view/file://' + filename),
- wsgi_client('/', 'url=' + quote('file://' + filename, safe='')),
+ wsgi_client('/', {'url': 'file://' + filename}),
]:
body = body.decode('utf8')
assert status == '200 OK'
Please sign in to comment.
Something went wrong with that request. Please try again.