Remove circular dependency.
Reviwed in https://codereview.appspot.com/7506043/.
diff --git a/oauth2client/appengine.py b/oauth2client/appengine.py
index a4738f8..570f0f5 100644
--- a/oauth2client/appengine.py
+++ b/oauth2client/appengine.py
@@ -36,7 +36,6 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import login_required
from google.appengine.ext.webapp.util import run_wsgi_app
-from apiclient import discovery
from oauth2client import GOOGLE_AUTH_URI
from oauth2client import GOOGLE_REVOKE_URI
from oauth2client import GOOGLE_TOKEN_URI
@@ -799,7 +798,7 @@
if decorator._token_response_param and credentials.token_response:
resp_json = simplejson.dumps(credentials.token_response)
- redirect_uri = discovery._add_query_parameter(
+ redirect_uri = util._add_query_parameter(
redirect_uri, decorator._token_response_param, resp_json)
self.redirect(redirect_uri)
diff --git a/oauth2client/util.py b/oauth2client/util.py
index 178d218..ee6a100 100644
--- a/oauth2client/util.py
+++ b/oauth2client/util.py
@@ -28,6 +28,13 @@
import inspect
import logging
import types
+import urllib
+import urlparse
+
+try:
+ from urlparse import parse_qsl
+except ImportError:
+ from cgi import parse_qsl
logger = logging.getLogger(__name__)
@@ -160,3 +167,26 @@
A tuple representing the dictionary in it's naturally sorted ordering.
"""
return tuple(sorted(dictionary.items()))
+
+
+def _add_query_parameter(url, name, value):
+ """Adds a query parameter to a url.
+
+ Replaces the current value if it already exists in the URL.
+
+ Args:
+ url: string, url to add the query parameter to.
+ name: string, query parameter name.
+ value: string, query parameter value.
+
+ Returns:
+ Updated query parameter. Does not update the url if value is None.
+ """
+ if value is None:
+ return url
+ else:
+ parsed = list(urlparse.urlparse(url))
+ q = dict(parse_qsl(parsed[4]))
+ q[name] = value
+ parsed[4] = urllib.urlencode(q)
+ return urlparse.urlunparse(parsed)