Skip to content

Commit

Permalink
GYB 1.2 - fix Google Auth errors by allowing user project creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jay0lee committed Mar 22, 2019
1 parent 30cdd5c commit 3158a6a
Show file tree
Hide file tree
Showing 150 changed files with 23,165 additions and 1,245 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -59,6 +59,7 @@ GYB-GMail-Backup-*/
lastcheck.txt
gyb/
oauth2service.json
client_secrets.json

# Prevents committing private key.
privatekey.p12
Expand All @@ -69,4 +70,4 @@ privatekey.p12
*.msi
*.tar.xz
*.wixobj
*.wixpdb
*.wixpdb
15 changes: 0 additions & 15 deletions client_secrets.json

This file was deleted.

2 changes: 1 addition & 1 deletion googleapiclient/__init__.py
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.7.3"
__version__ = "1.7.8"

# Set default logging handler to avoid "No handler found" warnings.
import logging
Expand Down
16 changes: 15 additions & 1 deletion googleapiclient/channel.py
@@ -1,3 +1,17 @@
# Copyright 2014 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Channel notifications support.
Classes and functions to support channel subscriptions and notifications
Expand Down Expand Up @@ -53,7 +67,7 @@
Example of unsubscribing.
service.channels().stop(channel.body())
service.channels().stop(channel.body()).execute()
"""
from __future__ import absolute_import

Expand Down
17 changes: 12 additions & 5 deletions googleapiclient/discovery.py
Expand Up @@ -126,14 +126,16 @@ class _BytesGenerator(BytesGenerator):
_write_lines = BytesGenerator.write

def fix_method_name(name):
"""Fix method names to avoid reserved word conflicts.
"""Fix method names to avoid '$' characters and reserved word conflicts.
Args:
name: string, method name.
Returns:
The name with an '_' appended if the name is a reserved word.
The name with '_' appended if the name is a reserved word and '$'
replaced with '_'.
"""
name = name.replace('$', '_')
if keyword.iskeyword(name) or name in RESERVED_WORDS:
return name + '_'
else:
Expand Down Expand Up @@ -219,7 +221,7 @@ def build(serviceName,

try:
content = _retrieve_discovery_doc(
requested_url, discovery_http, cache_discovery, cache)
requested_url, discovery_http, cache_discovery, cache, developerKey)
return build_from_document(content, base=discovery_url, http=http,
developerKey=developerKey, model=model, requestBuilder=requestBuilder,
credentials=credentials)
Expand All @@ -233,7 +235,8 @@ def build(serviceName,
"name: %s version: %s" % (serviceName, version))


def _retrieve_discovery_doc(url, http, cache_discovery, cache=None):
def _retrieve_discovery_doc(url, http, cache_discovery, cache=None,
developerKey=None):
"""Retrieves the discovery_doc from cache or the internet.
Args:
Expand Down Expand Up @@ -264,6 +267,8 @@ def _retrieve_discovery_doc(url, http, cache_discovery, cache=None):
# document to avoid exceeding the quota on discovery requests.
if 'REMOTE_ADDR' in os.environ:
actual_url = _add_query_parameter(url, 'userIp', os.environ['REMOTE_ADDR'])
if developerKey:
actual_url = _add_query_parameter(url, 'key', developerKey)
logger.info('URL being requested: GET %s', actual_url)

resp, content = http.request(actual_url)
Expand Down Expand Up @@ -360,7 +365,9 @@ def build_from_document(
# The credentials need to be scoped.
credentials = _auth.with_scopes(credentials, scopes)

# Create an authorized http instance
# If credentials are provided, create an authorized http instance;
# otherwise, skip authentication.
if credentials:
http = _auth.authorized_http(credentials)

# If the service doesn't require scopes then there is no need for
Expand Down
32 changes: 25 additions & 7 deletions googleapiclient/http.py
Expand Up @@ -73,6 +73,8 @@

MAX_URI_LENGTH = 2048

MAX_BATCH_LIMIT = 1000

_TOO_MANY_REQUESTS = 429

DEFAULT_HTTP_TIMEOUT_SEC = 60
Expand Down Expand Up @@ -173,6 +175,8 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
'WSAETIMEDOUT', 'ETIMEDOUT', 'EPIPE', 'ECONNABORTED'}:
raise
exception = socket_error
except httplib2.ServerNotFoundError as server_not_found_error:
exception = server_not_found_error

if exception:
if retry_num == num_retries:
Expand Down Expand Up @@ -645,6 +649,14 @@ def __init__(self, fd, request, chunksize=DEFAULT_CHUNK_SIZE):
self._sleep = time.sleep
self._rand = random.random

self._headers = {}
for k, v in six.iteritems(request.headers):
# allow users to supply custom headers by setting them on the request
# but strip out the ones that are set by default on requests generated by
# API methods like Drive's files().get(fileId=...)
if not k.lower() in ('accept', 'accept-encoding', 'user-agent'):
self._headers[k] = v

@util.positional(1)
def next_chunk(self, num_retries=0):
"""Get the next chunk of the download.
Expand All @@ -664,10 +676,9 @@ def next_chunk(self, num_retries=0):
googleapiclient.errors.HttpError if the response was not a 2xx.
httplib2.HttpLib2Error if a transport error has occured.
"""
headers = {
'range': 'bytes=%d-%d' % (
headers = self._headers.copy()
headers['range'] = 'bytes=%d-%d' % (
self._progress, self._progress + self._chunksize)
}
http = self._request.http

resp, content = _retry_request(
Expand Down Expand Up @@ -1169,7 +1180,10 @@ def _id_to_header(self, id_):
if self._base_id is None:
self._base_id = uuid.uuid4()

return '<%s+%s>' % (self._base_id, quote(id_))
# NB: we intentionally leave whitespace between base/id and '+', so RFC2822
# line folding works properly on Python 3; see
# https://github.com/google/google-api-python-client/issues/164
return '<%s + %s>' % (self._base_id, quote(id_))

def _header_to_id(self, header):
"""Convert a Content-ID header value to an id.
Expand All @@ -1190,7 +1204,7 @@ def _header_to_id(self, header):
raise BatchError("Invalid value for Content-ID: %s" % header)
if '+' not in header:
raise BatchError("Invalid value for Content-ID: %s" % header)
base, id_ = header[1:-1].rsplit('+', 1)
base, id_ = header[1:-1].split(' + ', 1)

return unquote(id_)

Expand Down Expand Up @@ -1300,8 +1314,8 @@ def add(self, request, callback=None, request_id=None):
request id, and the second is the deserialized response object. The
third is an googleapiclient.errors.HttpError exception object if an HTTP error
occurred while processing the request, or None if no errors occurred.
request_id: string, A unique id for the request. The id will be passed to
the callback with the response.
request_id: string, A unique id for the request. The id will be passed
to the callback with the response.
Returns:
None
Expand All @@ -1310,6 +1324,10 @@ def add(self, request, callback=None, request_id=None):
BatchError if a media request is added to a batch.
KeyError is the request_id is not unique.
"""

if len(self._order) >= MAX_BATCH_LIMIT:
raise BatchError("Exceeded the maximum calls(%d) in a single batch request."
% MAX_BATCH_LIMIT)
if request_id is None:
request_id = self._new_id()
if request.resumable is not None:
Expand Down
15 changes: 7 additions & 8 deletions googleapiclient/sample_tools.py
Expand Up @@ -28,14 +28,6 @@
from googleapiclient import discovery
from googleapiclient.http import build_http

try:
from oauth2client import client
from oauth2client import file
from oauth2client import tools
except ImportError:
raise ImportError('googleapiclient.sample_tools requires oauth2client. Please install oauth2client and try again.')


def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_filename=None):
"""A common initialization routine for samples.
Expand All @@ -60,6 +52,13 @@ def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_f
A tuple of (service, flags), where service is the service object and flags
is the parsed command-line flags.
"""
try:
from oauth2client import client
from oauth2client import file
from oauth2client import tools
except ImportError:
raise ImportError('googleapiclient.sample_tools requires oauth2client. Please install oauth2client and try again.')

if scope is None:
scope = 'https://www.googleapis.com/auth/' + name

Expand Down

0 comments on commit 3158a6a

Please sign in to comment.