Skip to content

Commit

Permalink
added compatibility for older versions of python which don't have url…
Browse files Browse the repository at this point in the history
…parse.parse_qs
  • Loading branch information
muffinresearch authored and joestump committed Dec 1, 2009
1 parent 39d1d91 commit 0575c84
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import binascii
import httplib2

try:
from urlparse import parse_qs, parse_qsl
except ImportError:
from cgi import parse_qs, parse_qsl


VERSION = '1.0' # Hi Blaine!
HTTP_METHOD = 'GET'
Expand Down Expand Up @@ -192,7 +197,7 @@ def from_string(s):
if not len(s):
raise ValueError("Invalid parameter string.")

params = urlparse.parse_qs(s, keep_blank_values=False)
params = parse_qs(s, keep_blank_values=False)
if not len(params):
raise ValueError("Invalid parameter string.")

Expand Down Expand Up @@ -435,7 +440,7 @@ def _split_header(header):
@staticmethod
def _split_url_string(param_str):
"""Turn URL string into parameters."""
parameters = urlparse.parse_qs(param_str, keep_blank_values=False)
parameters = parse_qs(param_str, keep_blank_values=False)
for k, v in parameters.iteritems():
parameters[k] = urllib.unquote(v[0])
return parameters
Expand Down Expand Up @@ -567,10 +572,10 @@ def request(self, uri, method="GET", body=None, headers=None,
headers = {}

if body and method == "POST":
parameters = dict(urlparse.parse_qsl(body))
parameters = dict(parse_qsl(body))
elif method == "GET":
parsed = urlparse.urlparse(uri)
parameters = urlparse.parse_qs(parsed.query)
parameters = parse_qs(parsed.query)
else:
parameters = None

Expand Down

0 comments on commit 0575c84

Please sign in to comment.