From b1e26e3a48ceae8a79437179c1f210721b15def7 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Mon, 26 Mar 2018 15:21:08 -0400 Subject: [PATCH] googleapiclient 1.6.5+ --- src/googleapiclient/__init__.py | 2 +- src/googleapiclient/_auth.py | 6 +++++- src/googleapiclient/discovery.py | 4 ---- src/googleapiclient/http.py | 21 +++++++++------------ 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/googleapiclient/__init__.py b/src/googleapiclient/__init__.py index 184219af..0cbe2c3f 100644 --- a/src/googleapiclient/__init__.py +++ b/src/googleapiclient/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.6.4" +__version__ = "1.6.5" # Set default logging handler to avoid "No handler found" warnings. import logging diff --git a/src/googleapiclient/_auth.py b/src/googleapiclient/_auth.py index ada4ffb1..9d6d363f 100644 --- a/src/googleapiclient/_auth.py +++ b/src/googleapiclient/_auth.py @@ -120,6 +120,8 @@ def refresh_credentials(credentials): def apply_credentials(credentials, headers): # oauth2client and google-auth have the same interface for this. + if not is_valid(credentials): + refresh_credentials(credentials) return credentials.apply(headers) @@ -128,7 +130,9 @@ def is_valid(credentials): credentials, google.auth.credentials.Credentials): return credentials.valid else: - return not credentials.access_token_expired + return ( + credentials.access_token is not None and + not credentials.access_token_expired) def get_credentials_from_http(http): diff --git a/src/googleapiclient/discovery.py b/src/googleapiclient/discovery.py index c8956f43..fe19022c 100644 --- a/src/googleapiclient/discovery.py +++ b/src/googleapiclient/discovery.py @@ -334,10 +334,6 @@ def build_from_document( if http is not None and credentials is not None: raise ValueError('Arguments http and credentials are mutually exclusive.') - if developerKey is not None and credentials is not None: - raise ValueError( - 'Arguments developerKey and credentials are mutually exclusive.') - if isinstance(service, six.string_types): service = json.loads(service) diff --git a/src/googleapiclient/http.py b/src/googleapiclient/http.py index f5d08a19..66af5d89 100644 --- a/src/googleapiclient/http.py +++ b/src/googleapiclient/http.py @@ -63,7 +63,6 @@ except ImportError: from oauth2client import _helpers as util from googleapiclient import _auth -from googleapiclient import mimeparse from googleapiclient.errors import BatchError from googleapiclient.errors import HttpError from googleapiclient.errors import InvalidChunkSizeError @@ -75,7 +74,7 @@ from googleapiclient.model import JsonModel LOGGER = logging.getLogger(__name__) -DEFAULT_CHUNK_SIZE = 512*1024 +DEFAULT_CHUNK_SIZE = 100*1024*1024 MAX_URI_LENGTH = 2048 @@ -89,7 +88,7 @@ def _should_retry_response(resp_status, content): Args: resp_status: The response status received. - content: The response content body. + content: The response content body. Returns: True if the response should be retried, otherwise False. @@ -112,7 +111,10 @@ def _should_retry_response(resp_status, content): # Content is in JSON format. try: data = json.loads(content.decode('utf-8')) - reason = data['error']['errors'][0]['reason'] + if isinstance(data, dict): + reason = data['error']['errors'][0]['reason'] + else: + reason = data[0]['error']['errors']['reason'] except (UnicodeDecodeError, ValueError, KeyError): LOGGER.warning('Invalid JSON content from response: %s', content) return False @@ -510,7 +512,6 @@ class MediaFileUpload(MediaIoBaseUpload): Construct a MediaFileUpload and pass as the media_body parameter of the method. For example, if we had a service that allowed uploading images: - media = MediaFileUpload('cow.png', mimetype='image/png', chunksize=1024*1024, resumable=True) farm.animals().insert( @@ -654,9 +655,9 @@ class MediaIoBaseDownload(object): request only once. Returns: - (status, done): (MediaDownloadStatus, boolean) + (status, done): (MediaDownloadProgress, boolean) The value of 'done' will be True when the media has been fully - downloaded. + downloaded or the total size of the media is unknown. Raises: googleapiclient.errors.HttpError if the response was not a 2xx. @@ -685,7 +686,7 @@ class MediaIoBaseDownload(object): elif 'content-length' in resp: self._total_size = int(resp['content-length']) - if self._progress == self._total_size: + if self._total_size is None or self._progress == self._total_size: self._done = True return MediaDownloadProgress(self._progress, self._total_size), self._done else: @@ -767,10 +768,6 @@ class HttpRequest(object): self.response_callbacks = [] self._in_error_state = False - # Pull the multipart boundary out of the content-type header. - major, minor, params = mimeparse.parse_mime_type( - self.headers.get('content-type', 'application/json')) - # The size of the non-media part of the request. self.body_size = len(self.body or '')