client.pyi 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from typing import BinaryIO, Optional, Sequence, Type, TypeVar
  2. from twisted.internet.defer import Deferred
  3. from twisted.internet.interfaces import IConsumer, IProtocol
  4. from twisted.internet.task import Cooperator
  5. from twisted.python.failure import Failure
  6. from twisted.web.http_headers import Headers
  7. from twisted.web.iweb import (
  8. IAgent,
  9. IAgentEndpointFactory,
  10. IBodyProducer,
  11. IPolicyForHTTPS,
  12. IResponse,
  13. )
  14. from zope.interface import implementer
  15. _C = TypeVar("_C")
  16. class ResponseFailed(Exception):
  17. def __init__(
  18. self, reasons: Sequence[Failure], response: Optional[Response] = ...
  19. ): ...
  20. class HTTPConnectionPool:
  21. persistent: bool
  22. maxPersistentPerHost: int
  23. cachedConnectionTimeout: float
  24. retryAutomatically: bool
  25. def __init__(self, reactor: object, persistent: bool = ...): ...
  26. @implementer(IAgent)
  27. class Agent:
  28. # Here and in `usingEndpointFactory`, reactor should be a "provider of
  29. # L{IReactorTCP}, L{IReactorTime} and either
  30. # L{IReactorPluggableNameResolver} or L{IReactorPluggableResolver}."
  31. # I don't know how to encode that in the type system; see also
  32. # https://github.com/Shoobx/mypy-zope/issues/58
  33. def __init__(
  34. self,
  35. reactor: object,
  36. contextFactory: IPolicyForHTTPS = ...,
  37. connectTimeout: Optional[float] = ...,
  38. bindAddress: Optional[bytes] = ...,
  39. pool: Optional[HTTPConnectionPool] = ...,
  40. ): ...
  41. def request(
  42. self,
  43. method: bytes,
  44. uri: bytes,
  45. headers: Optional[Headers] = ...,
  46. bodyProducer: Optional[IBodyProducer] = ...,
  47. ) -> Deferred[IResponse]: ...
  48. @classmethod
  49. def usingEndpointFactory(
  50. cls: Type[_C],
  51. reactor: object,
  52. endpointFactory: IAgentEndpointFactory,
  53. pool: Optional[HTTPConnectionPool] = ...,
  54. ) -> _C: ...
  55. @implementer(IBodyProducer)
  56. class FileBodyProducer:
  57. def __init__(
  58. self,
  59. inputFile: BinaryIO,
  60. cooperator: Cooperator = ...,
  61. readSize: int = ...,
  62. ): ...
  63. # Length is either `int` or the opaque object UNKNOWN_LENGTH.
  64. length: int | object
  65. def startProducing(self, consumer: IConsumer) -> Deferred[None]: ...
  66. def stopProducing(self) -> None: ...
  67. def pauseProducing(self) -> None: ...
  68. def resumeProducing(self) -> None: ...
  69. def readBody(response: IResponse) -> Deferred[bytes]: ...
  70. # Type ignore: I don't want to respecify the methods on the interface that we
  71. # don't use.
  72. @implementer(IResponse) # type: ignore[misc]
  73. class Response:
  74. code: int
  75. headers: Headers
  76. # Length is either `int` or the opaque object UNKNOWN_LENGTH.
  77. length: int | object
  78. def deliverBody(self, protocol: IProtocol) -> None: ...
  79. class ResponseDone: ...
  80. class URI:
  81. scheme: bytes
  82. netloc: bytes
  83. host: bytes
  84. port: int
  85. path: bytes
  86. params: bytes
  87. query: bytes
  88. fragment: bytes
  89. def __init__(
  90. self,
  91. scheme: bytes,
  92. netloc: bytes,
  93. host: bytes,
  94. port: int,
  95. path: bytes,
  96. params: bytes,
  97. query: bytes,
  98. fragment: bytes,
  99. ): ...
  100. @classmethod
  101. def fromBytes(
  102. cls: Type[_C], uri: bytes, defaultPort: Optional[int] = ...
  103. ) -> _C: ...
  104. @implementer(IAgent)
  105. class RedirectAgent:
  106. def __init__(self, agent: Agent, redirectLimit: int = ...): ...
  107. def request(
  108. self,
  109. method: bytes,
  110. uri: bytes,
  111. headers: Optional[Headers] = ...,
  112. bodyProducer: Optional[IBodyProducer] = ...,
  113. ) -> Deferred[IResponse]: ...