Index: oauth.py =================================================================== --- oauth.py (revision 509) +++ oauth.py (working copy) @@ -22,7 +22,14 @@ # url escape def escape(s): # escape '/' too - return urllib.quote(s, safe='~') + s = unicode(s) + news = unicode() + for c in s: + if ord(c) > 128: + news += repr(unicode(c))[2:-1].upper() + else: + news += c + return urllib.quote(news, safe='~') # util function: current timestamp # seconds since epoch (UTC) @@ -66,7 +73,7 @@ # oauth_token_secret=digg&oauth_token=digg @staticmethod def from_string(s): - params = cgi.parse_qs(s, keep_blank_values=False) + params = cgi.parse_qs(s, keep_blank_values=True) key = params['oauth_token'][0] secret = params['oauth_token_secret'][0] return OAuthToken(key, secret) @@ -191,15 +198,14 @@ except: raise OAuthError('Unable to parse OAuth parameters from Authorization header.') + # from the url string + param_str = urlparse.urlparse(http_url).query + parameters = OAuthRequest._split_url_string(param_str) + # from the parameter string (post body) if http_method == 'POST' and postdata is not None: - parameters = OAuthRequest._split_url_string(postdata) + parameters.update(OAuthRequest._split_url_string(postdata)) - # from the url string - elif http_method == 'GET': - param_str = urlparse.urlparse(http_url).query - parameters = OAuthRequest._split_url_string(param_str) - if parameters: return OAuthRequest(http_method, http_url, parameters) @@ -257,7 +263,7 @@ # util function: turn url string into parameters, has to do some unescaping @staticmethod def _split_url_string(param_str): - parameters = cgi.parse_qs(param_str, keep_blank_values=False) + parameters = cgi.parse_qs(param_str, keep_blank_values=True) for k, v in parameters.iteritems(): parameters[k] = urllib.unquote(v[0]) return parameters @@ -482,7 +488,7 @@ sig = ( escape(oauth_request.get_normalized_http_method()), escape(oauth_request.get_normalized_http_url()), - escape(oauth_request.get_normalized_parameters()), + escape(oauth_request.get_normalized_parameters()).replace("%255CU", "%25"), ) key = '%s&' % escape(consumer.secret)