| | from __future__ import annotations |
| |
|
| | from os import PathLike |
| | from typing import ( |
| | IO, |
| | TYPE_CHECKING, |
| | Any, |
| | Dict, |
| | List, |
| | Type, |
| | Tuple, |
| | Union, |
| | Mapping, |
| | TypeVar, |
| | Callable, |
| | Iterable, |
| | Iterator, |
| | Optional, |
| | Sequence, |
| | AsyncIterable, |
| | ) |
| | from typing_extensions import ( |
| | Set, |
| | Literal, |
| | Protocol, |
| | TypeAlias, |
| | TypedDict, |
| | SupportsIndex, |
| | overload, |
| | override, |
| | runtime_checkable, |
| | ) |
| |
|
| | import httpx |
| | import pydantic |
| | from httpx import URL, Proxy, Timeout, Response, BaseTransport, AsyncBaseTransport |
| |
|
| | if TYPE_CHECKING: |
| | from ._models import BaseModel |
| | from ._response import APIResponse, AsyncAPIResponse |
| | from ._legacy_response import HttpxBinaryResponseContent |
| |
|
| | Transport = BaseTransport |
| | AsyncTransport = AsyncBaseTransport |
| | Query = Mapping[str, object] |
| | Body = object |
| | AnyMapping = Mapping[str, object] |
| | ModelT = TypeVar("ModelT", bound=pydantic.BaseModel) |
| | _T = TypeVar("_T") |
| |
|
| |
|
| | |
| | |
| | ProxiesDict = Dict["str | URL", Union[None, str, URL, Proxy]] |
| | ProxiesTypes = Union[str, Proxy, ProxiesDict] |
| | if TYPE_CHECKING: |
| | Base64FileInput = Union[IO[bytes], PathLike[str]] |
| | FileContent = Union[IO[bytes], bytes, PathLike[str]] |
| | else: |
| | Base64FileInput = Union[IO[bytes], PathLike] |
| | FileContent = Union[IO[bytes], bytes, PathLike] |
| |
|
| |
|
| | |
| | |
| | BinaryTypes = Union[bytes, bytearray, IO[bytes], Iterable[bytes]] |
| | AsyncBinaryTypes = Union[bytes, bytearray, IO[bytes], AsyncIterable[bytes]] |
| |
|
| | FileTypes = Union[ |
| | |
| | FileContent, |
| | |
| | Tuple[Optional[str], FileContent], |
| | |
| | Tuple[Optional[str], FileContent, Optional[str]], |
| | |
| | Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], |
| | ] |
| | RequestFiles = Union[Mapping[str, FileTypes], Sequence[Tuple[str, FileTypes]]] |
| |
|
| | |
| | HttpxFileContent = Union[IO[bytes], bytes] |
| | HttpxFileTypes = Union[ |
| | |
| | HttpxFileContent, |
| | |
| | Tuple[Optional[str], HttpxFileContent], |
| | |
| | Tuple[Optional[str], HttpxFileContent, Optional[str]], |
| | |
| | Tuple[Optional[str], HttpxFileContent, Optional[str], Mapping[str, str]], |
| | ] |
| | HttpxRequestFiles = Union[Mapping[str, HttpxFileTypes], Sequence[Tuple[str, HttpxFileTypes]]] |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | if TYPE_CHECKING: |
| | NoneType: Type[None] |
| | else: |
| | NoneType = type(None) |
| |
|
| |
|
| | class RequestOptions(TypedDict, total=False): |
| | headers: Headers |
| | max_retries: int |
| | timeout: float | Timeout | None |
| | params: Query |
| | extra_json: AnyMapping |
| | idempotency_key: str |
| | follow_redirects: bool |
| |
|
| |
|
| | |
| | class NotGiven: |
| | """ |
| | For parameters with a meaningful None value, we need to distinguish between |
| | the user explicitly passing None, and the user not passing the parameter at |
| | all. |
| | |
| | User code shouldn't need to use not_given directly. |
| | |
| | For example: |
| | |
| | ```py |
| | def create(timeout: Timeout | None | NotGiven = not_given): ... |
| | |
| | |
| | create(timeout=1) # 1s timeout |
| | create(timeout=None) # No timeout |
| | create() # Default timeout behavior |
| | ``` |
| | """ |
| |
|
| | def __bool__(self) -> Literal[False]: |
| | return False |
| |
|
| | @override |
| | def __repr__(self) -> str: |
| | return "NOT_GIVEN" |
| |
|
| |
|
| | not_given = NotGiven() |
| | |
| | NOT_GIVEN = NotGiven() |
| |
|
| |
|
| | class Omit: |
| | """ |
| | To explicitly omit something from being sent in a request, use `omit`. |
| | |
| | ```py |
| | # as the default `Content-Type` header is `application/json` that will be sent |
| | client.post("/upload/files", files={"file": b"my raw file content"}) |
| | |
| | # you can't explicitly override the header as it has to be dynamically generated |
| | # to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983' |
| | client.post(..., headers={"Content-Type": "multipart/form-data"}) |
| | |
| | # instead you can remove the default `application/json` header by passing omit |
| | client.post(..., headers={"Content-Type": omit}) |
| | ``` |
| | """ |
| |
|
| | def __bool__(self) -> Literal[False]: |
| | return False |
| |
|
| |
|
| | omit = Omit() |
| |
|
| |
|
| | @runtime_checkable |
| | class ModelBuilderProtocol(Protocol): |
| | @classmethod |
| | def build( |
| | cls: type[_T], |
| | *, |
| | response: Response, |
| | data: object, |
| | ) -> _T: ... |
| |
|
| |
|
| | Headers = Mapping[str, Union[str, Omit]] |
| |
|
| |
|
| | class HeadersLikeProtocol(Protocol): |
| | def get(self, __key: str) -> str | None: ... |
| |
|
| |
|
| | HeadersLike = Union[Headers, HeadersLikeProtocol] |
| |
|
| | ResponseT = TypeVar( |
| | "ResponseT", |
| | bound=Union[ |
| | object, |
| | str, |
| | None, |
| | "BaseModel", |
| | List[Any], |
| | Dict[str, Any], |
| | Response, |
| | ModelBuilderProtocol, |
| | "APIResponse[Any]", |
| | "AsyncAPIResponse[Any]", |
| | "HttpxBinaryResponseContent", |
| | ], |
| | ) |
| |
|
| | StrBytesIntFloat = Union[str, bytes, int, float] |
| |
|
| | |
| | |
| | IncEx: TypeAlias = Union[Set[int], Set[str], Mapping[int, Union["IncEx", bool]], Mapping[str, Union["IncEx", bool]]] |
| |
|
| | PostParser = Callable[[Any], Any] |
| |
|
| |
|
| | @runtime_checkable |
| | class InheritsGeneric(Protocol): |
| | """Represents a type that has inherited from `Generic` |
| | |
| | The `__orig_bases__` property can be used to determine the resolved |
| | type variable for a given base class. |
| | """ |
| |
|
| | __orig_bases__: tuple[_GenericAlias] |
| |
|
| |
|
| | class _GenericAlias(Protocol): |
| | __origin__: type[object] |
| |
|
| |
|
| | class HttpxSendArgs(TypedDict, total=False): |
| | auth: httpx.Auth |
| | follow_redirects: bool |
| |
|
| |
|
| | _T_co = TypeVar("_T_co", covariant=True) |
| |
|
| |
|
| | if TYPE_CHECKING: |
| | |
| | |
| | |
| | |
| | |
| | class SequenceNotStr(Protocol[_T_co]): |
| | @overload |
| | def __getitem__(self, index: SupportsIndex, /) -> _T_co: ... |
| | @overload |
| | def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ... |
| | def __contains__(self, value: object, /) -> bool: ... |
| | def __len__(self) -> int: ... |
| | def __iter__(self) -> Iterator[_T_co]: ... |
| | def __reversed__(self) -> Iterator[_T_co]: ... |
| | else: |
| | |
| | |
| | SequenceNotStr = Sequence |
| |
|