|
1 | 1 | import pkg_resources
|
2 |
| -import six |
3 | 2 | import ssl
|
| 3 | +import sys |
4 | 4 |
|
5 | 5 | import requests
|
6 | 6 | from requests.adapters import HTTPAdapter
|
@@ -41,20 +41,16 @@ def pinned_session(pool_maxsize=8):
|
41 | 41 | import time
|
42 | 42 | import urllib
|
43 | 43 |
|
44 |
| -try: |
45 |
| - from urlparse import parse_qs |
46 |
| -except ImportError: |
47 |
| - # fall back for Python 2.5 |
48 |
| - from cgi import parse_qs |
49 |
| - |
50 | 44 | from . import rest
|
51 | 45 |
|
52 |
| -if six.PY3: |
53 |
| - url_path_quote = urllib.parse.quote |
54 |
| - url_encode = urllib.parse.urlencode |
55 |
| -else: |
| 46 | +if six.PY2: |
| 47 | + from urlparse import parse_qs |
56 | 48 | url_path_quote = urllib.quote
|
57 | 49 | url_encode = urllib.urlencode
|
| 50 | +else: |
| 51 | + from urllib.parse import parse_qs |
| 52 | + url_path_quote = urllib.parse.quote |
| 53 | + url_encode = urllib.parse.urlencode |
58 | 54 |
|
59 | 55 |
|
60 | 56 | class OAuthToken(object):
|
@@ -320,13 +316,19 @@ def _parse_token(cls, s):
|
320 | 316 | if not params:
|
321 | 317 | raise ValueError("Invalid parameter string: %r" % s)
|
322 | 318 |
|
| 319 | + if six.PY2: |
| 320 | + oauth_token_key = 'oauth_token' |
| 321 | + oauth_token_secret_key = 'oauth_token_secret' |
| 322 | + else: |
| 323 | + oauth_token_key = b'oauth_token' |
| 324 | + oauth_token_secret_key = b'oauth_token_secret' |
323 | 325 | try:
|
324 |
| - key = params['oauth_token'][0] |
| 326 | + key = params[oauth_token_key][0] |
325 | 327 | except Exception:
|
326 | 328 | raise ValueError("'oauth_token' not found in OAuth request.")
|
327 | 329 |
|
328 | 330 | try:
|
329 |
| - secret = params['oauth_token_secret'][0] |
| 331 | + secret = params[oauth_token_secret_key][0] |
330 | 332 | except Exception:
|
331 | 333 | raise ValueError("'oauth_token_secret' not found in "
|
332 | 334 | "OAuth request.")
|
|
0 commit comments