|
29 | 29 | import hmac
|
30 | 30 | import binascii
|
31 | 31 | import httplib2
|
32 |
| -from types import ListType |
33 | 32 |
|
34 | 33 | try:
|
35 | 34 | from urlparse import parse_qs, parse_qsl
|
@@ -328,9 +327,17 @@ def get_parameter(self, parameter):
|
328 | 327 |
|
329 | 328 | def get_normalized_parameters(self):
|
330 | 329 | """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)) |
334 | 341 | # Encode signature parameters per Oauth Core 1.0 protocol
|
335 | 342 | # spec draft 7, section 3.6
|
336 | 343 | # (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)
|
@@ -585,7 +592,13 @@ def request(self, uri, method="GET", body=None, headers=None,
|
585 | 592 | parameters = dict(parse_qsl(body))
|
586 | 593 | elif method == "GET":
|
587 | 594 | parsed = urlparse.urlparse(uri)
|
588 |
| - parameters = parse_qsl(parsed.query) |
| 595 | + |
| 596 | + try: |
| 597 | + query = parsed.query |
| 598 | + except AttributeError: |
| 599 | + query = parsed[4] |
| 600 | + |
| 601 | + parameters = parse_qsl(query) |
589 | 602 | else:
|
590 | 603 | parameters = None
|
591 | 604 |
|
@@ -665,11 +678,11 @@ def sign(self, request, consumer, token):
|
665 | 678 |
|
666 | 679 | # HMAC object.
|
667 | 680 | try:
|
668 |
| - import hashlib # 2.5 |
669 |
| - hashed = hmac.new(key, raw, hashlib.sha1) |
| 681 | + import hashlib.sha1 as sha # 2.5 |
670 | 682 | except ImportError:
|
671 | 683 | import sha # Deprecated
|
672 |
| - hashed = hmac.new(key, raw, sha) |
| 684 | + |
| 685 | + hashed = hmac.new(key, raw, sha) |
673 | 686 |
|
674 | 687 | # Calculate the digest base 64.
|
675 | 688 | return binascii.b2a_base64(hashed.digest())[:-1]
|
|
0 commit comments