diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-04-21 23:54:13 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-04-21 23:54:13 +0200 |
commit | aa5aed1005a8fef5815b1613b138fc36ee637f4e (patch) | |
tree | f2912e942d5d7d28f1f7cc0f4bf133aa2661c4ac /paste | |
parent | 10051523ef1b7a9949e4bbd84d4382ad35630ddb (diff) | |
download | paste-git-aa5aed1005a8fef5815b1613b138fc36ee637f4e.tar.gz |
Fix httpheaders on Python 3
* Call list.sort() with a key function instead of a compare function.
* Fix FakeRequest in httpheaders on Python 3: urllib.request now expects
properties, not getters (get_xxx() methods).
Diffstat (limited to 'paste')
-rw-r--r-- | paste/httpheaders.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/paste/httpheaders.py b/paste/httpheaders.py index 702e596..3c11bad 100644 --- a/paste/httpheaders.py +++ b/paste/httpheaders.py @@ -590,13 +590,10 @@ def normalize_headers(response_headers, strict=True): continue response_headers[idx] = (str(head), val) category[str(head)] = head.sort_order - def compare(a, b): - ac = category[a[0]] - bc = category[b[0]] - if ac == bc: - return cmp(a[0], b[0]) - return cmp(ac, bc) - response_headers.sort(compare) + def key_func(item): + value = item[0] + return (category[value], value) + response_headers.sort(key=key_func) class _DateHeader(_SingleValueHeader): """ @@ -975,7 +972,7 @@ class _AcceptLanguage(_MultiValueHeader): if lvalue == "q": q = float(rvalue) qs.append((lang, q)) - qs.sort(lambda a, b: -cmp(a[1], b[1])) + qs.sort(key=lambda query: query[1], reverse=True) return [lang for (lang, q) in qs] _AcceptLanguage('Accept-Language', 'request', 'RFC 2616, 14.4') @@ -1020,13 +1017,28 @@ class _Authorization(_SingleValueHeader): (token, challenge) = challenge.split(' ', 1) chal = parse_keqv_list(parse_http_list(challenge)) class FakeRequest(object): - def get_full_url(self): - return path - def has_data(self): - return False + if six.PY3: + @property + def full_url(self): + return path + + selector = full_url + + @property + def data(self): + return None + else: + def get_full_url(self): + return path + + get_selector = get_full_url + + def has_data(self): + return False + def get_method(self): return method or "GET" - get_selector = get_full_url + retval = "Digest %s" % auth.get_authorization(FakeRequest(), chal) return (retval,) _Authorization('Authorization', 'request', 'RFC 2617') |