Skip to content

Commit 5110561

Browse files
committed
Oh, after we've made sure it can be converted to unicode, just leave it as a unicode object after that.
1 parent 902490b commit 5110561

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

oauth2/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,19 @@ def build_xoauth_string(url, consumer, token=None):
8888
return "%s %s %s" % ("GET", url, ','.join(params))
8989

9090

91-
def check_for_bad_encoding(s):
92-
""" Raise exception with instructive error message if s is not unicode or ascii. """
91+
def to_unicode(s):
92+
""" Convert to unicode, raise exception with instructive error
93+
message if s is not unicode or ascii. """
9394
if not isinstance(s, unicode):
9495
try:
95-
s.decode('ascii')
96+
s = s.decode('ascii')
9697
except UnicodeDecodeError, le:
9798
raise TypeError('You are required to pass either a unicode object or an ascii string here. You passed a Python string object which contained non-ascii: %r. The UnicodeDecodeError that resulted from attempting to interpret it as ascii was: %s' % (s, le,))
99+
return s
98100

99101
def escape(s):
100102
"""Escape a URL including any /."""
101-
check_for_bad_encoding(s)
103+
s = to_unicode(s)
102104
return urllib.quote(s.encode('utf-8'), safe='~')
103105

104106
def generate_timestamp():
@@ -285,7 +287,7 @@ class Request(dict):
285287

286288
def __init__(self, method=HTTP_METHOD, url=None, parameters=None):
287289
if url is not None:
288-
check_for_bad_encoding(url)
290+
url = to_unicode(url)
289291
self.url = unicode(url)
290292
self.method = method
291293
if parameters is not None:

0 commit comments

Comments
 (0)