Skip to content

Commit 2dda203

Browse files
Optimize packet parsing to avoid calls to json parser (Fixes #399)
1 parent 3e70a1e commit 2dda203

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/engineio/packet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def decode(self, encoded_packet):
7272
else:
7373
self.packet_type = int(encoded_packet[0])
7474
try:
75-
self.data = self.json.loads(encoded_packet[1:])
76-
if isinstance(self.data, int):
75+
if encoded_packet[1].isnumeric():
7776
# do not allow integer payloads, see
7877
# github.com/miguelgrinberg/python-engineio/issues/75
7978
# for background on this decision
8079
raise ValueError
81-
except ValueError:
80+
self.data = self.json.loads(encoded_packet[1:])
81+
except (ValueError, IndexError):
8282
self.data = encoded_packet[1:]

0 commit comments

Comments
 (0)