PyPlumIO 0.5.52__py3-none-any.whl → 0.5.53__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyplumio/_version.py +2 -2
- pyplumio/connection.py +1 -1
- pyplumio/data_types.py +7 -0
- pyplumio/filters.py +7 -0
- pyplumio/frames/__init__.py +13 -0
- pyplumio/parameters/__init__.py +5 -1
- pyplumio/stream.py +39 -45
- pyplumio/utils.py +26 -2
- {pyplumio-0.5.52.dist-info → pyplumio-0.5.53.dist-info}/METADATA +4 -4
- {pyplumio-0.5.52.dist-info → pyplumio-0.5.53.dist-info}/RECORD +13 -14
- pyplumio/helpers/timeout.py +0 -32
- {pyplumio-0.5.52.dist-info → pyplumio-0.5.53.dist-info}/WHEEL +0 -0
- {pyplumio-0.5.52.dist-info → pyplumio-0.5.53.dist-info}/licenses/LICENSE +0 -0
- {pyplumio-0.5.52.dist-info → pyplumio-0.5.53.dist-info}/top_level.txt +0 -0
pyplumio/_version.py
CHANGED
pyplumio/connection.py
CHANGED
@@ -11,8 +11,8 @@ from serial import EIGHTBITS, PARITY_NONE, STOPBITS_ONE
|
|
11
11
|
|
12
12
|
from pyplumio.exceptions import ConnectionFailedError
|
13
13
|
from pyplumio.helpers.task_manager import TaskManager
|
14
|
-
from pyplumio.helpers.timeout import timeout
|
15
14
|
from pyplumio.protocol import AsyncProtocol, Protocol
|
15
|
+
from pyplumio.utils import timeout
|
16
16
|
|
17
17
|
_LOGGER = logging.getLogger(__name__)
|
18
18
|
|
pyplumio/data_types.py
CHANGED
@@ -33,6 +33,13 @@ class DataType(ABC, Generic[T]):
|
|
33
33
|
|
34
34
|
return f"{self.__class__.__name__}()"
|
35
35
|
|
36
|
+
def __hash__(self) -> int:
|
37
|
+
"""Return a hash of the data type based on its value."""
|
38
|
+
if hasattr(self, "_value"):
|
39
|
+
return hash(self._value)
|
40
|
+
|
41
|
+
return hash(type(self))
|
42
|
+
|
36
43
|
def __eq__(self, other: object) -> bool:
|
37
44
|
"""Compare if this data type is equal to other."""
|
38
45
|
if (
|
pyplumio/filters.py
CHANGED
@@ -56,6 +56,9 @@ class SupportsComparison(Protocol):
|
|
56
56
|
|
57
57
|
__slots__ = ()
|
58
58
|
|
59
|
+
def __hash__(self) -> int:
|
60
|
+
"""Return a hash of the value."""
|
61
|
+
|
59
62
|
def __eq__(self: SupportsComparison, other: SupportsComparison) -> bool:
|
60
63
|
"""Compare a value."""
|
61
64
|
|
@@ -130,6 +133,10 @@ class Filter(ABC):
|
|
130
133
|
self._callback = callback
|
131
134
|
self._value = UNDEFINED
|
132
135
|
|
136
|
+
def __hash__(self) -> int:
|
137
|
+
"""Return a hash of the filter based on its callback."""
|
138
|
+
return hash(self._callback)
|
139
|
+
|
133
140
|
def __eq__(self, other: Any) -> bool:
|
134
141
|
"""Compare callbacks."""
|
135
142
|
if isinstance(other, Filter):
|
pyplumio/frames/__init__.py
CHANGED
@@ -114,6 +114,19 @@ class Frame(ABC):
|
|
114
114
|
self._data = data if not kwargs else ensure_dict(data, kwargs)
|
115
115
|
self._message = message
|
116
116
|
|
117
|
+
def __hash__(self) -> int:
|
118
|
+
"""Return a hash of the frame based on its values."""
|
119
|
+
return hash(
|
120
|
+
(
|
121
|
+
self.recipient,
|
122
|
+
self.sender,
|
123
|
+
self.econet_type,
|
124
|
+
self.econet_version,
|
125
|
+
self._message,
|
126
|
+
frozenset(self._data.items()) if self._data else None,
|
127
|
+
)
|
128
|
+
)
|
129
|
+
|
117
130
|
def __eq__(self, other: object) -> bool:
|
118
131
|
"""Compare if this frame is equal to other."""
|
119
132
|
if isinstance(other, Frame):
|
pyplumio/parameters/__init__.py
CHANGED
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
5
5
|
from abc import ABC, abstractmethod
|
6
6
|
import asyncio
|
7
7
|
from contextlib import suppress
|
8
|
-
from dataclasses import dataclass
|
8
|
+
from dataclasses import asdict, dataclass
|
9
9
|
import logging
|
10
10
|
from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, get_args
|
11
11
|
|
@@ -115,6 +115,10 @@ class Parameter(ABC):
|
|
115
115
|
f"index={self._index})"
|
116
116
|
)
|
117
117
|
|
118
|
+
def __hash__(self) -> int:
|
119
|
+
"""Return a hash of the parameter based on its values."""
|
120
|
+
return hash(frozenset(asdict(self.values).items()))
|
121
|
+
|
118
122
|
def _call_relational_method(self, method_to_call: str, other: Any) -> Any:
|
119
123
|
"""Call a specified relational method."""
|
120
124
|
if isinstance(other, Parameter):
|
pyplumio/stream.py
CHANGED
@@ -20,7 +20,7 @@ from pyplumio.frames import (
|
|
20
20
|
bcc,
|
21
21
|
struct_header,
|
22
22
|
)
|
23
|
-
from pyplumio.
|
23
|
+
from pyplumio.utils import timeout
|
24
24
|
|
25
25
|
READER_TIMEOUT: Final = 10
|
26
26
|
WRITER_TIMEOUT: Final = 10
|
@@ -67,7 +67,7 @@ class FrameWriter:
|
|
67
67
|
await self._writer.wait_closed()
|
68
68
|
|
69
69
|
|
70
|
-
class
|
70
|
+
class BufferedReader:
|
71
71
|
"""Represents a buffered reader for reading frames."""
|
72
72
|
|
73
73
|
__slots__ = ("_buffer", "_reader")
|
@@ -89,7 +89,7 @@ class BufferManager:
|
|
89
89
|
try:
|
90
90
|
data = await self._reader.readexactly(bytes_to_read)
|
91
91
|
self._buffer.extend(data)
|
92
|
-
self.trim_to(
|
92
|
+
self.trim_to(DEFAULT_BUFFER_SIZE)
|
93
93
|
except IncompleteReadError as e:
|
94
94
|
raise ReadError(
|
95
95
|
f"Incomplete read. Tried to read {bytes_to_read} additional bytes "
|
@@ -104,22 +104,36 @@ class BufferManager:
|
|
104
104
|
f"Serial connection broken while trying to ensure {size} bytes: {e}"
|
105
105
|
) from e
|
106
106
|
|
107
|
+
async def peek(self, size: int) -> bytes:
|
108
|
+
"""Read the specified number of bytes without consuming them."""
|
109
|
+
await self.ensure_buffer(size)
|
110
|
+
return memoryview(self._buffer)[:size].tobytes()
|
111
|
+
|
107
112
|
async def consume(self, size: int) -> None:
|
108
113
|
"""Consume the specified number of bytes from the buffer."""
|
109
114
|
await self.ensure_buffer(size)
|
110
115
|
self._buffer = self._buffer[size:]
|
111
116
|
|
112
|
-
async def
|
113
|
-
"""Read the specified number of bytes
|
114
|
-
await self.ensure_buffer(size)
|
115
|
-
return self._buffer[:size]
|
116
|
-
|
117
|
-
async def read(self, size: int) -> bytearray:
|
118
|
-
"""Read the bytes from buffer or stream and consume them."""
|
117
|
+
async def read_into_buffer(self, size: int) -> None:
|
118
|
+
"""Read the specified number of bytes from the stream."""
|
119
119
|
try:
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
chunk = await self._reader.read(size)
|
121
|
+
except asyncio.CancelledError:
|
122
|
+
_LOGGER.debug("Read operation cancelled while filling internal buffer.")
|
123
|
+
raise
|
124
|
+
except Exception as e:
|
125
|
+
raise OSError(
|
126
|
+
f"Serial connection broken while filling internal buffer: {e}"
|
127
|
+
) from e
|
128
|
+
|
129
|
+
if not chunk:
|
130
|
+
_LOGGER.debug("Stream ended while filling internal buffer.")
|
131
|
+
raise OSError(
|
132
|
+
"Serial connection broken: stream ended while filling internal buffer"
|
133
|
+
)
|
134
|
+
|
135
|
+
self._buffer.extend(chunk)
|
136
|
+
self.trim_to(DEFAULT_BUFFER_SIZE)
|
123
137
|
|
124
138
|
def seek_to(self, delimiter: SupportsIndex) -> bool:
|
125
139
|
"""Trim the buffer to the first occurrence of the delimiter.
|
@@ -137,27 +151,6 @@ class BufferManager:
|
|
137
151
|
if len(self._buffer) > size:
|
138
152
|
self._buffer = self._buffer[-size:]
|
139
153
|
|
140
|
-
async def fill(self) -> None:
|
141
|
-
"""Fill the buffer with data from the stream."""
|
142
|
-
try:
|
143
|
-
chunk = await self._reader.read(MAX_FRAME_LENGTH)
|
144
|
-
except asyncio.CancelledError:
|
145
|
-
_LOGGER.debug("Read operation cancelled while filling read buffer.")
|
146
|
-
raise
|
147
|
-
except Exception as e:
|
148
|
-
raise OSError(
|
149
|
-
f"Serial connection broken while filling read buffer: {e}"
|
150
|
-
) from e
|
151
|
-
|
152
|
-
if not chunk:
|
153
|
-
_LOGGER.debug("Stream ended while filling read buffer.")
|
154
|
-
raise OSError(
|
155
|
-
"Serial connection broken: stream ended while filling read buffer"
|
156
|
-
)
|
157
|
-
|
158
|
-
self._buffer.extend(chunk)
|
159
|
-
self.trim_to(DEFAULT_BUFFER_SIZE)
|
160
|
-
|
161
154
|
@property
|
162
155
|
def buffer(self) -> bytearray:
|
163
156
|
"""Return the internal buffer."""
|
@@ -177,22 +170,23 @@ class Header(NamedTuple):
|
|
177
170
|
class FrameReader:
|
178
171
|
"""Represents a frame reader."""
|
179
172
|
|
180
|
-
__slots__ = ("
|
173
|
+
__slots__ = ("_reader",)
|
181
174
|
|
182
|
-
|
175
|
+
_reader: BufferedReader
|
183
176
|
|
184
177
|
def __init__(self, reader: StreamReader) -> None:
|
185
178
|
"""Initialize a new frame reader."""
|
186
|
-
self.
|
179
|
+
self._reader = BufferedReader(reader)
|
187
180
|
|
188
181
|
async def _read_header(self) -> Header:
|
189
182
|
"""Locate and read a frame header."""
|
190
183
|
while True:
|
191
|
-
if self.
|
192
|
-
header_bytes = await self.
|
193
|
-
|
184
|
+
if self._reader.seek_to(FRAME_START):
|
185
|
+
header_bytes = await self._reader.peek(HEADER_SIZE)
|
186
|
+
header_fields = struct_header.unpack_from(header_bytes)
|
187
|
+
return Header(*header_fields[DELIMITER_SIZE:])
|
194
188
|
|
195
|
-
await self.
|
189
|
+
await self._reader.read_into_buffer(MAX_FRAME_LENGTH)
|
196
190
|
|
197
191
|
@timeout(READER_TIMEOUT)
|
198
192
|
async def read(self) -> Frame | None:
|
@@ -201,22 +195,22 @@ class FrameReader:
|
|
201
195
|
frame_length, recipient, sender, econet_type, econet_version = header
|
202
196
|
|
203
197
|
if frame_length > MAX_FRAME_LENGTH or frame_length < MIN_FRAME_LENGTH:
|
204
|
-
await self.
|
198
|
+
await self._reader.consume(HEADER_SIZE)
|
205
199
|
raise ReadError(
|
206
200
|
f"Unexpected frame length ({frame_length}), expected between "
|
207
201
|
f"{MIN_FRAME_LENGTH} and {MAX_FRAME_LENGTH}"
|
208
202
|
)
|
209
203
|
|
210
|
-
frame_bytes = await self.
|
204
|
+
frame_bytes = await self._reader.peek(frame_length)
|
211
205
|
checksum = bcc(frame_bytes[:BCC_INDEX])
|
212
206
|
if checksum != frame_bytes[BCC_INDEX]:
|
213
|
-
await self.
|
207
|
+
await self._reader.consume(HEADER_SIZE)
|
214
208
|
raise ChecksumError(
|
215
209
|
f"Incorrect frame checksum: calculated {checksum}, "
|
216
210
|
f"expected {frame_bytes[BCC_INDEX]}. Frame data: {frame_bytes.hex()}"
|
217
211
|
)
|
218
212
|
|
219
|
-
await self.
|
213
|
+
await self._reader.consume(frame_length)
|
220
214
|
if recipient not in (DeviceType.ECONET, DeviceType.ALL):
|
221
215
|
_LOGGER.debug(
|
222
216
|
"Skipping frame intended for different recipient (%s)", recipient
|
pyplumio/utils.py
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
-
|
5
|
+
import asyncio
|
6
|
+
from collections.abc import Awaitable, Callable, Mapping
|
7
|
+
from functools import wraps
|
6
8
|
from typing import TypeVar
|
7
9
|
|
10
|
+
from typing_extensions import ParamSpec
|
11
|
+
|
8
12
|
KT = TypeVar("KT") # Key type.
|
9
13
|
VT = TypeVar("VT") # Value type.
|
10
14
|
|
@@ -40,4 +44,24 @@ def is_divisible(a: float, b: float, precision: int = 6) -> bool:
|
|
40
44
|
return a_scaled % b_scaled == 0
|
41
45
|
|
42
46
|
|
43
|
-
|
47
|
+
T = TypeVar("T")
|
48
|
+
P = ParamSpec("P")
|
49
|
+
|
50
|
+
|
51
|
+
def timeout(
|
52
|
+
seconds: float,
|
53
|
+
) -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]:
|
54
|
+
"""Decorate a timeout for the awaitable."""
|
55
|
+
|
56
|
+
def decorator(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
|
57
|
+
@wraps(func)
|
58
|
+
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
59
|
+
return await asyncio.wait_for(func(*args, **kwargs), timeout=seconds)
|
60
|
+
|
61
|
+
setattr(wrapper, "_has_timeout_seconds", seconds)
|
62
|
+
return wrapper
|
63
|
+
|
64
|
+
return decorator
|
65
|
+
|
66
|
+
|
67
|
+
__all__ = ["ensure_dict", "is_divisible", "to_camelcase", "timeout"]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: PyPlumIO
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.53
|
4
4
|
Summary: PyPlumIO is a native ecoNET library for Plum ecoMAX controllers.
|
5
5
|
Author-email: Denis Paavilainen <denpa@denpa.pro>
|
6
6
|
License: MIT License
|
@@ -25,7 +25,7 @@ Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
26
26
|
Requires-Dist: dataslots==1.2.0
|
27
27
|
Requires-Dist: pyserial-asyncio==0.6
|
28
|
-
Requires-Dist: typing-extensions
|
28
|
+
Requires-Dist: typing-extensions<5.0,>=4.14.0
|
29
29
|
Provides-Extra: test
|
30
30
|
Requires-Dist: codespell==2.4.1; extra == "test"
|
31
31
|
Requires-Dist: coverage==7.9.1; extra == "test"
|
@@ -35,8 +35,8 @@ Requires-Dist: numpy<3.0.0,>=2.0.0; extra == "test"
|
|
35
35
|
Requires-Dist: pyserial-asyncio-fast==0.16; extra == "test"
|
36
36
|
Requires-Dist: pytest==8.4.1; extra == "test"
|
37
37
|
Requires-Dist: pytest-asyncio==1.0.0; extra == "test"
|
38
|
-
Requires-Dist: ruff==0.
|
39
|
-
Requires-Dist: tox==4.
|
38
|
+
Requires-Dist: ruff==0.12.1; extra == "test"
|
39
|
+
Requires-Dist: tox==4.27.0; extra == "test"
|
40
40
|
Requires-Dist: types-pyserial==3.5.0.20250326; extra == "test"
|
41
41
|
Provides-Extra: docs
|
42
42
|
Requires-Dist: sphinx==8.1.3; extra == "docs"
|
@@ -1,21 +1,21 @@
|
|
1
1
|
pyplumio/__init__.py,sha256=3H5SO4WFw5mBTFeEyD4w0H8-MsNo93NyOH3RyMN7IS0,3337
|
2
2
|
pyplumio/__main__.py,sha256=3IwHHSq-iay5FaeMc95klobe-xv82yydSKcBE7BFZ6M,500
|
3
|
-
pyplumio/_version.py,sha256=
|
4
|
-
pyplumio/connection.py,sha256=
|
3
|
+
pyplumio/_version.py,sha256=XU3GvfwHGD0uhY3L2CgqZXptcJXNuiDPHBlo4yPL1hY,513
|
4
|
+
pyplumio/connection.py,sha256=u-iOzEUqoEEL4YLpLtzBWi5Qy8_RABgKD8DyXf-er-4,5892
|
5
5
|
pyplumio/const.py,sha256=eoq-WNJ8TO3YlP7dC7KkVQRKGjt9FbRZ6M__s29vb1U,5659
|
6
|
-
pyplumio/data_types.py,sha256=
|
6
|
+
pyplumio/data_types.py,sha256=BTDxwErRo_odvFT5DNfIniNh8ZfyjRKEDaJmoEJqdEg,9426
|
7
7
|
pyplumio/exceptions.py,sha256=_B_0EgxDxd2XyYv3WpZM733q0cML5m6J-f55QOvYRpI,996
|
8
|
-
pyplumio/filters.py,sha256=
|
8
|
+
pyplumio/filters.py,sha256=gW3XadVYIMunpHmVQRLc_dAqTldKZl8yvGjTTIWNKXc,15607
|
9
9
|
pyplumio/protocol.py,sha256=DWM-yJnm2EQPLvGzXNlkQ0IpKQn44e-WkNB_DqZAag8,8313
|
10
10
|
pyplumio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
pyplumio/stream.py,sha256=
|
12
|
-
pyplumio/utils.py,sha256=
|
11
|
+
pyplumio/stream.py,sha256=zFMKZ_GxsSGcaBTJigVM1CK3uGjlEJXgcvKqus8MDzk,7740
|
12
|
+
pyplumio/utils.py,sha256=ktV8_Th2DiwQ0W6afOCau9kBJ8pOrqR-SM2Y2GRy-xE,1869
|
13
13
|
pyplumio/devices/__init__.py,sha256=OLPY_Kk5E2SiJ4FLN2g6zmKQdQfutePV5jRH9kRHAMA,8260
|
14
14
|
pyplumio/devices/ecomax.py,sha256=3_Hk6RaQ2e9WqIJ2NdPhofgVFjLbWIyR3TsRmMG35WY,16043
|
15
15
|
pyplumio/devices/ecoster.py,sha256=X46ky5XT8jHMFq9sBW0ve8ZI_tjItQDMt4moXsW-ogY,307
|
16
16
|
pyplumio/devices/mixer.py,sha256=7WdUVgwO4VXmaPNzh3ZWpKr2ooRXWemz2KFHAw35_Rk,2731
|
17
17
|
pyplumio/devices/thermostat.py,sha256=MHMKe45fQ7jKlhBVObJ7McbYQKuF6-LOKSHy-9VNsCU,2253
|
18
|
-
pyplumio/frames/__init__.py,sha256=
|
18
|
+
pyplumio/frames/__init__.py,sha256=QAjdvZxQj5Av1OKFqdlSgZBn3RbCcRVMQv_lCnTkW5M,8272
|
19
19
|
pyplumio/frames/messages.py,sha256=ImQGWFFTa2eaXfytQmFZKC-IxyPRkxD8qp0bEm16-ws,3628
|
20
20
|
pyplumio/frames/requests.py,sha256=jr-_XSSCCDDTbAmrw95CKyWa5nb7JNeGzZ2jDXIxlAo,7348
|
21
21
|
pyplumio/frames/responses.py,sha256=M6Ky4gg2AoShmRXX0x6nftajxrvmQLKPVRWbwyhvI0E,6663
|
@@ -24,8 +24,7 @@ pyplumio/helpers/async_cache.py,sha256=EGQcU8LWJpVx3Hk6iaI-3mqAhnR5ACfBOGb9tWw-V
|
|
24
24
|
pyplumio/helpers/event_manager.py,sha256=aKNlhsPNTy3eOSfWVb9TJxtIsN9GAQv9XxhOi_BOhlM,8097
|
25
25
|
pyplumio/helpers/factory.py,sha256=c3sitnkUjJWz7fPpTE9uRIpa8h46Qim3xsAblMw3eDo,1049
|
26
26
|
pyplumio/helpers/task_manager.py,sha256=N71F6Ag1HHxdf5zJeCMcEziFdH9lmJKtMPoRGjJ-E40,1209
|
27
|
-
pyplumio/
|
28
|
-
pyplumio/parameters/__init__.py,sha256=2YTJJF-ehMLbPJwp02I1fycyLsatIXPSlTxXLwtkHtk,16054
|
27
|
+
pyplumio/parameters/__init__.py,sha256=YKIXmb_-E2HeIVljDHdD2bLbsfUsQ8sVhl9sl7kLzyo,16220
|
29
28
|
pyplumio/parameters/ecomax.py,sha256=4UqI7cokCt7qS9Du4-7JgLhM7mhHCHt8SWPl_qncmXQ,26239
|
30
29
|
pyplumio/parameters/mixer.py,sha256=RjhfUU_62STyNV0Ud9A4G4FEvVwo02qGVl8h1QvqQXI,6646
|
31
30
|
pyplumio/parameters/thermostat.py,sha256=-DK2Mb78CGrKmdhwAD0M3GiGJatczPnl1e2gVeT19tI,5070
|
@@ -57,8 +56,8 @@ pyplumio/structures/statuses.py,sha256=1h-EUw1UtuS44E19cNOSavUgZeAxsLgX3iS0eVC8p
|
|
57
56
|
pyplumio/structures/temperatures.py,sha256=2VD3P_vwp9PEBkOn2-WhifOR8w-UYNq35aAxle0z2Vg,2831
|
58
57
|
pyplumio/structures/thermostat_parameters.py,sha256=st3x3HkjQm3hqBrn_fpvPDQu8fuc-Sx33ONB19ViQak,3007
|
59
58
|
pyplumio/structures/thermostat_sensors.py,sha256=rO9jTZWGQpThtJqVdbbv8sYMYHxJi4MfwZQza69L2zw,3399
|
60
|
-
pyplumio-0.5.
|
61
|
-
pyplumio-0.5.
|
62
|
-
pyplumio-0.5.
|
63
|
-
pyplumio-0.5.
|
64
|
-
pyplumio-0.5.
|
59
|
+
pyplumio-0.5.53.dist-info/licenses/LICENSE,sha256=m-UuZFjXJ22uPTGm9kSHS8bqjsf5T8k2wL9bJn1Y04o,1088
|
60
|
+
pyplumio-0.5.53.dist-info/METADATA,sha256=GxKUdJNkna132kU5kPYV8_piH9cqw34mVUnflq1L1Rc,5615
|
61
|
+
pyplumio-0.5.53.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
62
|
+
pyplumio-0.5.53.dist-info/top_level.txt,sha256=kNBz9UPPkPD9teDn3U_sEy5LjzwLm9KfADCXtBlbw8A,9
|
63
|
+
pyplumio-0.5.53.dist-info/RECORD,,
|
pyplumio/helpers/timeout.py
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
"""Contains a timeout decorator."""
|
2
|
-
|
3
|
-
from __future__ import annotations
|
4
|
-
|
5
|
-
import asyncio
|
6
|
-
from collections.abc import Awaitable, Callable
|
7
|
-
from functools import wraps
|
8
|
-
from typing import TypeVar
|
9
|
-
|
10
|
-
from typing_extensions import ParamSpec
|
11
|
-
|
12
|
-
T = TypeVar("T")
|
13
|
-
P = ParamSpec("P")
|
14
|
-
|
15
|
-
|
16
|
-
def timeout(
|
17
|
-
seconds: float,
|
18
|
-
) -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]:
|
19
|
-
"""Decorate a timeout for the awaitable."""
|
20
|
-
|
21
|
-
def decorator(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
|
22
|
-
@wraps(func)
|
23
|
-
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
24
|
-
return await asyncio.wait_for(func(*args, **kwargs), timeout=seconds)
|
25
|
-
|
26
|
-
setattr(wrapper, "_has_timeout_seconds", seconds)
|
27
|
-
return wrapper
|
28
|
-
|
29
|
-
return decorator
|
30
|
-
|
31
|
-
|
32
|
-
__all__ = ["timeout"]
|
File without changes
|
File without changes
|
File without changes
|