Skip to content

Commit

Permalink
Fix token sesssion parsing in PY3.
Browse files Browse the repository at this point in the history
  • Loading branch information
kratos83 authored and braincore committed Feb 18, 2016
1 parent f45219f commit 28c2588
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions dropbox/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pkg_resources
import six
import ssl
import sys

import requests
from requests.adapters import HTTPAdapter
Expand Down Expand Up @@ -41,20 +41,16 @@ def pinned_session(pool_maxsize=8):
import time
import urllib

try:
from urlparse import parse_qs
except ImportError:
# fall back for Python 2.5
from cgi import parse_qs

from . import rest

if six.PY3:
url_path_quote = urllib.parse.quote
url_encode = urllib.parse.urlencode
else:
if six.PY2:
from urlparse import parse_qs
url_path_quote = urllib.quote
url_encode = urllib.urlencode
else:
from urllib.parse import parse_qs
url_path_quote = urllib.parse.quote
url_encode = urllib.parse.urlencode


class OAuthToken(object):
Expand Down Expand Up @@ -320,13 +316,19 @@ def _parse_token(cls, s):
if not params:
raise ValueError("Invalid parameter string: %r" % s)

if six.PY2:
oauth_token_key = 'oauth_token'
oauth_token_secret_key = 'oauth_token_secret'
else:
oauth_token_key = b'oauth_token'
oauth_token_secret_key = b'oauth_token_secret'
try:
key = params['oauth_token'][0]
key = params[oauth_token_key][0]
except Exception:
raise ValueError("'oauth_token' not found in OAuth request.")

try:
secret = params['oauth_token_secret'][0]
secret = params[oauth_token_secret_key][0]
except Exception:
raise ValueError("'oauth_token_secret' not found in "
"OAuth request.")
Expand Down

0 comments on commit 28c2588

Please sign in to comment.