projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
9135: Add basic tests for Python events listeners.
[arvados.git]
/
sdk
/
python
/
arvados
/
safeapi.py
diff --git
a/sdk/python/arvados/safeapi.py
b/sdk/python/arvados/safeapi.py
index d38763c023fb200395130bdbceff5dbb8c8e2e62..5c5c87250ac678f9b9bf93cbf56cb335707c6554 100644
(file)
--- a/
sdk/python/arvados/safeapi.py
+++ b/
sdk/python/arvados/safeapi.py
@@
-2,31
+2,30
@@
import threading
import api
import keep
import config
import api
import keep
import config
+import copy
+
+class ThreadSafeApiCache(object):
+ """Threadsafe wrapper for API objects.
+
+ This stores and returns a different api object per thread, because httplib2
+ which underlies apiclient is not threadsafe.
-class SafeApi(object):
- """Threadsafe wrapper for API object. This stores and returns a different api
- object per thread, because httplib2 which underlies apiclient is not
- threadsafe.
"""
def __init__(self, apiconfig=None, keep_params={}):
"""
def __init__(self, apiconfig=None, keep_params={}):
- if not apiconfig:
- apiconfig = config
- self.host = apiconfig.get('ARVADOS_API_HOST')
- self.api_token = apiconfig.get('ARVADOS_API_TOKEN')
- self.insecure = apiconfig.flag_is_true('ARVADOS_API_HOST_INSECURE')
+ if apiconfig is None:
+ apiconfig = config.settings()
+ self.apiconfig = copy.copy(apiconfig)
self.local = threading.local()
self.keep = keep.KeepClient(api_client=self, **keep_params)
def localapi(self):
if 'api' not in self.local.__dict__:
self.local = threading.local()
self.keep = keep.KeepClient(api_client=self, **keep_params)
def localapi(self):
if 'api' not in self.local.__dict__:
- self.local.api = api.api('v1', False, self.host,
- self.api_token, self.insecure)
+ self.local.api = api.api_from_config('v1', apiconfig=self.apiconfig)
return self.local.api
def __getattr__(self, name):
# Proxy nonexistent attributes to the thread-local API client.
return self.local.api
def __getattr__(self, name):
# Proxy nonexistent attributes to the thread-local API client.
- try:
- return getattr(self.localapi(), name)
- except AttributeError:
- return super(SafeApi, self).__getattr__(name)
+ if name == "api_token":
+ return self.apiconfig['ARVADOS_API_TOKEN']
+ return getattr(self.localapi(), name)