11__all__ = [
2+ "CreatePageFactory" ,
23 "CursorFlow" ,
34 "CursorFlowFunc" ,
45 "LimitOffsetFlow" ,
910 "generic_flow" ,
1011]
1112
13+ from collections .abc import Sequence
1214from contextlib import ExitStack
13- from typing import Any , Callable , Optional
15+ from typing import Any , Callable , Optional , Protocol
1416
1517from typing_extensions import TypeAlias
1618
3032TotalFlowFunc : TypeAlias = Callable [[], AnyFlow [Optional [int ]]]
3133
3234
35+ class CreatePageFactory (Protocol ):
36+ def __call__ (
37+ self ,
38+ items : Sequence [Any ],
39+ / ,
40+ total : Optional [int ] = None ,
41+ params : Optional [AbstractParams ] = None ,
42+ ** kwargs : Any ,
43+ ) -> Any : # pragma: no cover
44+ pass
45+
46+
3347@flow
3448def create_page_flow (
3549 items : Any ,
@@ -40,6 +54,7 @@ def create_page_flow(
4054 additional_data : Optional [dict [str , Any ]] = None ,
4155 config : Optional [Config ] = None ,
4256 async_ : bool = False ,
57+ create_page_factory : Optional [CreatePageFactory ] = None ,
4358) -> Any :
4459 with ExitStack () as stack :
4560 if config and config .page_cls :
@@ -51,13 +66,18 @@ def create_page_flow(
5166 async_ = async_ ,
5267 )
5368
54- return create_page (
69+ if create_page_factory is None :
70+ create_page_factory = create_page
71+
72+ page = yield create_page_factory (
5573 t_items ,
5674 total = total ,
5775 params = params ,
5876 ** (additional_data or {}),
5977 )
6078
79+ return page
80+
6181
6282@flow
6383def generic_flow ( # noqa: C901
@@ -71,6 +91,7 @@ def generic_flow( # noqa: C901
7191 additional_data : Optional [AdditionalData ] = None ,
7292 config : Optional [Config ] = None ,
7393 async_ : bool = False ,
94+ create_page_factory : Optional [CreatePageFactory ] = None ,
7495) -> Any :
7596 types : list [ParamsType ] = []
7697 if limit_offset_flow is not None :
@@ -120,6 +141,7 @@ def generic_flow( # noqa: C901
120141 additional_data = additional_data ,
121142 config = config ,
122143 async_ = async_ ,
144+ create_page_factory = create_page_factory ,
123145 )
124146
125147 return page
0 commit comments