Skip to content

Commit 970711b

Browse files
committed
if/else ternary operator is 2.5+. let's be more compatible than that.
1 parent 695c5e3 commit 970711b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

oauth2/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import hmac
3030
import binascii
3131
import httplib2
32-
from types import ListType
3332

3433
try:
3534
from urlparse import parse_qs, parse_qsl
@@ -328,9 +327,17 @@ def get_parameter(self, parameter):
328327

329328
def get_normalized_parameters(self):
330329
"""Return a string that contains the parameters that must be signed."""
331-
# 1.0a/9.1.1 states that kvp must be sorted by key, then by value
332-
items = [(k, v if type(v) != ListType else sorted(v)) for k,v in sorted(self.items()) if k != 'oauth_signature']
333-
encoded_str = urllib.urlencode(items, True)
330+
items = []
331+
for key, value in self.iteritems():
332+
if key == 'oauth_signature':
333+
continue
334+
# 1.0a/9.1.1 states that kvp must be sorted by key, then by value,
335+
# so we unpack sequence values into multiple items for sorting.
336+
if hasattr(value, '__iter__'):
337+
items.extend((key, item) for item in value)
338+
else:
339+
items.append((key, value))
340+
encoded_str = urllib.urlencode(sorted(items))
334341
# Encode signature parameters per Oauth Core 1.0 protocol
335342
# spec draft 7, section 3.6
336343
# (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)

0 commit comments

Comments
 (0)