diff options
author | Victor Stinner <vstinner@redhat.com> | 2015-11-27 09:54:05 +0100 |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2016-02-09 14:19:58 +0100 |
commit | 6ce605545a324b8a6724b6bed24b6e59ef1e5c27 (patch) | |
tree | eae580667eb7fca455f6b219d8e462dd558b052f | |
parent | e336dc26b9a6b56b2c7492345fc456c6a31dbd80 (diff) | |
download | routes-6ce605545a324b8a6724b6bed24b6e59ef1e5c27.tar.gz |
Fix BytesWarning in Mapper.generate()
When python3 is run with -bb, str(bytes) raises a BytesWarning. On
Python 3, Mapper.generate() gets such BytesWarning because
script_name type is str whereas cache_key type is byte.
On Python 3, generate() now encodes the script_name to UTF-8 and uses
bytes concatenation to fix this issue.
.travis.yml: Run tests using "python -bb $(which nosetests)" to raise
BytesWarning exception on bytes vs Unicode issue.
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | routes/mapper.py | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml index e7788ce..2f9b500 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ matrix: install: - python setup.py develop - pip install webob webtest coverage -script: nosetests +script: python -bb $(which nosetests) diff --git a/routes/mapper.py b/routes/mapper.py index 43372d7..06f09f2 100644 --- a/routes/mapper.py +++ b/routes/mapper.py @@ -789,7 +789,11 @@ class Mapper(SubMapperParent): six.text_type(kargs).encode('utf8') if self.urlcache is not None: - cache_key_script_name = '%s:%s' % (script_name, cache_key) + if six.PY3: + cache_key_script_name = b':'.join((script_name.encode('utf-8'), + cache_key)) + else: + cache_key_script_name = '%s:%s' % (script_name, cache_key) # Check the url cache to see if it exists, use it if it does val = self.urlcache.get(cache_key_script_name, self) |