From 75a2eb7ded57746641f10174ac79f0f6be2a34db Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 21 Apr 2015 23:54:13 +0200 Subject: 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). --- paste/httpheaders.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'paste/httpheaders.py') 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') -- cgit v1.2.1