diff options
author | i026e <klev.paul@gmail.com> | 2014-12-17 11:25:07 +0300 |
---|---|---|
committer | i026e <klev.paul@gmail.com> | 2014-12-17 11:25:07 +0300 |
commit | 93ba12c7d7483af5374ba5f0e62a46ddc5e1ffe2 (patch) | |
tree | 6c3a1b950eeb7354bffe47310cb74f7e2b6aca7b | |
parent | df1cca48b204fc20fde1e49d7ad763394b01d931 (diff) | |
download | httplib2-93ba12c7d7483af5374ba5f0e62a46ddc5e1ffe2.tar.gz |
Update __init__.py
There is a problem with headers when a binary string is passed (like b'Authorization')
I've added a function to decode such strings.
It is not an elegant solution, but it works for me
-rw-r--r-- | python3/httplib2/__init__.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py index 43f7419..b7b00b1 100644 --- a/python3/httplib2/__init__.py +++ b/python3/httplib2/__init__.py @@ -192,8 +192,13 @@ def safename(filename): NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+') def _normalize_headers(headers): - return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip()) for (key, value) in headers.items()]) + return dict([ (_convert_byte_str(key).lower(), NORMALIZE_SPACE.sub(_convert_byte_str(value), ' ').strip()) for (key, value) in headers.items()]) +def _convert_byte_str(s): + if not isinstance(s, str): + return str(s, 'utf-8') + return s + def _parse_cache_control(headers): retval = {} if 'cache-control' in headers: |