imf_reader.utils
Utility functions
Attributes
Functions
|
Translate a requests exception into ConnectionError and raise it. |
|
Make a GET request through the shared CachedSession. |
|
Make a POST request through the shared CachedSession. |
Module Contents
- imf_reader.utils._raise_connection_error(url: str, exc: Exception) NoReturn
Translate a requests exception into ConnectionError and raise it.
Always raises; return type Never so callers’ control flow is understood.
- imf_reader.utils.make_get_request(url: str, *, use_http_cache: bool = True) requests.Response
Make a GET request through the shared CachedSession.
When caching is disabled (e.g. via
cache.disable_cache()), falls through to barerequests.getso test patches onrequests.getkeep working.- Parameters:
url – URL to request.
use_http_cache – When
False, bypass the requests-cache layer for this call and go through barerequests.get. Use this for payloads that have their own bulk-cache layer (e.g. validated SDMX zips handled byCacheManager) so a corrupt response cannot be retained by the HTTP cache and re-served on retry.
- Returns:
the response object.
- Return type:
requests.Response
- Raises:
ConnectionError – on any network failure or non-2xx HTTP response. The cache does not silently fall back to stale data on 5xx (
stale_if_error=False).
- imf_reader.utils.make_post_request(url: str, *, data: dict | None = None, use_http_cache: bool = True) requests.Response
Make a POST request through the shared CachedSession.
When caching is disabled, falls through to bare
requests.post.- Parameters:
url – URL to POST to.
data – Optional form data dict.
use_http_cache – When
False, bypass the requests-cache layer for this call (seemake_get_request()for rationale).
- Returns:
the response object.
- Return type:
requests.Response
- Raises:
ConnectionError – on any network failure or non-2xx HTTP response. Same
stale_if_error=Falsecontract asmake_get_request.
- imf_reader.utils.make_request