# HG changeset patch # User RĂ©mi Cardona # Date 1442924294 -7200 # Node ID 7ece2df9cc5c929f9fc7e410f36dc7e5590dbdf7 # Parent be0bd5aa21b4baa1490bc6ba7cc6741c35e8a251 [py3k] unicode vs str vs bytes vs the world diff -r be0bd5aa21b4 -r 7ece2df9cc5c req.py --- a/req.py Wed Sep 16 16:07:29 2015 +0200 +++ b/req.py Tue Sep 22 14:18:14 2015 +0200 @@ -22,7 +22,7 @@ from warnings import warn from datetime import time, datetime, timedelta -from six import PY2, text_type +from six import PY2, PY3, text_type from six.moves.urllib.parse import parse_qs, parse_qsl, quote as urlquote, unquote as urlunquote, urlsplit, urlunsplit from logilab.common.decorators import cached @@ -324,6 +324,8 @@ decoding is based on `self.encoding` which is the encoding used in `url_quote` """ + if PY3: + return urlunquote(quoted) if isinstance(quoted, unicode): quoted = quoted.encode(self.encoding) try: @@ -333,6 +335,9 @@ def url_parse_qsl(self, querystring): """return a list of (key, val) found in the url quoted query string""" + if PY3: + for key, val in parse_qsl(querystring): + yield key, val if isinstance(querystring, unicode): querystring = querystring.encode(self.encoding) for key, val in parse_qsl(querystring): diff -r be0bd5aa21b4 -r 7ece2df9cc5c web/test/unittest_views_staticcontrollers.py --- a/web/test/unittest_views_staticcontrollers.py Wed Sep 16 16:07:29 2015 +0200 +++ b/web/test/unittest_views_staticcontrollers.py Tue Sep 22 14:18:14 2015 +0200 @@ -120,12 +120,12 @@ yield res, req def expected_content(self, js_files): - content = u'' + content = b'' for js_file in js_files: dirpath, rid = self.config.locate_resource(js_file) if dirpath is not None: # ignore resources not found - with open(osp.join(dirpath, rid)) as f: - content += f.read() + '\n' + with open(osp.join(dirpath, rid), 'rb') as f: + content += f.read() + b'\n' return content def test_cache(self): diff -r be0bd5aa21b4 -r 7ece2df9cc5c web/views/staticcontrollers.py --- a/web/views/staticcontrollers.py Wed Sep 16 16:07:29 2015 +0200 +++ b/web/views/staticcontrollers.py Tue Sep 22 14:18:14 2015 +0200 @@ -167,7 +167,7 @@ with open(osp.join(dirpath, rid), 'rb') as source: for line in source: f.write(line) - f.write('\n') + f.write(b'\n') f.close() except: os.remove(tmpfile)