diff options
author | Ian Bicking <ianb@colorstudy.com> | 2010-09-16 13:18:45 -0400 |
---|---|---|
committer | Ian Bicking <ianb@colorstudy.com> | 2010-09-16 13:18:45 -0400 |
commit | dc8a588b82fd813876fbfd1fb68d989b9f16bc5f (patch) | |
tree | eaecfb897a42d2dd8c6b90230601b3b7dbc5f75c | |
parent | 37d976c6f97b71bc033004fc5785e6ead24b7e4a (diff) | |
download | paste-dc8a588b82fd813876fbfd1fb68d989b9f16bc5f.tar.gz |
Fix #443: url_unquote undefined
-rw-r--r-- | docs/news.txt | 5 | ||||
-rw-r--r-- | paste/auth/auth_tkt.py | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/docs/news.txt b/docs/news.txt index 2189a32..87e3267 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -3,6 +3,11 @@ News .. contents:: +hg tip +------ + +* Fix bug introduced in :mod:`paste.auth.auth_tkt` (with ``url_unquote``) + 1.7.5 ----- diff --git a/paste/auth/auth_tkt.py b/paste/auth/auth_tkt.py index 830a116..8dfce00 100644 --- a/paste/auth/auth_tkt.py +++ b/paste/auth/auth_tkt.py @@ -45,6 +45,7 @@ except ImportError: import Cookie from paste import request from urllib import quote as url_quote +from urllib import unquote as url_unquote class AuthTicket(object): @@ -118,6 +119,7 @@ class AuthTicket(object): c[self.cookie_name]['secure'] = 'true' return c + class BadTicket(Exception): """ Exception raised when a ticket can't be parsed. If we get @@ -129,6 +131,7 @@ class BadTicket(Exception): self.expected = expected Exception.__init__(self, msg) + def parse_ticket(secret, ticket, ip): """ Parse the ticket, returning (timestamp, userid, tokens, user_data). @@ -165,6 +168,7 @@ def parse_ticket(secret, ticket, ip): return (timestamp, userid, tokens, user_data) + def calculate_digest(ip, timestamp, secret, userid, tokens, user_data): secret = maybe_encode(secret) userid = maybe_encode(userid) @@ -176,6 +180,7 @@ def calculate_digest(ip, timestamp, secret, userid, tokens, user_data): digest = md5(digest0 + secret).hexdigest() return digest + def encode_ip_timestamp(ip, timestamp): ip_chars = ''.join(map(chr, map(int, ip.split('.')))) t = int(timestamp) @@ -186,11 +191,13 @@ def encode_ip_timestamp(ip, timestamp): ts_chars = ''.join(map(chr, ts)) return ip_chars + ts_chars + def maybe_encode(s, encoding='utf8'): if isinstance(s, unicode): s = s.encode(encoding) return s + class AuthTKTMiddleware(object): """ @@ -260,7 +267,7 @@ class AuthTKTMiddleware(object): def __call__(self, environ, start_response): cookies = request.get_cookies(environ) - if cookies.has_key(self.cookie_name): + if self.cookie_name in cookies: cookie_value = cookies[self.cookie_name].value else: cookie_value = '' @@ -289,18 +296,23 @@ class AuthTKTMiddleware(object): # in or anything pass set_cookies = [] + def set_user(userid, tokens='', user_data=''): set_cookies.extend(self.set_user_cookie( environ, userid, tokens, user_data)) + def logout_user(): set_cookies.extend(self.logout_user_cookie(environ)) + environ['paste.auth_tkt.set_user'] = set_user environ['paste.auth_tkt.logout_user'] = logout_user if self.logout_path and environ.get('PATH_INFO') == self.logout_path: logout_user() + def cookie_setting_start_response(status, headers, exc_info=None): headers.extend(set_cookies) return start_response(status, headers, exc_info) + return self.app(environ, cookie_setting_start_response) def set_user_cookie(self, environ, userid, tokens, user_data): @@ -357,6 +369,7 @@ class AuthTKTMiddleware(object): ] return cookies + def make_auth_tkt_middleware( app, global_conf, |