From 7443c8eb0c3d5ab1f3380fa1bae890442bb0c65c Mon Sep 17 00:00:00 2001 From: wesley chun Date: Wed, 3 Nov 2021 19:06:16 -0700 Subject: [PATCH] rev to Py3 so GAE local tests work --- python/src/cloudstorage/__init__.py | 9 ++++----- python/src/cloudstorage/api_utils.py | 7 +++++-- python/src/cloudstorage/cloudstorage_api.py | 5 ++++- python/src/cloudstorage/errors.py | 5 ++++- python/src/cloudstorage/rest_api.py | 15 +++++---------- python/src/cloudstorage/storage_api.py | 18 ++++++++---------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/python/src/cloudstorage/__init__.py b/python/src/cloudstorage/__init__.py index 349a021..4f413ac 100644 --- a/python/src/cloudstorage/__init__.py +++ b/python/src/cloudstorage/__init__.py @@ -17,13 +17,12 @@ -from .api_utils import RetryParams -from .api_utils import set_default_retry_params -from cloudstorage_api import * +from .cloudstorage_api import * +from .api_utils import * from .common import CSFileStat from .common import GCSFileStat from .common import validate_bucket_name from .common import validate_bucket_path from .common import validate_file_path -from errors import * -from storage_api import * +from .errors import * +from .storage_api import * diff --git a/python/src/cloudstorage/api_utils.py b/python/src/cloudstorage/api_utils.py index 33e4b6e..f96fec6 100644 --- a/python/src/cloudstorage/api_utils.py +++ b/python/src/cloudstorage/api_utils.py @@ -21,7 +21,10 @@ ] import copy -import httplib +try: + import httplib +except ImportError: + import http.client as httplib import logging import math import os @@ -170,7 +173,7 @@ def run(self, tasklet, **kwds): 'Tasklet has exceeded request deadline after %s seconds total', time.time() - start_time) raise - except self.retriable_exceptions as e: + except self.retriable_exceptions: pass if n == 1: diff --git a/python/src/cloudstorage/cloudstorage_api.py b/python/src/cloudstorage/cloudstorage_api.py index 1c186d4..6d5a5c0 100644 --- a/python/src/cloudstorage/cloudstorage_api.py +++ b/python/src/cloudstorage/cloudstorage_api.py @@ -31,7 +31,10 @@ ] import logging -import StringIO +try: + import StringIO +except: + from io import StringIO import urllib import os import itertools diff --git a/python/src/cloudstorage/errors.py b/python/src/cloudstorage/errors.py index 2174380..89a205a 100644 --- a/python/src/cloudstorage/errors.py +++ b/python/src/cloudstorage/errors.py @@ -31,7 +31,10 @@ 'TransientError', ] -import httplib +try: + import httplib +except ImportError: + import http.client as httplib class Error(Exception): diff --git a/python/src/cloudstorage/rest_api.py b/python/src/cloudstorage/rest_api.py index ff02819..6f70959 100644 --- a/python/src/cloudstorage/rest_api.py +++ b/python/src/cloudstorage/rest_api.py @@ -27,14 +27,9 @@ from . import api_utils -try: - from google.appengine.api import app_identity - from google.appengine.api import lib_config - from google.appengine.ext import ndb -except ImportError: - from google.appengine.api import app_identity - from google.appengine.api import lib_config - from google.appengine.ext import ndb +from google.appengine.api import app_identity +from google.appengine.api import lib_config +from google.appengine.ext import ndb @@ -97,7 +92,7 @@ def add_sync_methods(cls): Returns: The same class, modified in place. """ - for name in cls.__dict__.keys(): + for name in list(cls.__dict__.keys()): if name.endswith('_async'): sync_name = name[:-6] if not hasattr(cls, sync_name): @@ -257,7 +252,7 @@ def urlfetch_async(self, url, method='GET', headers=None, headers.update(self.user_agent) try: self.token = yield self.get_token_async() - except app_identity.InternalError, e: + except app_identity.InternalError: if os.environ.get('DATACENTER', '').endswith('sandman'): self.token = None logging.warning('Could not fetch an authentication token in sandman ' diff --git a/python/src/cloudstorage/storage_api.py b/python/src/cloudstorage/storage_api.py index 26254fd..be773d1 100644 --- a/python/src/cloudstorage/storage_api.py +++ b/python/src/cloudstorage/storage_api.py @@ -24,20 +24,18 @@ import collections import os -import urlparse +try: + import urlparse +except ImportError: + import urllib.parse as urlparse from . import api_utils from . import common from . import errors from . import rest_api -try: - from google.appengine.api import urlfetch - from google.appengine.ext import ndb -except ImportError: - from google.appengine.api import urlfetch - from google.appengine.ext import ndb - +from google.appengine.api import urlfetch +from google.appengine.ext import ndb from google.appengine.api import app_identity @@ -135,9 +133,9 @@ def do_request_async(self, url, method='GET', headers=None, payload=None, resp_tuple = yield super(_StorageApi, self).do_request_async( url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback) - except urlfetch.DownloadError as e: + except urlfetch.DownloadError: raise errors.TimeoutError( - 'Request to Google Cloud Storage timed out.', e) + 'Request to Google Cloud Storage timed out.') raise ndb.Return(resp_tuple)