diff --git a/apiclient/discovery.py b/apiclient/discovery.py index 580db0e..19af41a 100644 --- a/apiclient/discovery.py +++ b/apiclient/discovery.py @@ -58,6 +58,7 @@ from apiclient.schema import Schemas from email.mime.multipart import MIMEMultipart from email.mime.nonmultipart import MIMENonMultipart from oauth2client.util import positional +from oauth2client.util import _add_query_parameter from oauth2client.anyjson import simplejson # The client library requires a version of httplib2 that supports RETRIES. @@ -108,29 +109,6 @@ def fix_method_name(name): return name -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) - - def key2param(key): """Converts key names into parameter names. 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 db 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 @@ class OAuth2Decorator(object): 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 gflags 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 @@ def dict_to_tuple_key(dictionary): 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) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 92213ac..b8b5ac0 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -41,7 +41,6 @@ except ImportError: from cgi import parse_qs -from apiclient.discovery import _add_query_parameter from apiclient.discovery import _fix_up_media_upload from apiclient.discovery import _fix_up_method_description from apiclient.discovery import _fix_up_parameters @@ -68,6 +67,7 @@ from apiclient.http import tunnel_patch from oauth2client import GOOGLE_TOKEN_URI from oauth2client.anyjson import simplejson from oauth2client.client import OAuth2Credentials +from oauth2client.util import _add_query_parameter import uritemplate