projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
5652: Code style fixes.
[arvados.git]
/
sdk
/
python
/
arvados
/
api.py
diff --git
a/sdk/python/arvados/api.py
b/sdk/python/arvados/api.py
index d1263e24f27b2e89b3ef386d3d35a28bb9341811..e69f1a112d401c21875b2ab310e444fef2f1ddc6 100644
(file)
--- a/
sdk/python/arvados/api.py
+++ b/
sdk/python/arvados/api.py
@@
-1,5
+1,13
@@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+from __future__ import absolute_import
+from future import standard_library
+standard_library.install_aliases()
+from builtins import range
import collections
import collections
-import http
lib
+import http
.client
import httplib2
import json
import logging
import httplib2
import json
import logging
@@
-12,10
+20,10
@@
import types
import apiclient
from apiclient import discovery as apiclient_discovery
from apiclient import errors as apiclient_errors
import apiclient
from apiclient import discovery as apiclient_discovery
from apiclient import errors as apiclient_errors
-import config
-import errors
-import util
-import cache
+
from .
import config
+
from .
import errors
+
from .
import util
+
from .
import cache
_logger = logging.getLogger('arvados.api')
_logger = logging.getLogger('arvados.api')
@@
-44,7
+52,7
@@
class OrderedJsonModel(apiclient.model.JsonModel):
return body
return body
-def _intercept_http_request(self, uri, **kwargs):
+def _intercept_http_request(self, uri,
method="GET",
**kwargs):
if (self.max_request_size and
kwargs.get('body') and
self.max_request_size < len(kwargs['body'])):
if (self.max_request_size and
kwargs.get('body') and
self.max_request_size < len(kwargs['body'])):
@@
-58,7
+66,7
@@
def _intercept_http_request(self, uri, **kwargs):
kwargs['headers']['Authorization'] = 'OAuth2 %s' % self.arvados_api_token
kwargs['headers']['Authorization'] = 'OAuth2 %s' % self.arvados_api_token
- retryable =
kwargs.get('method', 'GET')
in [
+ retryable =
method
in [
'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT']
retry_count = self._retry_count if retryable else 0
'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT']
retry_count = self._retry_count if retryable else 0
@@
-67,7
+75,7
@@
def _intercept_http_request(self, uri, **kwargs):
# High probability of failure due to connection atrophy. Make
# sure this request [re]opens a new connection by closing and
# forgetting all cached connections first.
# High probability of failure due to connection atrophy. Make
# sure this request [re]opens a new connection by closing and
# forgetting all cached connections first.
- for conn in self.connections.
iter
values():
+ for conn in self.connections.values():
conn.close()
self.connections.clear()
conn.close()
self.connections.clear()
@@
-75,8
+83,8
@@
def _intercept_http_request(self, uri, **kwargs):
for _ in range(retry_count):
self._last_request_time = time.time()
try:
for _ in range(retry_count):
self._last_request_time = time.time()
try:
- return self.orig_http_request(uri, **kwargs)
- except http
lib
.HTTPException:
+ return self.orig_http_request(uri,
method,
**kwargs)
+ except http
.client
.HTTPException:
_logger.debug("Retrying API request in %d s after HTTP error",
delay, exc_info=True)
except socket.error:
_logger.debug("Retrying API request in %d s after HTTP error",
delay, exc_info=True)
except socket.error:
@@
-87,13
+95,13
@@
def _intercept_http_request(self, uri, **kwargs):
# httplib2 reopens connections when needed.
_logger.debug("Retrying API request in %d s after socket error",
delay, exc_info=True)
# httplib2 reopens connections when needed.
_logger.debug("Retrying API request in %d s after socket error",
delay, exc_info=True)
- for conn in self.connections.
iter
values():
+ for conn in self.connections.values():
conn.close()
time.sleep(delay)
delay = delay * self._retry_delay_backoff
self._last_request_time = time.time()
conn.close()
time.sleep(delay)
delay = delay * self._retry_delay_backoff
self._last_request_time = time.time()
- return self.orig_http_request(uri, **kwargs)
+ return self.orig_http_request(uri,
method,
**kwargs)
def _patch_http_request(http, api_token):
http.arvados_api_token = api_token
def _patch_http_request(http, api_token):
http.arvados_api_token = api_token
@@
-113,6
+121,7
@@
_cast_orig = apiclient_discovery._cast
def _cast_objects_too(value, schema_type):
global _cast_orig
if (type(value) != type('') and
def _cast_objects_too(value, schema_type):
global _cast_orig
if (type(value) != type('') and
+ type(value) != type(b'') and
(schema_type == 'object' or schema_type == 'array')):
return json.dumps(value)
else:
(schema_type == 'object' or schema_type == 'array')):
return json.dumps(value)
else:
@@
-136,7
+145,7
@@
def http_cache(data_type):
try:
util.mkdir_dash_p(path)
except OSError:
try:
util.mkdir_dash_p(path)
except OSError:
-
path =
None
+
return
None
return cache.SafeHTTPCache(path, max_age=60*60*24*2)
def api(version=None, cache=True, host=None, token=None, insecure=False, **kwargs):
return cache.SafeHTTPCache(path, max_age=60*60*24*2)
def api(version=None, cache=True, host=None, token=None, insecure=False, **kwargs):