From 4940fc1e1e2ddc86c28cd3b626dad75d6845243f Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 2 Dec 2020 07:59:11 +0000 Subject: [PATCH] v5 protocol: rename ERROR packet to CONNECT_ERROR --- socketio/asyncio_client.py | 2 +- socketio/asyncio_server.py | 7 ++++--- socketio/client.py | 2 +- socketio/packet.py | 4 ++-- socketio/server.py | 7 ++++--- tests/common/test_packet.py | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/socketio/asyncio_client.py b/socketio/asyncio_client.py index 6c97203..85ea3c2 100644 --- a/socketio/asyncio_client.py +++ b/socketio/asyncio_client.py @@ -450,7 +450,7 @@ class AsyncClient(client.Client): elif pkt.packet_type == packet.BINARY_EVENT or \ pkt.packet_type == packet.BINARY_ACK: self._binary_packet = pkt - elif pkt.packet_type == packet.ERROR: + elif pkt.packet_type == packet.CONNECT_ERROR: await self._handle_error(pkt.namespace, pkt.data) else: raise ValueError('Unknown packet type.') diff --git a/socketio/asyncio_server.py b/socketio/asyncio_server.py index 30d1505..7a7e324 100644 --- a/socketio/asyncio_server.py +++ b/socketio/asyncio_server.py @@ -427,7 +427,8 @@ class AsyncServer(server.Server): packet.DISCONNECT, data=fail_reason, namespace=namespace)) elif namespace != '/': await self._send_packet(sid, packet.Packet( - packet.ERROR, data=fail_reason, namespace=namespace)) + packet.CONNECT_ERROR, data=fail_reason, + namespace=namespace)) self.manager.disconnect(sid, namespace) if namespace == '/' and sid in self.environ: # pragma: no cover del self.environ[sid] @@ -541,8 +542,8 @@ class AsyncServer(server.Server): elif pkt.packet_type == packet.BINARY_EVENT or \ pkt.packet_type == packet.BINARY_ACK: self._binary_packet[sid] = pkt - elif pkt.packet_type == packet.ERROR: - raise ValueError('Unexpected ERROR packet.') + elif pkt.packet_type == packet.CONNECT_ERROR: + raise ValueError('Unexpected CONNECT_ERROR packet.') else: raise ValueError('Unknown packet type.') diff --git a/socketio/client.py b/socketio/client.py index 2ca8396..7b26358 100644 --- a/socketio/client.py +++ b/socketio/client.py @@ -605,7 +605,7 @@ class Client(object): elif pkt.packet_type == packet.BINARY_EVENT or \ pkt.packet_type == packet.BINARY_ACK: self._binary_packet = pkt - elif pkt.packet_type == packet.ERROR: + elif pkt.packet_type == packet.CONNECT_ERROR: self._handle_error(pkt.namespace, pkt.data) else: raise ValueError('Unknown packet type.') diff --git a/socketio/packet.py b/socketio/packet.py index 73b469d..bcb45c4 100644 --- a/socketio/packet.py +++ b/socketio/packet.py @@ -3,9 +3,9 @@ import json as _json import six -(CONNECT, DISCONNECT, EVENT, ACK, ERROR, BINARY_EVENT, BINARY_ACK) = \ +(CONNECT, DISCONNECT, EVENT, ACK, CONNECT_ERROR, BINARY_EVENT, BINARY_ACK) = \ (0, 1, 2, 3, 4, 5, 6) -packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'ERROR', +packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'CONNECT_ERROR', 'BINARY_EVENT', 'BINARY_ACK'] diff --git a/socketio/server.py b/socketio/server.py index 7e99510..eb8ae42 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -625,7 +625,8 @@ class Server(object): packet.DISCONNECT, data=fail_reason, namespace=namespace)) elif namespace != '/': self._send_packet(sid, packet.Packet( - packet.ERROR, data=fail_reason, namespace=namespace)) + packet.CONNECT_ERROR, data=fail_reason, + namespace=namespace)) self.manager.disconnect(sid, namespace) if namespace == '/' and sid in self.environ: # pragma: no cover del self.environ[sid] @@ -729,8 +730,8 @@ class Server(object): elif pkt.packet_type == packet.BINARY_EVENT or \ pkt.packet_type == packet.BINARY_ACK: self._binary_packet[sid] = pkt - elif pkt.packet_type == packet.ERROR: - raise ValueError('Unexpected ERROR packet.') + elif pkt.packet_type == packet.CONNECT_ERROR: + raise ValueError('Unexpected CONNECT_ERROR packet.') else: raise ValueError('Unknown packet type.') diff --git a/tests/common/test_packet.py b/tests/common/test_packet.py index 3643451..2f859cd 100644 --- a/tests/common/test_packet.py +++ b/tests/common/test_packet.py @@ -87,7 +87,7 @@ class TestPacket(unittest.TestCase): def test_invalid_binary_packet(self): with pytest.raises(ValueError): - packet.Packet(packet_type=packet.ERROR, data=b'123') + packet.Packet(packet_type=packet.CONNECT_ERROR, data=b'123') def test_encode_namespace(self): pkt = packet.Packet(