From ed3be007fff5a001fe23dca8343044ab10a9a624 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 24 Jul 2024 14:49:41 -0400 Subject: [PATCH] 21935: Rename SafeHTTPCache to ThreadSafeHTTPCache This mirrors the name of ThreadSafeAPIClient and clarifies what it is "safe" for. Arvados-DCO-1.1-Signed-off-by: Brett Smith --- sdk/python/arvados/api.py | 8 ++++---- sdk/python/arvados/cache.py | 6 +++--- sdk/python/tests/test_http_cache.py | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/python/arvados/api.py b/sdk/python/arvados/api.py index f4aa142486..d716777b8f 100644 --- a/sdk/python/arvados/api.py +++ b/sdk/python/arvados/api.py @@ -159,7 +159,7 @@ def _new_http_error(cls, *args, **kwargs): errors.ApiError, *args, **kwargs) apiclient_errors.HttpError.__new__ = staticmethod(_new_http_error) -class SafeHTTPCache(object): +class ThreadSafeHTTPCache: """Thread-safe replacement for `httplib2.FileCache` `arvados.api.http_cache` is the preferred way to construct this object. @@ -289,10 +289,10 @@ class ThreadSafeAPIClient(object): return getattr(self.localapi(), name) -def http_cache(data_type: str) -> Optional[SafeHTTPCache]: +def http_cache(data_type: str) -> Optional[ThreadSafeHTTPCache]: """Set up an HTTP file cache - This function constructs and returns an `arvados.api.SafeHTTPCache` + This function constructs and returns an `arvados.api.ThreadSafeHTTPCache` backed by the filesystem under a cache directory from the environment, or `None` if the directory cannot be set up. The return value can be passed to `httplib2.Http` as the `cache` argument. @@ -307,7 +307,7 @@ def http_cache(data_type: str) -> Optional[SafeHTTPCache]: except (OSError, RuntimeError): return None else: - return SafeHTTPCache(str(path), max_age=60*60*24*2) + return ThreadSafeHTTPCache(str(path), max_age=60*60*24*2) def api_client( version: str, diff --git a/sdk/python/arvados/cache.py b/sdk/python/arvados/cache.py index 3fcc769f93..97cdb5af20 100644 --- a/sdk/python/arvados/cache.py +++ b/sdk/python/arvados/cache.py @@ -3,11 +3,11 @@ # SPDX-License-Identifier: Apache-2.0 """arvados.cache - Shim compatibility module -This module used to define `arvados.api.SafeHTTPCache`. Now it only exists +This module used to define `arvados.cache.SafeHTTPCache`. Now it only exists to provide backwards compatible imports. New code should prefer to import -`arvados.api`. +`arvados.api.ThreadSafeHTTPCache`. @private """ -from .api import SafeHTTPCache +from .api import ThreadSafeHTTPCache as SafeHTTPCache diff --git a/sdk/python/tests/test_http_cache.py b/sdk/python/tests/test_http_cache.py index c6ac218e09..49feb0615c 100644 --- a/sdk/python/tests/test_http_cache.py +++ b/sdk/python/tests/test_http_cache.py @@ -15,7 +15,7 @@ import pytest from unittest import mock import arvados -import arvados.cache +import arvados.api import arvados.util from arvados._internal import basedirs @@ -30,7 +30,7 @@ class CacheTestThread(threading.Thread): self._dir = dir def run(self): - c = arvados.cache.SafeHTTPCache(self._dir) + c = arvados.api.ThreadSafeHTTPCache(self._dir) url = 'http://example.com/foo' self.ok = True for x in range(16): @@ -76,7 +76,7 @@ class CacheTest(unittest.TestCase): shutil.rmtree(self._dir) def test_cache_crud(self): - c = arvados.cache.SafeHTTPCache(self._dir, max_age=0) + c = arvados.api.ThreadSafeHTTPCache(self._dir, max_age=0) url = 'https://example.com/foo?bar=baz' data1 = _random(256) data2 = _random(128) @@ -105,6 +105,6 @@ class CacheIntegrationTest(run_test_server.TestCaseWithServers): MAIN_SERVER = {} def test_cache_used_by_default_client(self): - with mock.patch('arvados.cache.SafeHTTPCache.get') as getter: + with mock.patch('arvados.api.ThreadSafeHTTPCache.get') as getter: arvados.api('v1')._rootDesc.get('foobar') getter.assert_called() -- 2.30.2