Skip to content

Commit 6101a34

Browse files
committed
refactor(ogc): colocate ChunkedCall contract
Keep the private fetch/finalize aliases and default finalizer adjacent to their sole consumer.
1 parent 0b76978 commit 6101a34

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

dataretrieval/ogc/chunking.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,6 @@
101101
_retry,
102102
)
103103

104-
# ---------------------------------------------------------------------------
105-
# Type aliases for the ChunkedCall contract.
106-
# ---------------------------------------------------------------------------
107-
108-
# The per-sub-request fetcher the decorator wraps and ``ChunkedCall`` drives:
109-
# an ``async def fetch(args) -> (df, response)``.
110-
_Fetch = Callable[[dict[str, Any]], Awaitable[tuple[pd.DataFrame, httpx.Response]]]
111-
112-
# Caller-supplied transform applied to the combined chunk result, so a
113-
# resumed call returns the same shape as an un-interrupted one rather than
114-
# the chunker's raw ``(frame, httpx.Response)``. This keeps the chunker
115-
# generic: the OGC getters inject their post-processing (type coercion,
116-
# column arrangement, ``BaseMetadata``) through ``_finalize_ogc``.
117-
# The default is identity, so direct ``ChunkedCall`` use is unaffected.
118-
_Finalize = Callable[[pd.DataFrame, httpx.Response], tuple[pd.DataFrame, Any]]
119-
120-
121-
def _passthrough_result(
122-
frame: pd.DataFrame, response: httpx.Response
123-
) -> tuple[pd.DataFrame, Any]:
124-
"""Default :data:`_Finalize`: return the raw combined pair unchanged."""
125-
return frame, response
126-
127-
128104
# Empirically the API replies HTTP 414 above ~8200 bytes of full URL —
129105
# matches nginx's default ``large_client_header_buffers`` of 8 KB. 8000
130106
# leaves ~200 bytes for request-line framing and proxy variance. The decorator
@@ -312,6 +288,30 @@ def parallel_chunks(n: int) -> Iterator[None]:
312288
yield
313289

314290

291+
# ---------------------------------------------------------------------------
292+
# Type aliases for the ChunkedCall contract.
293+
# ---------------------------------------------------------------------------
294+
295+
# The per-sub-request fetcher the decorator wraps and ``ChunkedCall`` drives:
296+
# an ``async def fetch(args) -> (df, response)``.
297+
_Fetch = Callable[[dict[str, Any]], Awaitable[tuple[pd.DataFrame, httpx.Response]]]
298+
299+
# Caller-supplied transform applied to the combined chunk result, so a
300+
# resumed call returns the same shape as an un-interrupted one rather than
301+
# the chunker's raw ``(frame, httpx.Response)``. This keeps the chunker
302+
# generic: the OGC getters inject their post-processing (type coercion,
303+
# column arrangement, ``BaseMetadata``) through ``_finalize_ogc``.
304+
# The default is identity, so direct ``ChunkedCall`` use is unaffected.
305+
_Finalize = Callable[[pd.DataFrame, httpx.Response], tuple[pd.DataFrame, Any]]
306+
307+
308+
def _passthrough_result(
309+
frame: pd.DataFrame, response: httpx.Response
310+
) -> tuple[pd.DataFrame, Any]:
311+
"""Default :data:`_Finalize`: return the raw combined pair unchanged."""
312+
return frame, response
313+
314+
315315
class ChunkedCall:
316316
"""
317317
Stateful handle for a chunked call.

0 commit comments

Comments
 (0)