_future.pyi 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. """type annotations for async sockets"""
  2. from __future__ import annotations
  3. from asyncio import Future
  4. from pickle import DEFAULT_PROTOCOL
  5. from typing import Any, Awaitable, Literal, Sequence, TypeVar, overload
  6. import zmq as _zmq
  7. class _AsyncPoller(_zmq.Poller):
  8. _socket_class: type[_AsyncSocket]
  9. def poll(self, timeout=-1) -> Awaitable[list[tuple[Any, int]]]: ... # type: ignore
  10. T = TypeVar("T", bound="_AsyncSocket")
  11. class _AsyncSocket(_zmq.Socket[Future]):
  12. @classmethod
  13. def from_socket(cls: type[T], socket: _zmq.Socket, io_loop: Any = None) -> T: ...
  14. def send( # type: ignore
  15. self,
  16. data: Any,
  17. flags: int = 0,
  18. copy: bool = True,
  19. track: bool = False,
  20. routing_id: int | None = None,
  21. group: str | None = None,
  22. ) -> Awaitable[_zmq.MessageTracker | None]: ...
  23. @overload # type: ignore
  24. def recv(self, flags: int = 0, *, track: bool = False) -> Awaitable[bytes]: ...
  25. @overload
  26. def recv(
  27. self, flags: int = 0, *, copy: Literal[True], track: bool = False
  28. ) -> Awaitable[bytes]: ...
  29. @overload
  30. def recv(
  31. self, flags: int = 0, *, copy: Literal[False], track: bool = False
  32. ) -> Awaitable[_zmq.Frame]: ...
  33. @overload
  34. def recv(
  35. self, flags: int = 0, copy: bool = True, track: bool = False
  36. ) -> Awaitable[bytes | _zmq.Frame]: ...
  37. def recv_into( # type: ignore
  38. self, buffer: Any, /, *, nbytes: int = 0, flags: int = 0
  39. ) -> Awaitable[int]: ...
  40. def send_multipart( # type: ignore
  41. self,
  42. msg_parts: Sequence,
  43. flags: int = 0,
  44. copy: bool = True,
  45. track: bool = False,
  46. routing_id: int | None = None,
  47. group: str | None = None,
  48. ) -> Awaitable[_zmq.MessageTracker | None]: ...
  49. @overload # type: ignore
  50. def recv_multipart(
  51. self, flags: int = 0, *, track: bool = False
  52. ) -> Awaitable[list[bytes]]: ...
  53. @overload
  54. def recv_multipart(
  55. self, flags: int = 0, *, copy: Literal[True], track: bool = False
  56. ) -> Awaitable[list[bytes]]: ...
  57. @overload
  58. def recv_multipart(
  59. self, flags: int = 0, *, copy: Literal[False], track: bool = False
  60. ) -> Awaitable[list[_zmq.Frame]]: ...
  61. @overload
  62. def recv_multipart(
  63. self, flags: int = 0, copy: bool = True, track: bool = False
  64. ) -> Awaitable[list[bytes] | list[_zmq.Frame]]: ...
  65. # serialization wrappers
  66. def send_string( # type: ignore
  67. self,
  68. u: str,
  69. flags: int = 0,
  70. copy: bool = True,
  71. *,
  72. encoding: str = 'utf-8',
  73. **kwargs,
  74. ) -> Awaitable[_zmq.Frame | None]: ...
  75. def recv_string( # type: ignore
  76. self, flags: int = 0, encoding: str = 'utf-8'
  77. ) -> Awaitable[str]: ...
  78. def send_pyobj( # type: ignore
  79. self, obj: Any, flags: int = 0, protocol: int = DEFAULT_PROTOCOL, **kwargs
  80. ) -> Awaitable[_zmq.Frame | None]: ...
  81. def recv_pyobj(self, flags: int = 0) -> Awaitable[Any]: ... # type: ignore
  82. def send_json( # type: ignore
  83. self, obj: Any, flags: int = 0, **kwargs
  84. ) -> Awaitable[_zmq.Frame | None]: ...
  85. def recv_json(self, flags: int = 0, **kwargs) -> Awaitable[Any]: ... # type: ignore
  86. def poll(self, timeout=-1) -> Awaitable[list[tuple[Any, int]]]: ... # type: ignore