|
| 1 | +import re |
| 2 | +from collections.abc import Callable, Iterable, Mapping |
| 3 | +from contextlib import AbstractContextManager |
| 4 | +from http.client import HTTPMessage |
| 5 | +from types import TracebackType |
| 6 | +from typing import Any, Literal, TypeAlias, overload |
| 7 | +from typing_extensions import ParamSpec |
| 8 | + |
| 9 | +from .http import HttpBaseClass |
| 10 | + |
| 11 | +_P = ParamSpec("_P") |
| 12 | +_HTTPMethod: TypeAlias = Literal["GET", "PUT", "POST", "DELETE", "HEAD", "PATCH", "OPTIONS", "CONNECT"] |
| 13 | +_URI: TypeAlias = str | re.Pattern[str] |
| 14 | +_HeaderValue: TypeAlias = str | int | bool | None |
| 15 | +_Headers: TypeAlias = Mapping[str, _HeaderValue] |
| 16 | +_Body: TypeAlias = str | bytes |
| 17 | +_ResponseBody: TypeAlias = _Body | Callable[[HTTPrettyRequest, str, _Headers], tuple[int, _Headers, _Body]] |
| 18 | + |
| 19 | +def set_default_thread_timeout(timeout: float) -> None: ... |
| 20 | +def get_default_thread_timeout() -> float: ... |
| 21 | + |
| 22 | +class HTTPrettyRequest(HttpBaseClass): |
| 23 | + headers: HTTPMessage |
| 24 | + raw_headers: str |
| 25 | + path: str |
| 26 | + querystring: dict[str, list[str]] |
| 27 | + parsed_body: Any |
| 28 | + created_at: float |
| 29 | + def __init__( |
| 30 | + self, headers: str | bytes, body: _Body = "", sock: object | None = None, path_encoding: str = "iso-8859-1" |
| 31 | + ) -> None: ... |
| 32 | + @property |
| 33 | + def method(self) -> str: ... |
| 34 | + @property |
| 35 | + def protocol(self) -> str: ... |
| 36 | + |
| 37 | + @property |
| 38 | + def body(self) -> str: ... |
| 39 | + @body.setter |
| 40 | + def body(self, value: _Body) -> None: ... |
| 41 | + |
| 42 | + @property |
| 43 | + def url(self) -> str: ... |
| 44 | + @property |
| 45 | + def host(self) -> str: ... |
| 46 | + def parse_querystring(self, qs: str) -> dict[str, list[str]]: ... |
| 47 | + def parse_request_body(self, body: str) -> Any: ... |
| 48 | + |
| 49 | +class EmptyRequestHeaders(dict[str, str]): ... |
| 50 | + |
| 51 | +class HTTPrettyRequestEmpty: |
| 52 | + method: str | None |
| 53 | + url: str | None |
| 54 | + body: str |
| 55 | + headers: EmptyRequestHeaders |
| 56 | + |
| 57 | +class Entry(HttpBaseClass): |
| 58 | + method: _HTTPMethod |
| 59 | + uri: str |
| 60 | + request: HTTPrettyRequest |
| 61 | + body: _Body |
| 62 | + status: int |
| 63 | + streaming: bool |
| 64 | + adding_headers: dict[str, str] |
| 65 | + forcing_headers: dict[str, str] |
| 66 | + def __init__( |
| 67 | + self, |
| 68 | + method: str, |
| 69 | + uri: str, |
| 70 | + body: _ResponseBody, |
| 71 | + adding_headers: _Headers | None = None, |
| 72 | + forcing_headers: _Headers | None = None, |
| 73 | + status: int = 200, |
| 74 | + streaming: bool = False, |
| 75 | + **headers: str, |
| 76 | + ) -> None: ... |
| 77 | + def validate(self) -> None: ... |
| 78 | + def normalize_headers(self, headers: _Headers) -> dict[str, str]: ... |
| 79 | + def fill_filekind(self, fk: Any) -> None: ... |
| 80 | + |
| 81 | +class URIInfo(HttpBaseClass): |
| 82 | + default_str_attrs: tuple[str, ...] |
| 83 | + username: str |
| 84 | + password: str |
| 85 | + hostname: str |
| 86 | + port: int |
| 87 | + path: str |
| 88 | + query: str |
| 89 | + scheme: str |
| 90 | + fragment: str |
| 91 | + last_request: HTTPrettyRequest | None |
| 92 | + def __init__( |
| 93 | + self, |
| 94 | + username: str = "", |
| 95 | + password: str = "", |
| 96 | + hostname: str = "", |
| 97 | + port: int = 80, |
| 98 | + path: str = "/", |
| 99 | + query: str = "", |
| 100 | + fragment: str = "", |
| 101 | + scheme: str = "", |
| 102 | + last_request: HTTPrettyRequest | None = None, |
| 103 | + ) -> None: ... |
| 104 | + def to_str(self, attrs: Iterable[str]) -> str: ... |
| 105 | + def str_with_query(self) -> str: ... |
| 106 | + def full_url(self, use_querystring: bool = True) -> str: ... |
| 107 | + def get_full_domain(self) -> str: ... |
| 108 | + @classmethod |
| 109 | + def from_uri(cls, uri: str, entry: Entry) -> URIInfo: ... |
| 110 | + |
| 111 | +class URIMatcher: |
| 112 | + regex: re.Pattern[str] | None |
| 113 | + info: URIInfo | None |
| 114 | + entries: list[Entry] |
| 115 | + priority: int |
| 116 | + uri: _URI |
| 117 | + def __init__(self, uri: _URI, entries: Iterable[Entry], match_querystring: bool = False, priority: int = 0) -> None: ... |
| 118 | + def matches(self, info: URIInfo) -> bool: ... |
| 119 | + def get_next_entry(self, method: _HTTPMethod, info: URIInfo, request: HTTPrettyRequest) -> Entry: ... |
| 120 | + |
| 121 | +class httpretty(HttpBaseClass): |
| 122 | + GET: Literal["GET"] |
| 123 | + PUT: Literal["PUT"] |
| 124 | + POST: Literal["POST"] |
| 125 | + DELETE: Literal["DELETE"] |
| 126 | + HEAD: Literal["HEAD"] |
| 127 | + PATCH: Literal["PATCH"] |
| 128 | + OPTIONS: Literal["OPTIONS"] |
| 129 | + CONNECT: Literal["CONNECT"] |
| 130 | + METHODS: tuple[_HTTPMethod, ...] |
| 131 | + latest_requests: list[HTTPrettyRequest] |
| 132 | + last_request: HTTPrettyRequest | HTTPrettyRequestEmpty |
| 133 | + allow_net_connect: bool |
| 134 | + @classmethod |
| 135 | + def match_uriinfo(cls, info: URIInfo) -> tuple[Entry | None, list[str]]: ... |
| 136 | + @classmethod |
| 137 | + def match_https_hostname(cls, hostname: str) -> bool: ... |
| 138 | + @classmethod |
| 139 | + def match_http_address(cls, hostname: str, port: int) -> bool: ... |
| 140 | + @classmethod |
| 141 | + def record( |
| 142 | + cls, |
| 143 | + filename: str, |
| 144 | + indentation: int = 4, |
| 145 | + encoding: str = "utf-8", |
| 146 | + verbose: bool = False, |
| 147 | + allow_net_connect: bool = True, |
| 148 | + pool_manager_params: Mapping[str, Any] | None = None, |
| 149 | + ) -> AbstractContextManager[None]: ... |
| 150 | + @classmethod |
| 151 | + def playback(cls, filename: str, allow_net_connect: bool = True, verbose: bool = False) -> AbstractContextManager[None]: ... |
| 152 | + @classmethod |
| 153 | + def reset(cls) -> None: ... |
| 154 | + @classmethod |
| 155 | + def historify_request(cls, headers: str | bytes, body: _Body = "", sock: object | None = None) -> HTTPrettyRequest: ... |
| 156 | + @classmethod |
| 157 | + def register_uri( |
| 158 | + cls, |
| 159 | + method: str, |
| 160 | + uri: _URI, |
| 161 | + body: _ResponseBody = '{"message": "HTTPretty :)"}', |
| 162 | + adding_headers: _Headers | None = None, |
| 163 | + forcing_headers: _Headers | None = None, |
| 164 | + status: int = 200, |
| 165 | + responses: Iterable[Entry] | None = None, |
| 166 | + match_querystring: bool = False, |
| 167 | + priority: int = 0, |
| 168 | + **headers: str, |
| 169 | + ) -> None: ... |
| 170 | + @classmethod |
| 171 | + def Response( |
| 172 | + cls, |
| 173 | + body: _ResponseBody, |
| 174 | + method: _HTTPMethod | None = None, |
| 175 | + uri: str | None = None, |
| 176 | + adding_headers: _Headers | None = None, |
| 177 | + forcing_headers: _Headers | None = None, |
| 178 | + status: int = 200, |
| 179 | + streaming: bool = False, |
| 180 | + **headers: str, |
| 181 | + ) -> Entry: ... |
| 182 | + @classmethod |
| 183 | + def disable(cls) -> None: ... |
| 184 | + @classmethod |
| 185 | + def is_enabled(cls) -> bool: ... |
| 186 | + @classmethod |
| 187 | + def enable(cls, allow_net_connect: bool = True, verbose: bool = False) -> None: ... |
| 188 | + |
| 189 | +class httprettized: |
| 190 | + allow_net_connect: bool |
| 191 | + verbose: bool |
| 192 | + def __init__(self, allow_net_connect: bool = True, verbose: bool = False) -> None: ... |
| 193 | + def __enter__(self) -> None: ... |
| 194 | + def __exit__( |
| 195 | + self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None |
| 196 | + ) -> None: ... |
| 197 | + |
| 198 | +@overload |
| 199 | +def httprettified(test: Callable[_P, Any]) -> Callable[_P, Any]: ... |
| 200 | +@overload |
| 201 | +def httprettified( |
| 202 | + test: None = None, allow_net_connect: bool = True, verbose: bool = False |
| 203 | +) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ... |
0 commit comments