@@ -11,7 +11,7 @@ class Handle(Protocol):
11
11
12
12
def read (self , size : int ) -> bytes :
13
13
""" "
14
- Read up to `size` bytes.
14
+ Read up to `size` bytes.
15
15
"""
16
16
17
17
def write (self , data : bytes ) -> int :
@@ -105,12 +105,9 @@ def __init__(
105
105
106
106
# Pre-allocate buffer that fits header + body. The premable will be
107
107
# cleared when it is detected, so it does not need space.
108
- self .stream = bytearray (max_length + consts .LEN_HEADER + consts .LEN_BODY )
108
+ self .buffer = bytearray (max_length + consts .LEN_HEADER + consts .LEN_BODY )
109
109
self .index = 0
110
110
111
- # Python 2 does not allow unpack from bytearray, but Python 3.
112
- self .buffer = self .stream
113
-
114
111
def write_frame (self , frame : Frame ) -> int :
115
112
"""
116
113
Write a frame via the handle.
@@ -168,8 +165,8 @@ def read(self, limit: int = 1) -> list[Frame]:
168
165
if not char :
169
166
return []
170
167
171
- # Append to stream .
172
- self .stream [self .index ] = ord (char )
168
+ # Append to buffer .
169
+ self .buffer [self .index ] = ord (char )
173
170
self .index += 1
174
171
175
172
# Decide what to do.
@@ -187,10 +184,10 @@ def read(self, limit: int = 1) -> list[Frame]:
187
184
self .index
188
185
== self .max_length + consts .LEN_HEADER + consts .LEN_BODY
189
186
):
190
- # Preamble not found and stream is full. Copy last four
187
+ # Preamble not found and buffer is full. Copy last four
191
188
# bytes, because the next byte may form the preamble
192
189
# together with the last three bytes.
193
- self .stream [0 :4 ] = self .stream [- 4 :]
190
+ self .buffer [0 :4 ] = self .buffer [- 4 :]
194
191
self .index = 4
195
192
196
193
elif self .state == consts .WAITING_FOR_HEADER :
0 commit comments