Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/tools/chromevox_webstore_util.py |
| diff --git a/chrome/browser/resources/chromeos/chromevox/tools/chromevox_webstore_util.py b/chrome/browser/resources/chromeos/chromevox/tools/chromevox_webstore_util.py |
| index 5aa96f707d8e43b9c7bb6a21f045334c4a72a878..588c14ee19f0deec85e0e1b716583f60547599ae 100755 |
| --- a/chrome/browser/resources/chromeos/chromevox/tools/chromevox_webstore_util.py |
| +++ b/chrome/browser/resources/chromeos/chromevox/tools/chromevox_webstore_util.py |
| @@ -24,7 +24,10 @@ PROJECT_ARGS = { |
| 'redirect_uri': 'http://localhost:8000' |
| } |
| +# Globals. |
| PORT = 8000 |
| +auth_code = None |
|
dmazzoni
2015/02/20 23:03:01
No strong preference, but maybe g_auth_code? I'm n
David Tseng
2015/02/20 23:34:52
Done.
|
| +oauth_token = None |
| APP_ID = 'kgejglhpjiefppelpmljglcjbhoiplfn' |
| OAUTH_DOMAIN = 'accounts.google.com' |
| @@ -45,6 +48,10 @@ class CodeRequestHandler(SocketServer.StreamRequestHandler): |
| self.rfile.close() |
| def GetAuthCode(): |
| + global auth_code |
| + if auth_code: |
| + return auth_code |
| + |
| Handler = CodeRequestHandler |
| httpd = SocketServer.TCPServer(("", PORT), Handler) |
| query = '&'.join(['response_type=code', |
| @@ -56,9 +63,14 @@ def GetAuthCode(): |
| webbrowser.open(auth_url) |
| httpd.handle_request() |
| httpd.server_close() |
| - return httpd.code |
| + auth_code = httpd.code |
| + return auth_code |
| def GetOauthToken(code, client_secret): |
| + global oauth_token |
| + if oauth_token: |
| + return oauth_token |
| + |
| PROJECT_ARGS['code'] = code |
| PROJECT_ARGS['client_secret'] = client_secret |
| body = urllib.urlencode(PROJECT_ARGS) |
| @@ -69,11 +81,14 @@ def GetOauthToken(code, client_secret): |
| conn.endheaders() |
| conn.send(body) |
| content = conn.getresponse().read() |
| - return json.loads(content) |
| + conn.close() |
| + oauth_token = json.loads(content) |
| + return oauth_token |
| def GetPopulatedHeader(client_secret): |
| code = GetAuthCode() |
| access_token = GetOauthToken(code, client_secret) |
| + print "a!"+str(access_token) |
|
dmazzoni
2015/02/20 23:03:01
debugging?
David Tseng
2015/02/20 23:34:52
Oops; removed.
|
| url = 'www.googleapis.com' |
| return {'Authorization': 'Bearer %(access_token)s' % access_token, |
| @@ -85,14 +100,18 @@ def SendGetCommand(command, client_secret): |
| headers = GetPopulatedHeader(client_secret) |
| conn = httplib.HTTPSConnection(API_ENDPOINT_DOMAIN) |
| conn.request('GET', command, '', headers) |
| - return conn.getresponse() |
| + r = conn.getresponse() |
| + conn.close() |
| + return r |
| def SendPostCommand(command, client_secret, header_additions = {}, body=None): |
| headers = GetPopulatedHeader(client_secret) |
| headers = dict(headers.items() + header_additions.items()) |
| conn = httplib.HTTPSConnection(API_ENDPOINT_DOMAIN) |
| conn.request('POST', command, body, headers) |
| - return conn.getresponse() |
| + r = conn.getresponse() |
| + conn.close() |
| + return r |
| def GetUploadStatus(client_secret): |
| '''Gets the status of a previous upload. |