Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b95ca24

Browse files
FuNK3Ydpgeorge
FuNK3Y
authored andcommitted
aiohttp: Fix partial reads by using readexactly.
Fixes issue #1012. Signed-off-by: FuNK3Y <fun__key@hotmail.com>
1 parent f95568d commit b95ca24

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

‎python-ecosys/aiohttp/aiohttp/__init__.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def _decode(self, data):
4242
return data
4343

4444
async def read(self, sz=-1):
45-
return self._decode(await self.content.read(sz))
45+
return self._decode(
46+
await (self.content.read(sz) if sz == -1 else self.content.readexactly(sz))
47+
)
4648

4749
async def text(self, encoding="utf-8"):
4850
return (await self.read(int(self._get_header("content-length", -1)))).decode(encoding)
@@ -66,13 +68,13 @@ async def read(self, sz=4 * 1024 * 1024):
6668
self.chunk_size = int(l, 16)
6769
if self.chunk_size == 0:
6870
# End of message
69-
sep = await self.content.read(2)
71+
sep = await self.content.readexactly(2)
7072
assert sep == b"\r\n"
7173
return b""
72-
data = await self.content.read(min(sz, self.chunk_size))
74+
data = await self.content.readexactly(min(sz, self.chunk_size))
7375
self.chunk_size -= len(data)
7476
if self.chunk_size == 0:
75-
sep = await self.content.read(2)
77+
sep = await self.content.readexactly(2)
7678
assert sep == b"\r\n"
7779
return self._decode(data)
7880

‎python-ecosys/aiohttp/aiohttp/aiohttp_ws.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,21 @@ async def close(self):
189189
await self.send(b"", self.CLOSE)
190190

191191
async def _read_frame(self):
192-
header = await self.reader.read(2)
192+
header = await self.reader.readexactly(2)
193193
if len(header) != 2: # pragma: no cover
194194
# raise OSError(32, "Websocket connection closed")
195195
opcode = self.CLOSE
196196
payload = b""
197197
return opcode, payload
198198
fin, opcode, has_mask, length = self._parse_frame_header(header)
199199
if length == 126: # Magic number, length header is 2 bytes
200-
(length,) = struct.unpack("!H", await self.reader.read(2))
200+
(length,) = struct.unpack("!H", await self.reader.readexactly(2))
201201
elif length == 127: # Magic number, length header is 8 bytes
202-
(length,) = struct.unpack("!Q", await self.reader.read(8))
202+
(length,) = struct.unpack("!Q", await self.reader.readexactly(8))
203203

204204
if has_mask: # pragma: no cover
205-
mask = await self.reader.read(4)
206-
payload = await self.reader.read(length)
205+
mask = await self.reader.readexactly(4)
206+
payload = await self.reader.readexactly(length)
207207
if has_mask: # pragma: no cover
208208
payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload))
209209
return opcode, payload

‎python-ecosys/aiohttp/manifest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
metadata(
22
description="HTTP client module for MicroPython asyncio module",
3-
version="0.0.5",
3+
version="0.0.6",
44
pypi="aiohttp",
55
)
66

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /