BaseResolver
Pactole Index / Data / BaseResolver
Auto-generated documentation for data.base_resolver module.
BaseResolver
Show source in base_resolver.py:6
Base class for resolving available archives.
Arguments
cache_timeoutfloat, optional - Time to live for the cache in seconds. Defaults to TimeoutCache.DEFAULT_CACHE_TIMEOUT.
Examples
>>> class MyResolver(BaseResolver):
... def _load_cache(self) -> dict[str, str]:
... return {"archive.zip": "https://example.com/archive.zip"}
...
>>> resolver = MyResolver(cache_timeout=600)
>>> resolver.load()
{'archive.zip': 'https://example.com/archive.zip'}
>>> resolver.cache.expired
False
>>> resolver.load() # This will return cached result
{'archive.zip': 'https://example.com/archive.zip'}
>>> resolver.load(force=True) # This will reload the cache
{'archive.zip': 'https://example.com/archive.zip'}
>>> sleep(601) # Wait for cache to expire
>>> resolver.cache.expired
True
>>> resolver.load() # This will reload the cache
{'archive.zip': 'https://example.com/archive.zip'}
Signature
class BaseResolver:
def __init__(
self, cache_timeout: float = TimeoutCache.DEFAULT_CACHE_TIMEOUT
) -> None: ...
BaseResolver()._load_cache
Show source in base_resolver.py:111
Loads the list of available archives from the source.
This method should be implemented by subclasses.
Returns
dict[str,str] - A dictionary mapping archive filenames to their URLs.
Examples
>>> class MyResolver(BaseResolver):
... def _load_cache(self) -> dict[str, str]:
... return {"archive.zip": "https://example.com/archive.zip"}
...
>>> resolver = MyResolver(cache_timeout=600)
>>> resolver.load()
{'archive.zip': 'https://example.com/archive.zip'}
Signature
BaseResolver().cache
Show source in base_resolver.py:39
Get the memory cache instance.
Returns
TimeoutCache- The memory cache instance.
Examples
>>> resolver = BaseResolver(cache_timeout=600)
>>> resolver.cache
<pactole.utils.timeout_cache.TimeoutCache object at 0x...>
>>> resolver.cache.timeout
600
>>> resolver.cache.expired
False
Signature
BaseResolver().load
Show source in base_resolver.py:87
Loads the list of available archives.
Arguments
forcebool - If True, forces reloading the list even if cached.
Returns
dict[str,str] - A dictionary mapping archive filenames to their URLs.
Examples
>>> class MyResolver(BaseResolver):
... def _load_cache(self) -> dict[str, str]:
... return {"archive.zip": "https://example.com/archive.zip"}
...
>>> resolver = MyResolver(cache_timeout=600)
>>> resolver.load()
{'archive.zip': 'https://example.com/archive.zip'}
>>> resolver.load() # This will return cached result
{'archive.zip': 'https://example.com/archive.zip'}
>>> resolver.load(force=True) # This will reload the cache
{'archive.zip': 'https://example.com/archive.zip'}
Signature
BaseResolver().resolve
Show source in base_resolver.py:57
Resolve the URL for a given archive name.
Arguments
namestr - The name of the archive to resolve.forcebool, optional - If True, forces reloading the cache even if it's still valid. Defaults to False.
Returns
str- The URL of the resolved archive.
Raises
ValueError- If the specified archive name is not found in the available archives.
Examples
>>> class MyResolver(BaseResolver):
... def _load_cache(self) -> dict[str, str]:
... return {"archive.zip": "https://example.com/archive.zip"}
...
>>> resolver = MyResolver(cache_timeout=600)
>>> resolver.resolve("archive.zip")
'https://example.com/archive.zip'
>>> resolver.resolve("archive.zip", force=True)
'https://example.com/archive.zip'