foley.sources.http#
Injectable HTTP transport for foley’s live source adapters.
Live SOURCE adapters (Freesound, #5; hosted generators, #6) speak HTTP. To keep
import foley dependency-light (dol-only) and the test suite hermetic (no
network, no HTTP library), the HTTP call is a dependency-injected callable —
a Transport — that each adapter takes by keyword, defaulting to
requests_transport(). Tests inject a fake transport returning canned
responses; the real requests is imported lazily inside
requests_transport() and nowhere else, so it stays behind the
foley[freesound] extra (never pulled by the core or by the fake-injection
tests).
A Transport is any callable with the shape:
transport(method, url, *, params=None, headers=None, json=None) -> Response
and a Response is any object exposing status_code / content /
json() — a structural subset of requests.Response (which therefore
satisfies it with no wrapper).
The keyword-only json body was added for the hosted generate adapters (#6:
ElevenLabs Sound Effects POSTs a JSON body), where Freesound (#5) only ever did
GET-with-params. It defaults to None and is passed straight through to
requests.request(..., json=...), so every existing GET caller (and the
Freesound fake transport) is unaffected.
Module Attributes
Per-request timeout (seconds) for the default requests transport. |
Functions
|
The default |
Classes
|
The minimal HTTP response surface an adapter needs. |
|
A callable performing ONE HTTP request and returning a |
- foley.sources.http.DEFAULT_TIMEOUT_S: int = 30#
Per-request timeout (seconds) for the default requests transport. A live adapter never blocks foley indefinitely on a hung connection.
- class foley.sources.http.Response(*args, **kwargs)[source]#
Bases:
ProtocolThe minimal HTTP response surface an adapter needs.
A structural subset of
requests.Response—requestssatisfies it with no wrapper, and a test double is a tiny dataclass with the same three members.
- class foley.sources.http.Transport(*args, **kwargs)[source]#
Bases:
ProtocolA callable performing ONE HTTP request and returning a
Response.The dependency-injection seam: the default is
requests_transport(); tests pass a fake. Keyword-onlyparams/headersmirrorrequests.
- foley.sources.http.requests_transport(method, url, *, params=None, headers=None, json=None)[source]#
The default
Transport— a thin, lazy wrapper overrequests.requestsis imported HERE and only here (thefoley[freesound]/foley[elevenlabs]extras), so the foley core stays dol-only and the fake-injection test path never needs an HTTP library at all. The returnedrequests.Responsestructurally satisfiesResponse.- Parameters:
- Return type:
- Returns:
The
requests.Response(aResponse).