Skip to content

Commit 18b602e

Browse files
authored
Merge pull request #3 from basilfx/feature/python2_removal
Remove self.stream that existed for compatibility
2 parents a3ce7e5 + f226277 commit 18b602e

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

tinylink/link.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Handle(Protocol):
1111

1212
def read(self, size: int) -> bytes:
1313
""" "
14-
Read up to `size` bytes.
14+
Read up to `size` bytes.
1515
"""
1616

1717
def write(self, data: bytes) -> int:
@@ -105,12 +105,9 @@ def __init__(
105105

106106
# Pre-allocate buffer that fits header + body. The premable will be
107107
# 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)
109109
self.index = 0
110110

111-
# Python 2 does not allow unpack from bytearray, but Python 3.
112-
self.buffer = self.stream
113-
114111
def write_frame(self, frame: Frame) -> int:
115112
"""
116113
Write a frame via the handle.
@@ -168,8 +165,8 @@ def read(self, limit: int = 1) -> list[Frame]:
168165
if not char:
169166
return []
170167

171-
# Append to stream.
172-
self.stream[self.index] = ord(char)
168+
# Append to buffer.
169+
self.buffer[self.index] = ord(char)
173170
self.index += 1
174171

175172
# Decide what to do.
@@ -187,10 +184,10 @@ def read(self, limit: int = 1) -> list[Frame]:
187184
self.index
188185
== self.max_length + consts.LEN_HEADER + consts.LEN_BODY
189186
):
190-
# Preamble not found and stream is full. Copy last four
187+
# Preamble not found and buffer is full. Copy last four
191188
# bytes, because the next byte may form the preamble
192189
# together with the last three bytes.
193-
self.stream[0:4] = self.stream[-4:]
190+
self.buffer[0:4] = self.buffer[-4:]
194191
self.index = 4
195192

196193
elif self.state == consts.WAITING_FOR_HEADER:

0 commit comments

Comments
 (0)