Permalink
Browse files

handle unicode a little better in param normalization

git-svn-id: https://oauth.googlecode.com/svn/code/python@898 f7ae4463-c52f-0410-a7dc-93bad6e629e8
  • Loading branch information...
1 parent ac9f9b3 commit 2d9112621ff464e166ef5a26ace94823cab49c62 andyster@gmail.com committed Feb 20, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 oauth/oauth.py
View
@@ -24,6 +24,13 @@ def escape(s):
# escape '/' too
return urllib.quote(s, safe='~')
+# utf-8, please
+def _utf8_str(s):
+ if isinstance(s, unicode):
+ return s.encode("utf-8")
+ else:
+ return str(s)
+
# util function: current timestamp
# seconds since epoch (UTC)
def generate_timestamp():
@@ -149,7 +156,7 @@ def get_normalized_parameters(self):
# sort lexicographically, first after key, then after value
key_values.sort()
# combine key value pairs in string and escape
- return '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) for k, v in key_values])
+ return '&'.join(['%s=%s' % (escape(_utf8_str(k)), escape(_utf8_str(v))) for k, v in key_values])
# just uppercases the http method
def get_normalized_http_method(self):
@@ -528,4 +535,4 @@ def build_signature_base_string(self, oauth_request, consumer, token):
def build_signature(self, oauth_request, consumer, token):
key, raw = self.build_signature_base_string(oauth_request, consumer, token)
- return key
+ return key

0 comments on commit 2d91126

Please sign in to comment.