Remove circular dependency.

Reviwed in https://codereview.appspot.com/7506043/.
This commit is contained in:
Joe Gregorio
2013-03-06 09:48:04 -05:00
parent e366ef0cba
commit 1024403cf9
4 changed files with 33 additions and 26 deletions

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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