Skip to content

Commit

Permalink
fix some byte/unicode arguments for Python 2.6's benefit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikix committed Sep 3, 2012
1 parent d06f017 commit 56a5c73
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions oauthlib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@
unicode_type = unicode
bytes_type = str

def quote(s, safe='/'):

# 'safe' must be bytes (Python 2.6 requires bytes, other versions allow either)
def quote(s, safe=b'/'):
s = _quote(s, safe)
# PY3 always returns unicode. PY2 may return either, depending on whether
# it had to modify the string.
s = _quote(s, safe)
if isinstance(s, bytes_type):
s = s.decode('utf-8')
return s


def unquote(s):
s = _unquote(s)
# PY3 always returns unicode. PY2 seems to always return what you give it,
# which differs from quote's behavior. Just to be safe, make sure it is
# unicode before we return.
s = _unquote(s)
if isinstance(s, bytes_type):
s = s.decode('utf-8')
return s
Expand Down
2 changes: 1 addition & 1 deletion oauthlib/oauth1/rfc5849/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def normalize_base_string_uri(uri):
#
# .. _`section 3.4.1.3`: http://tools.ietf.org/html/rfc5849#section-3.4.1.3

def collect_parameters(uri_query=b'', body=[], headers=None,
def collect_parameters(uri_query='', body=[], headers=None,
exclude_oauth_signature=True):
"""**Parameter Sources**
Expand Down
2 changes: 1 addition & 1 deletion oauthlib/oauth1/rfc5849/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def escape(u):
raise ValueError('Only unicode objects are escapable.')
# Letters, digits, and the characters '_.-' are already treated as safe
# by urllib.quote(). We need to add '~' to fully support rfc5849.
return quote(u, safe='~')
return quote(u, safe=b'~')


def unescape(u):
Expand Down
2 changes: 1 addition & 1 deletion oauthlib/oauth2/draft25/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def escape(u):
"""
if not isinstance(u, unicode_type):
raise ValueError('Only unicode objects are escapable.')
return quote(u.encode('utf-8'), safe='~')
return quote(u.encode('utf-8'), safe=b'~')

0 comments on commit 56a5c73

Please sign in to comment.