txredisapi.pyi 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright 2020 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Contains *incomplete* type hints for txredisapi.
  15. """
  16. from typing import Any, List, Optional, Type, Union
  17. from twisted.internet import protocol
  18. from twisted.internet.defer import Deferred
  19. from twisted.internet.interfaces import IAddress
  20. from twisted.python.failure import Failure
  21. class RedisProtocol(protocol.Protocol):
  22. def publish(self, channel: str, message: bytes) -> "Deferred[None]": ...
  23. def ping(self) -> "Deferred[None]": ...
  24. def set(
  25. self,
  26. key: str,
  27. value: Any,
  28. expire: Optional[int] = None,
  29. pexpire: Optional[int] = None,
  30. only_if_not_exists: bool = False,
  31. only_if_exists: bool = False,
  32. ) -> "Deferred[None]": ...
  33. def get(self, key: str) -> "Deferred[Any]": ...
  34. class SubscriberProtocol(RedisProtocol):
  35. def __init__(self, *args: object, **kwargs: object): ...
  36. password: Optional[str]
  37. def subscribe(self, channels: Union[str, List[str]]) -> "Deferred[None]": ...
  38. def connectionMade(self) -> None: ...
  39. # type-ignore: twisted.internet.protocol.Protocol provides a default argument for
  40. # `reason`. txredisapi's LineReceiver Protocol doesn't. But that's fine: it's what's
  41. # actually specified in twisted.internet.interfaces.IProtocol.
  42. def connectionLost(self, reason: Failure) -> None: ... # type: ignore[override]
  43. def lazyConnection(
  44. host: str = ...,
  45. port: int = ...,
  46. dbid: Optional[int] = ...,
  47. reconnect: bool = ...,
  48. charset: str = ...,
  49. password: Optional[str] = ...,
  50. connectTimeout: Optional[int] = ...,
  51. replyTimeout: Optional[int] = ...,
  52. convertNumbers: bool = ...,
  53. ) -> RedisProtocol: ...
  54. # ConnectionHandler doesn't actually inherit from RedisProtocol, but it proxies
  55. # most methods to it via ConnectionHandler.__getattr__.
  56. class ConnectionHandler(RedisProtocol):
  57. def disconnect(self) -> "Deferred[None]": ...
  58. class RedisFactory(protocol.ReconnectingClientFactory):
  59. continueTrying: bool
  60. handler: ConnectionHandler
  61. pool: List[RedisProtocol]
  62. replyTimeout: Optional[int]
  63. def __init__(
  64. self,
  65. uuid: str,
  66. dbid: Optional[int],
  67. poolsize: int,
  68. isLazy: bool = False,
  69. handler: Type = ConnectionHandler,
  70. charset: str = "utf-8",
  71. password: Optional[str] = None,
  72. replyTimeout: Optional[int] = None,
  73. convertNumbers: Optional[int] = True,
  74. ): ...
  75. def buildProtocol(self, addr: IAddress) -> RedisProtocol: ...
  76. class SubscriberFactory(RedisFactory):
  77. def __init__(self) -> None: ...