stompman 3.4.0__tar.gz → 3.5.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stompman
3
- Version: 3.4.0
3
+ Version: 3.5.0
4
4
  Summary: Python STOMP client with pleasant API
5
5
  Project-URL: repository, https://github.com/community-of-python/stompman
6
6
  Author-email: Lev Vereshchagin <mail@vrslev.com>
@@ -37,7 +37,7 @@ def _reraise_connection_lost(*causes: type[Exception]) -> Generator[None, None,
37
37
  try:
38
38
  yield
39
39
  except causes as exception:
40
- raise ConnectionLostError from exception
40
+ raise ConnectionLostError(reason=exception) from exception
41
41
 
42
42
 
43
43
  @dataclass(kw_only=True, slots=True)
@@ -85,10 +85,8 @@ class Connection(AbstractConnection):
85
85
  await self.writer.drain()
86
86
 
87
87
  async def _read_non_empty_bytes(self, max_chunk_size: int) -> bytes:
88
- while ( # noqa: ASYNC110
89
- chunk := await self.reader.read(max_chunk_size)
90
- ) == b"": # pragma: no cover (it definitely happens)
91
- await asyncio.sleep(0)
88
+ if (chunk := await self.reader.read(max_chunk_size)) == b"":
89
+ raise ConnectionLostError(reason="eof")
92
90
  return chunk
93
91
 
94
92
  async def read_frames(self) -> AsyncGenerator[AnyServerFrame, None]:
@@ -103,7 +103,7 @@ class ConnectionManager:
103
103
  if not self._active_connection_state:
104
104
  continue
105
105
  if not self._active_connection_state.is_alive(self.check_server_alive_interval_factor):
106
- self._clear_active_connection_state()
106
+ self._clear_active_connection_state(ConnectionLostError(reason="server heartbeat timeout"))
107
107
 
108
108
  async def _create_connection_to_one_server(
109
109
  self, server: ConnectionParameters
@@ -168,7 +168,7 @@ class ConnectionManager:
168
168
  self._active_connection_state = connection_result
169
169
  if not is_initial_call:
170
170
  LOGGER.warning(
171
- "reconnected after failure connection failure. connection_parameters: %s",
171
+ "reconnected after connection failure. connection_parameters: %s",
172
172
  connection_result.lifespan.connection_parameters,
173
173
  )
174
174
  return connection_result
@@ -178,11 +178,12 @@ class ConnectionManager:
178
178
 
179
179
  raise FailedAllConnectAttemptsError(retry_attempts=self.connect_retry_attempts, issues=connection_issues)
180
180
 
181
- def _clear_active_connection_state(self) -> None:
181
+ def _clear_active_connection_state(self, error_reason: ConnectionLostError) -> None:
182
182
  if not self._active_connection_state:
183
183
  return
184
184
  LOGGER.warning(
185
- "connection lost. connection_parameters: %s",
185
+ "connection lost. reason: %s, connection_parameters: %s",
186
+ error_reason.reason,
186
187
  self._active_connection_state.lifespan.connection_parameters,
187
188
  )
188
189
  self._active_connection_state = None
@@ -192,8 +193,8 @@ class ConnectionManager:
192
193
  connection_state = await self._get_active_connection_state()
193
194
  try:
194
195
  return connection_state.connection.write_heartbeat()
195
- except ConnectionLostError:
196
- self._clear_active_connection_state()
196
+ except ConnectionLostError as error:
197
+ self._clear_active_connection_state(error)
197
198
 
198
199
  raise FailedAllWriteAttemptsError(retry_attempts=self.write_retry_attempts)
199
200
 
@@ -202,8 +203,8 @@ class ConnectionManager:
202
203
  connection_state = await self._get_active_connection_state()
203
204
  try:
204
205
  return await connection_state.connection.write_frame(frame)
205
- except ConnectionLostError:
206
- self._clear_active_connection_state()
206
+ except ConnectionLostError as error:
207
+ self._clear_active_connection_state(error)
207
208
 
208
209
  raise FailedAllWriteAttemptsError(retry_attempts=self.write_retry_attempts)
209
210
 
@@ -213,15 +214,15 @@ class ConnectionManager:
213
214
  try:
214
215
  async for frame in connection_state.connection.read_frames():
215
216
  yield frame
216
- except ConnectionLostError:
217
- self._clear_active_connection_state()
217
+ except ConnectionLostError as error:
218
+ self._clear_active_connection_state(error)
218
219
 
219
220
  async def maybe_write_frame(self, frame: AnyClientFrame) -> bool:
220
221
  if not self._active_connection_state:
221
222
  return False
222
223
  try:
223
224
  await self._active_connection_state.connection.write_frame(frame)
224
- except ConnectionLostError:
225
- self._clear_active_connection_state()
225
+ except ConnectionLostError as error:
226
+ self._clear_active_connection_state(error)
226
227
  return False
227
228
  return True
@@ -14,6 +14,8 @@ class Error(Exception):
14
14
  class ConnectionLostError(Error):
15
15
  """Raised in stompman.AbstractConnection—and handled in stompman.ConnectionManager, therefore is private."""
16
16
 
17
+ reason: Exception | str
18
+
17
19
 
18
20
  @dataclass(frozen=True, kw_only=True, slots=True)
19
21
  class ConnectionConfirmationTimeout:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes