imf_reader.utils

Utility functions

Attributes

make_request

Functions

_raise_connection_error(→ NoReturn)

Translate a requests exception into ConnectionError and raise it.

make_get_request(→ requests.Response)

Make a GET request through the shared CachedSession.

make_post_request(→ requests.Response)

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 bare requests.get so test patches on requests.get keep working.

Parameters:
  • url – URL to request.

  • use_http_cache – When False, bypass the requests-cache layer for this call and go through bare requests.get. Use this for payloads that have their own bulk-cache layer (e.g. validated SDMX zips handled by CacheManager) 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 (see make_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=False contract as make_get_request.

imf_reader.utils.make_request