-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
33 lines (22 loc) · 787 Bytes
/
base.py
File metadata and controls
33 lines (22 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import Generic, List, TypeVar
from pydantic import BaseModel, ConfigDict, RootModel
from pydantic.alias_generators import to_camel
from ..http_client import APIHttpClient
from .handler import _APIOperationExecutor
ModelT = TypeVar("ModelT")
class ResourceBase(_APIOperationExecutor):
def __init__(self, http_client: APIHttpClient):
self._http_client = http_client
class CamelModel(BaseModel):
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
)
class ResourceList(RootModel[List[ModelT]], Generic[ModelT]):
root: List[ModelT]
def __iter__(self):
return iter(self.root)
def __getitem__(self, item):
return self.root[item]
def __len__(self):
return len(self.root)