stompman 0.2.0__tar.gz → 0.2.1__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.1
2
2
  Name: stompman
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Python STOMP client with pleasant API
5
5
  Home-page: https://github.com/vrslev/stompman
6
6
  License: MIT
@@ -8,10 +8,15 @@ Keywords: stomp,artemis,activemq,messaging,jms
8
8
  Author: Lev Vereshchagin
9
9
  Author-email: mail@vrslev.com
10
10
  Requires-Python: >=3.11,<4.0
11
+ Classifier: Development Status :: 4 - Beta
11
12
  Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
12
14
  Classifier: Programming Language :: Python :: 3
13
15
  Classifier: Programming Language :: Python :: 3.11
14
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Topic :: System :: Networking
19
+ Classifier: Typing :: Typed
15
20
  Project-URL: Repository, https://github.com/vrslev/stompman
16
21
  Description-Content-Type: text/markdown
17
22
 
@@ -1,12 +1,19 @@
1
1
  [tool.poetry]
2
2
  name = "stompman"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "Python STOMP client with pleasant API"
5
5
  license = "MIT"
6
6
  authors = ["Lev Vereshchagin <mail@vrslev.com>"]
7
7
  readme = "README.md"
8
8
  repository = "https://github.com/vrslev/stompman"
9
9
  keywords = ["stomp", "artemis", "activemq", "messaging", "jms"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Natural Language :: English",
13
+ "Programming Language :: Python :: Implementation :: CPython",
14
+ "Topic :: System :: Networking",
15
+ "Typing :: Typed",
16
+ ]
10
17
 
11
18
  [tool.poetry.dependencies]
12
19
  python = "^3.11"
@@ -1,11 +1,11 @@
1
1
  import asyncio
2
- from collections.abc import AsyncGenerator, Iterable
2
+ from collections.abc import AsyncGenerator, Iterator
3
3
  from dataclasses import dataclass, field
4
4
  from typing import Protocol, TypeVar, cast
5
5
 
6
6
  from stompman.errors import ConnectError, ReadTimeoutError
7
7
  from stompman.frames import AnyRealFrame, ClientFrame, ServerFrame
8
- from stompman.protocol import NEWLINE, Parser, dump_frame, separate_complete_and_incomplete_packet_parts
8
+ from stompman.protocol import NEWLINE, Parser, dump_frame
9
9
 
10
10
 
11
11
  @dataclass
@@ -76,17 +76,13 @@ class Connection(AbstractConnection):
76
76
  return chunk
77
77
 
78
78
  async def read_frames(self) -> AsyncGenerator[ServerFrame, None]:
79
- incomplete_bytes = b""
80
79
  parser = Parser()
81
80
 
82
81
  while True:
83
82
  try:
84
- received_bytes = await asyncio.wait_for(self._read_non_empty_bytes(), timeout=self.read_timeout)
83
+ raw_frames = await asyncio.wait_for(self._read_non_empty_bytes(), timeout=self.read_timeout)
85
84
  except TimeoutError as exception:
86
- raise ReadTimeoutError(timeout=self.read_timeout) from exception
85
+ raise ReadTimeoutError(self.read_timeout) from exception
87
86
 
88
- complete_bytes, incomplete_bytes = separate_complete_and_incomplete_packet_parts(
89
- incomplete_bytes + received_bytes
90
- )
91
- for frame in cast(Iterable[ServerFrame], parser.load_frames(received_bytes)):
87
+ for frame in cast(Iterator[ServerFrame], parser.load_frames(raw_frames)):
92
88
  yield frame
@@ -49,16 +49,6 @@ def dump_frame(frame: AnyRealFrame) -> bytes:
49
49
  return b"".join(lines)
50
50
 
51
51
 
52
- def separate_complete_and_incomplete_packet_parts(raw_frames: bytes) -> tuple[bytes, bytes]:
53
- if raw_frames.replace(NEWLINE, b"") == b"":
54
- return (raw_frames, b"")
55
- parts = raw_frames.rpartition(NULL)
56
- if parts[2].replace(NEWLINE, b"") == b"":
57
- return (raw_frames, b"")
58
-
59
- return parts[0] + parts[1], parts[2]
60
-
61
-
62
52
  def unescape_byte(byte: bytes, previous_byte: bytes | None) -> bytes | None:
63
53
  if byte == b"\\":
64
54
  return None
@@ -106,43 +96,38 @@ def parse_lines_into_frame(lines: deque[list[bytes]]) -> AnyFrame | None:
106
96
 
107
97
  @dataclass
108
98
  class Parser:
109
- _remainder_from_last_packet: bytes = field(default=b"", init=False)
99
+ _lines: deque[list[bytes]] = field(default_factory=deque, init=False)
100
+ _current_line: list[bytes] = field(default_factory=list, init=False)
101
+ _previous_byte: bytes = field(default=b"", init=False)
102
+ _headers_processed: bool = field(default=False, init=False)
110
103
 
111
104
  def load_frames(self, raw_frames: bytes) -> Iterator[AnyFrame]:
112
- all_bytes = self._remainder_from_last_packet + raw_frames
113
- buffer = deque(struct.unpack(f"{len(all_bytes)!s}c", all_bytes))
114
- lines = deque[list[bytes]]()
115
- current_line: list[bytes] = []
116
- previous_byte = None
117
- headers_processed = False
118
-
105
+ buffer = deque(struct.unpack(f"{len(raw_frames)!s}c", raw_frames))
119
106
  while buffer:
120
107
  byte = buffer.popleft()
121
108
 
122
- if headers_processed and byte == NULL:
123
- lines.append(current_line)
124
- if parsed_frame := parse_lines_into_frame(lines):
109
+ if self._headers_processed and byte == NULL:
110
+ self._lines.append(self._current_line)
111
+ if parsed_frame := parse_lines_into_frame(self._lines):
125
112
  yield parsed_frame
126
- headers_processed = False
127
- lines.clear()
128
- current_line = []
113
+ self._headers_processed = False
114
+ self._lines.clear()
115
+ self._current_line = []
129
116
 
130
- elif not headers_processed and byte == NEWLINE:
131
- if current_line or lines:
132
- if not current_line: # extra empty line after headers
133
- headers_processed = True
117
+ elif not self._headers_processed and byte == NEWLINE:
118
+ if self._current_line or self._lines:
119
+ if not self._current_line: # extra empty line after headers
120
+ self._headers_processed = True
134
121
 
135
- if previous_byte == b"\r":
136
- current_line.pop()
122
+ if self._previous_byte == b"\r":
123
+ self._current_line.pop()
137
124
 
138
- lines.append(current_line)
139
- current_line = []
125
+ self._lines.append(self._current_line)
126
+ self._current_line = []
140
127
  else:
141
128
  yield HeartbeatFrame()
142
129
 
143
130
  else:
144
- current_line.append(byte)
145
-
146
- previous_byte = byte
131
+ self._current_line.append(byte)
147
132
 
148
- self._remainder_from_last_packet = b"".join(current_line)
133
+ self._previous_byte = byte
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes