adapter.pyi 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Stubs for requests_mock.adapter
  2. from http.cookiejar import CookieJar
  3. from io import IOBase
  4. from typing import Any, Callable, Dict, List, NewType, Optional, Pattern, Type, TypeVar, Union
  5. from requests import Response
  6. from requests.adapters import BaseAdapter
  7. from urllib3.response import HTTPResponse
  8. from requests_mock.request import Request
  9. from requests_mock.response import Context
  10. AnyMatcher = NewType("AnyMatcher", object)
  11. ANY: AnyMatcher = ...
  12. T = TypeVar('T')
  13. Callback = Callable[[Request, Context], T]
  14. Matcher = Callable[[Request], Optional[Response]]
  15. AdditionalMatcher = Callable[[Request], bool]
  16. class _RequestHistoryTracker:
  17. request_history: List[Request] = ...
  18. def __init__(self) -> None: ...
  19. @property
  20. def last_request(self) -> Optional[Request]: ...
  21. @property
  22. def called(self) -> bool: ...
  23. @property
  24. def called_once(self) -> bool: ...
  25. @property
  26. def call_count(self) -> int: ...
  27. class _RunRealHTTP(Exception): ...
  28. class _Matcher(_RequestHistoryTracker):
  29. def __init__(
  30. self,
  31. method: Any,
  32. url: Any,
  33. responses: Any,
  34. complete_qs: Any,
  35. request_headers: Any,
  36. additional_matcher: AdditionalMatcher,
  37. real_http: Any,
  38. case_sensitive: Any
  39. ) -> None: ...
  40. def __call__(self, request: Request) -> Optional[Response]: ...
  41. class Adapter(BaseAdapter, _RequestHistoryTracker):
  42. def __init__(self, case_sensitive: bool = ...) -> None: ...
  43. def register_uri(
  44. self,
  45. method: Union[str, AnyMatcher],
  46. url: Union[str, Pattern[str], AnyMatcher],
  47. response_list: Optional[List[Dict[str, Any]]] = ...,
  48. *,
  49. request_headers: Dict[str, str] = ...,
  50. complete_qs: bool = ...,
  51. status_code: int = ...,
  52. reason: str = ...,
  53. headers: Dict[str, str] = ...,
  54. cookies: Union[CookieJar, Dict[str, str]] = ...,
  55. json: Union[Any, Callback[Any]] = ...,
  56. text: Union[str, Callback[str]] = ...,
  57. content: Union[bytes, Callback[bytes]] = ...,
  58. body: Union[IOBase, Callback[IOBase]] = ...,
  59. raw: HTTPResponse = ...,
  60. exc: Union[Exception, Type[Exception]] = ...,
  61. additional_matcher: AdditionalMatcher = ...,
  62. **kwargs: Any
  63. ) -> _Matcher: ...
  64. def add_matcher(self, matcher: Matcher) -> None: ...
  65. def reset(self) -> None: ...