diff options
author | shadchin <shadchin@yandex-team.com> | 2024-03-04 21:16:16 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2024-03-04 21:43:39 +0300 |
commit | 74819c4157bd388a7d429c870ea4b343a282dafa (patch) | |
tree | 4bff355b03dfb24b14d33581357cc8e624d170fd /contrib/python/requests-mock | |
parent | f64c28a5443395e3a8f27e6f1b15a3507812d2de (diff) | |
download | ydb-74819c4157bd388a7d429c870ea4b343a282dafa.tar.gz |
Extend support pyi files
Сейчас pyi файлы в макросе PY_SRCS используются исключительно в Arcadia плагине для продуктов JB, при сборке эти файлы просто игнорируются.
В этом PR добавил шаг, который будет содержимое этих файлов складывать в ресурсы, секция PY_SRCS удобна тем, что позволяет раскладывать pyi файлы с учетом TOP_LEVEL/NAMESPACE, а это необходимо для правильной работы mypy.
3924b0556bc99947e6893cd79e5ce62ec72a18a9
Diffstat (limited to 'contrib/python/requests-mock')
7 files changed, 469 insertions, 0 deletions
diff --git a/contrib/python/requests-mock/py3/requests_mock/__init__.pyi b/contrib/python/requests-mock/py3/requests_mock/__init__.pyi new file mode 100644 index 0000000000..9d8dd002e9 --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/__init__.pyi @@ -0,0 +1,33 @@ +# Stubs for requests_mock + +from requests_mock.adapter import ( + ANY as ANY, + Adapter as Adapter, + Callback as Callback, + AdditionalMatcher as AdditionalMatcher, +) +from requests_mock.exceptions import ( + MockException as MockException, + NoMockAddress as NoMockAddress, +) +from requests_mock.mocker import ( + DELETE as DELETE, + GET as GET, + HEAD as HEAD, + Mocker as Mocker, + MockerCore as MockerCore, + OPTIONS as OPTIONS, + PATCH as PATCH, + POST as POST, + PUT as PUT, + mock as mock, +) +from requests_mock.request import ( + Request as Request, + _RequestObjectProxy as _RequestObjectProxy, # For backward compatibility +) +from requests_mock.response import ( + CookieJar as CookieJar, + create_response as create_response, + Context as Context, +) diff --git a/contrib/python/requests-mock/py3/requests_mock/adapter.pyi b/contrib/python/requests-mock/py3/requests_mock/adapter.pyi new file mode 100644 index 0000000000..dbeba496ba --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/adapter.pyi @@ -0,0 +1,75 @@ +# Stubs for requests_mock.adapter + +from http.cookiejar import CookieJar +from io import IOBase +from typing import Any, Callable, Dict, List, NewType, Optional, Pattern, Type, TypeVar, Union + +from requests import Response +from requests.adapters import BaseAdapter +from urllib3.response import HTTPResponse + +from requests_mock.request import Request +from requests_mock.response import Context + +AnyMatcher = NewType("AnyMatcher", object) + +ANY: AnyMatcher = ... + +T = TypeVar('T') +Callback = Callable[[Request, Context], T] +Matcher = Callable[[Request], Optional[Response]] +AdditionalMatcher = Callable[[Request], bool] + +class _RequestHistoryTracker: + request_history: List[Request] = ... + def __init__(self) -> None: ... + @property + def last_request(self) -> Optional[Request]: ... + @property + def called(self) -> bool: ... + @property + def called_once(self) -> bool: ... + @property + def call_count(self) -> int: ... + +class _RunRealHTTP(Exception): ... + +class _Matcher(_RequestHistoryTracker): + def __init__( + self, + method: Any, + url: Any, + responses: Any, + complete_qs: Any, + request_headers: Any, + additional_matcher: AdditionalMatcher, + real_http: Any, + case_sensitive: Any + ) -> None: ... + def __call__(self, request: Request) -> Optional[Response]: ... + +class Adapter(BaseAdapter, _RequestHistoryTracker): + def __init__(self, case_sensitive: bool = ...) -> None: ... + def register_uri( + self, + method: Union[str, AnyMatcher], + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + **kwargs: Any + ) -> _Matcher: ... + def add_matcher(self, matcher: Matcher) -> None: ... + def reset(self) -> None: ... diff --git a/contrib/python/requests-mock/py3/requests_mock/contrib/_pytest_plugin.pyi b/contrib/python/requests-mock/py3/requests_mock/contrib/_pytest_plugin.pyi new file mode 100644 index 0000000000..3ffb573881 --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/contrib/_pytest_plugin.pyi @@ -0,0 +1,6 @@ + +from typing import Literal, Optional, Union + + +_case_type = Optional[str] +_case_default = Union[Literal['false'], Literal[False]] diff --git a/contrib/python/requests-mock/py3/requests_mock/exceptions.pyi b/contrib/python/requests-mock/py3/requests_mock/exceptions.pyi new file mode 100644 index 0000000000..eb35447228 --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/exceptions.pyi @@ -0,0 +1,13 @@ +# Stubs for requests_mock.exceptions + +from typing import Any + +from requests import Request + +class MockException(Exception): ... + +class NoMockAddress(MockException): + request: Any = ... + def __init__(self, request: Request) -> None: ... + +class InvalidRequest(MockException): ... diff --git a/contrib/python/requests-mock/py3/requests_mock/mocker.pyi b/contrib/python/requests-mock/py3/requests_mock/mocker.pyi new file mode 100644 index 0000000000..891e7d6c9a --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/mocker.pyi @@ -0,0 +1,263 @@ +# Stubs for requests_mock.mocker + +from json import JSONEncoder +from http.cookiejar import CookieJar +from io import IOBase +from typing import Any, Callable, Dict, List, Optional, Pattern, Type, TypeVar, Union + +from requests import Response, Session +from urllib3.response import HTTPResponse + +from requests_mock.adapter import AnyMatcher, _Matcher, Callback, AdditionalMatcher +from requests_mock.request import Request + +DELETE: str +GET: str +HEAD: str +OPTIONS: str +PATCH: str +POST: str +PUT: str + +class MockerCore: + case_sensitive: bool = ... + def __init__(self, **kwargs: Any) -> None: ... + def start(self) -> None: ... + def stop(self) -> None: ... + def add_matcher(self, matcher: Callable[[Request], Optional[Response]]) -> None: ... + @property + def request_history(self) -> List[Request]: ... + @property + def last_request(self) -> Optional[Request]: ... + @property + def called(self) -> bool: ... + @property + def called_once(self) -> bool: ... + @property + def call_count(self) -> int: ... + def reset(self) -> None: ... + def reset_mock(self) -> None: ... + + def register_uri( + self, + method: Union[str, AnyMatcher], + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def request( + self, + method: Union[str, AnyMatcher], + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def get( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def head( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def options( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def post( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def put( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def patch( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + + def delete( + self, + url: Union[str, Pattern[str], AnyMatcher], + response_list: Optional[List[Dict[str, Any]]] = ..., + *, + request_headers: Dict[str, str] = ..., + complete_qs: bool = ..., + status_code: int = ..., + reason: str = ..., + headers: Dict[str, str] = ..., + cookies: Union[CookieJar, Dict[str, str]] = ..., + json: Union[Any, Callback[Any]] = ..., + text: Union[str, Callback[str]] = ..., + content: Union[bytes, Callback[bytes]] = ..., + body: Union[IOBase, Callback[IOBase]] = ..., + raw: HTTPResponse = ..., + exc: Union[Exception, Type[Exception]] = ..., + additional_matcher: AdditionalMatcher = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + **kwargs: Any, + ) -> _Matcher: ... + +_T = TypeVar('_T') + +class Mocker(MockerCore): + TEST_PREFIX: str = ... + real_http: bool = ... + + def __init__( + self, + kw: str = ..., + case_sensitive: bool = ..., + adapter: Any = ..., + session: Optional[Session] = ..., + real_http: bool = ..., + json_encoder: Optional[Type[JSONEncoder]] = ..., + ) -> None: ... + def __enter__(self) -> Any: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... + def __call__(self, obj: Any) -> Any: ... + def copy(self) -> Mocker: ... + def decorate_callable(self, func: Callable[..., _T]) -> Callable[..., _T]: ... + def decorate_class(self, klass: Type[_T]) -> Type[_T]: ... + +mock = Mocker diff --git a/contrib/python/requests-mock/py3/requests_mock/request.pyi b/contrib/python/requests-mock/py3/requests_mock/request.pyi new file mode 100644 index 0000000000..5e2fb30d20 --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/request.pyi @@ -0,0 +1,41 @@ +# Stubs for requests_mock.request + +from typing import Any, Dict, List + +class _RequestObjectProxy: + def __init__(self, request: Any, **kwargs: Any) -> None: ... + def __getattr__(self, name: str) -> Any: ... + @property + def scheme(self) -> str: ... + @property + def netloc(self) -> str: ... + @property + def hostname(self) -> str: ... + @property + def port(self) -> int: ... + @property + def path(self) -> str: ... + @property + def query(self) -> str: ... + @property + def qs(self) -> Dict[str, List[str]]: ... + @property + def timeout(self) -> int: ... + @property + def allow_redirects(self) -> bool: ... + @property + def verify(self) -> Any: ... + @property + def stream(self) -> Any: ... + @property + def cert(self) -> Any: ... + @property + def proxies(self) -> Any: ... + @property + def text(self) -> str: ... + def json(self, **kwargs: Any) -> Any: ... + @property + def matcher(self) -> Any: ... + + +Request = _RequestObjectProxy diff --git a/contrib/python/requests-mock/py3/requests_mock/response.pyi b/contrib/python/requests-mock/py3/requests_mock/response.pyi new file mode 100644 index 0000000000..e7c8977883 --- /dev/null +++ b/contrib/python/requests-mock/py3/requests_mock/response.pyi @@ -0,0 +1,38 @@ +# Stubs for requests_mock.response + +from typing import Any, Dict + +import six + +from requests import Request, Response +from requests.cookies import RequestsCookieJar + +class CookieJar(RequestsCookieJar): + def set(self, name: Any, value: Any, **kwargs: Any) -> Any: ... + +class _FakeConnection: + def send(self, request: Any, **kwargs: Any) -> None: ... + def close(self) -> None: ... + +class _IOReader(six.BytesIO): + def read(self, *args: Any, **kwargs: Any) -> Any: ... + +def create_response(request: Any, **kwargs: Any) -> Response: ... + +class _Context: + headers: Dict[str,str] = ... + status_code: int = ... + reason: str = ... + cookies: Any = ... + + def __init__(self, + headers: Dict[str, str], + status_code: int, + reason: str, + cookies: Any) -> None: ... + +class _MatcherResponse: + def __init__(self, **kwargs: Any) -> None: ... + def get_response(self, request: Request) -> Response: ... + +Context = _Context |