diff --git a/setup.py b/setup.py index da83f00..80365c2 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,6 @@ setup( include_package_data=True, platforms='any', install_requires=[ - 'six>=1.9.0', 'bidict>=0.21.0', 'python-engineio>=3.13.0,<4' ], diff --git a/socketio/asyncio_client.py b/socketio/asyncio_client.py index e8f3013..c10b39e 100644 --- a/socketio/asyncio_client.py +++ b/socketio/asyncio_client.py @@ -3,7 +3,6 @@ import logging import random import engineio -import six from . import client from . import exceptions @@ -100,7 +99,7 @@ class AsyncClient(client.Client): set(self.namespace_handlers.keys()))) if len(namespaces) == 0: namespaces = ['/'] - elif isinstance(namespaces, six.string_types): + elif isinstance(namespaces, str): namespaces = [namespaces] self.connection_namespaces = namespaces try: @@ -111,7 +110,7 @@ class AsyncClient(client.Client): await self._trigger_event( 'connect_error', '/', exc.args[1] if len(exc.args) > 1 else exc.args[0]) - six.raise_from(exceptions.ConnectionError(exc.args[0]), None) + raise exceptions.ConnectionError(exc.args[0]) from None self.connected = True async def wait(self): @@ -237,7 +236,7 @@ class AsyncClient(client.Client): try: await asyncio.wait_for(callback_event.wait(), timeout) except asyncio.TimeoutError: - six.raise_from(exceptions.TimeoutError(), None) + raise exceptions.TimeoutError() from None return callback_args[0] if len(callback_args[0]) > 1 \ else callback_args[0][0] if len(callback_args[0]) == 1 \ else None diff --git a/socketio/asyncio_pubsub_manager.py b/socketio/asyncio_pubsub_manager.py index fc4e205..cabd41e 100644 --- a/socketio/asyncio_pubsub_manager.py +++ b/socketio/asyncio_pubsub_manager.py @@ -3,7 +3,6 @@ import uuid import json import pickle -import six from .asyncio_manager import AsyncManager @@ -157,7 +156,7 @@ class AsyncPubSubManager(AsyncManager): if isinstance(message, dict): data = message else: - if isinstance(message, six.binary_type): # pragma: no cover + if isinstance(message, bytes): # pragma: no cover try: data = pickle.loads(message) except: diff --git a/socketio/asyncio_server.py b/socketio/asyncio_server.py index 20edbd5..1610e5e 100644 --- a/socketio/asyncio_server.py +++ b/socketio/asyncio_server.py @@ -1,7 +1,6 @@ import asyncio import engineio -import six from . import asyncio_manager from . import exceptions @@ -228,7 +227,7 @@ class AsyncServer(server.Server): try: await asyncio.wait_for(callback_event.wait(), timeout) except asyncio.TimeoutError: - six.raise_from(exceptions.TimeoutError(), None) + raise exceptions.TimeoutError() from None return callback_args[0] if len(callback_args[0]) > 1 \ else callback_args[0][0] if len(callback_args[0]) == 1 \ else None diff --git a/socketio/base_manager.py b/socketio/base_manager.py index 89c755b..58d4faa 100644 --- a/socketio/base_manager.py +++ b/socketio/base_manager.py @@ -2,7 +2,6 @@ import itertools import logging from bidict import bidict -import six default_logger = logging.getLogger('socketio') @@ -35,7 +34,7 @@ class BaseManager(object): def get_namespaces(self): """Return an iterable with the active namespace names.""" - return six.iterkeys(self.rooms) + return self.rooms.keys() def get_participants(self, namespace, room): """Return an iterable with the active participants in a room.""" @@ -83,7 +82,7 @@ class BaseManager(object): if namespace not in self.rooms: return rooms = [] - for room_name, room in six.iteritems(self.rooms[namespace].copy()): + for room_name, room in self.rooms[namespace].copy().items(): if sid in room: rooms.append(room_name) for room in rooms: @@ -129,7 +128,7 @@ class BaseManager(object): """Return the rooms a client is in.""" r = [] try: - for room_name, room in six.iteritems(self.rooms[namespace]): + for room_name, room in self.rooms[namespace].items(): if room_name is not None and sid in room: r.append(room_name) except KeyError: @@ -169,7 +168,7 @@ class BaseManager(object): """Generate a unique identifier for an ACK packet.""" if sid not in self.callbacks: self.callbacks[sid] = {0: itertools.count(1)} - id = six.next(self.callbacks[sid][0]) + id = next(self.callbacks[sid][0]) self.callbacks[sid][id] = callback return id diff --git a/socketio/client.py b/socketio/client.py index ab685e8..06aceaf 100644 --- a/socketio/client.py +++ b/socketio/client.py @@ -5,7 +5,6 @@ import signal import threading import engineio -import six from . import exceptions from . import namespace @@ -268,7 +267,7 @@ class Client(object): set(self.namespace_handlers.keys()))) if len(namespaces) == 0: namespaces = ['/'] - elif isinstance(namespaces, six.string_types): + elif isinstance(namespaces, str): namespaces = [namespaces] self.connection_namespaces = namespaces try: @@ -278,7 +277,7 @@ class Client(object): self._trigger_event( 'connect_error', '/', exc.args[1] if len(exc.args) > 1 else exc.args[0]) - six.raise_from(exceptions.ConnectionError(exc.args[0]), None) + raise exceptions.ConnectionError(exc.args[0]) from None self.connected = True def wait(self): @@ -471,7 +470,7 @@ class Client(object): namespace = namespace or '/' if namespace not in self.callbacks: self.callbacks[namespace] = {0: itertools.count(1)} - id = six.next(self.callbacks[namespace][0]) + id = next(self.callbacks[namespace][0]) self.callbacks[namespace][id] = callback return id diff --git a/socketio/packet.py b/socketio/packet.py index bcb45c4..49f210e 100644 --- a/socketio/packet.py +++ b/socketio/packet.py @@ -1,8 +1,6 @@ import functools import json as _json -import six - (CONNECT, DISCONNECT, EVENT, ACK, CONNECT_ERROR, BINARY_EVENT, BINARY_ACK) = \ (0, 1, 2, 3, 4, 5, 6) packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'CONNECT_ERROR', @@ -49,10 +47,10 @@ class Packet(object): of packets where the first is the original packet with placeholders for the binary components and the remaining ones the binary attachments. """ - encoded_packet = six.text_type(self.packet_type) + encoded_packet = str(self.packet_type) if self.packet_type == BINARY_EVENT or self.packet_type == BINARY_ACK: data, attachments = self._deconstruct_binary(self.data) - encoded_packet += six.text_type(len(attachments)) + '-' + encoded_packet += str(len(attachments)) + '-' else: data = self.data attachments = None @@ -64,7 +62,7 @@ class Packet(object): if needs_comma: encoded_packet += ',' needs_comma = False - encoded_packet += six.text_type(self.id) + encoded_packet += str(self.id) if data is not None: if needs_comma: encoded_packet += ',' @@ -139,7 +137,7 @@ class Packet(object): else: return {key: self._reconstruct_binary_internal(value, attachments) - for key, value in six.iteritems(data)} + for key, value in data.items()} else: return data @@ -150,7 +148,7 @@ class Packet(object): return data, attachments def _deconstruct_binary_internal(self, data, attachments): - if isinstance(data, six.binary_type): + if isinstance(data, bytes): attachments.append(data) return {'_placeholder': True, 'num': len(attachments) - 1} elif isinstance(data, list): @@ -158,13 +156,13 @@ class Packet(object): for item in data] elif isinstance(data, dict): return {key: self._deconstruct_binary_internal(value, attachments) - for key, value in six.iteritems(data)} + for key, value in data.items()} else: return data def _data_is_binary(self, data): """Check if the data contains binary components.""" - if isinstance(data, six.binary_type): + if isinstance(data, bytes): return True elif isinstance(data, list): return functools.reduce( @@ -173,7 +171,7 @@ class Packet(object): elif isinstance(data, dict): return functools.reduce( lambda a, b: a or b, [self._data_is_binary(item) - for item in six.itervalues(data)], + for item in data.values()], False) else: return False diff --git a/socketio/pubsub_manager.py b/socketio/pubsub_manager.py index dcbef88..ff3304c 100644 --- a/socketio/pubsub_manager.py +++ b/socketio/pubsub_manager.py @@ -3,7 +3,6 @@ import uuid import json import pickle -import six from .base_manager import BaseManager @@ -148,7 +147,7 @@ class PubSubManager(BaseManager): if isinstance(message, dict): data = message else: - if isinstance(message, six.binary_type): # pragma: no cover + if isinstance(message, bytes): # pragma: no cover try: data = pickle.loads(message) except: diff --git a/socketio/server.py b/socketio/server.py index 6870637..c2c4969 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -1,7 +1,6 @@ import logging import engineio -import six from . import base_manager from . import exceptions diff --git a/socketio/zmq_manager.py b/socketio/zmq_manager.py index f2a2ae5..54538cf 100644 --- a/socketio/zmq_manager.py +++ b/socketio/zmq_manager.py @@ -5,7 +5,6 @@ try: import eventlet.green.zmq as zmq except ImportError: zmq = None -import six from .pubsub_manager import PubSubManager @@ -98,7 +97,7 @@ class ZmqManager(PubSubManager): # pragma: no cover def _listen(self): for message in self.zmq_listen(): - if isinstance(message, six.binary_type): + if isinstance(message, bytes): try: message = pickle.loads(message) except Exception: diff --git a/tests/asyncio/test_asyncio_client.py b/tests/asyncio/test_asyncio_client.py index 590b4ea..2bbafc0 100644 --- a/tests/asyncio/test_asyncio_client.py +++ b/tests/asyncio/test_asyncio_client.py @@ -2,20 +2,15 @@ import asyncio from contextlib import contextmanager import sys import unittest +from unittest import mock -import six - -if six.PY3: - from unittest import mock -else: - import mock +import pytest from socketio import asyncio_client from socketio import asyncio_namespace from engineio import exceptions as engineio_exceptions from socketio import exceptions from socketio import packet -import pytest def AsyncMock(*args, **kwargs): @@ -371,6 +366,7 @@ class TestAsyncClient(unittest.TestCase): def test_call(self): c = asyncio_client.AsyncClient() c.namespaces = {'/': '1'} + async def fake_event_wait(): c._generate_ack_id.call_args_list[0][0][1]('foo', 321) diff --git a/tests/asyncio/test_asyncio_manager.py b/tests/asyncio/test_asyncio_manager.py index 66fe53a..d51ba47 100644 --- a/tests/asyncio/test_asyncio_manager.py +++ b/tests/asyncio/test_asyncio_manager.py @@ -1,13 +1,7 @@ import asyncio import sys import unittest - -import six - -if six.PY3: - from unittest import mock -else: - import mock +from unittest import mock from socketio import asyncio_manager diff --git a/tests/asyncio/test_asyncio_namespace.py b/tests/asyncio/test_asyncio_namespace.py index 2367838..b2ebfd0 100644 --- a/tests/asyncio/test_asyncio_namespace.py +++ b/tests/asyncio/test_asyncio_namespace.py @@ -1,13 +1,7 @@ import asyncio import sys import unittest - -import six - -if six.PY3: - from unittest import mock -else: - import mock +from unittest import mock from socketio import asyncio_namespace diff --git a/tests/asyncio/test_asyncio_pubsub_manager.py b/tests/asyncio/test_asyncio_pubsub_manager.py index 7ca06b4..f4a1375 100644 --- a/tests/asyncio/test_asyncio_pubsub_manager.py +++ b/tests/asyncio/test_asyncio_pubsub_manager.py @@ -2,17 +2,12 @@ import asyncio import functools import sys import unittest +from unittest import mock -import six - -if six.PY3: - from unittest import mock -else: - import mock +import pytest from socketio import asyncio_manager from socketio import asyncio_pubsub_manager -import pytest def AsyncMock(*args, **kwargs): diff --git a/tests/asyncio/test_asyncio_redis_manager.py b/tests/asyncio/test_asyncio_redis_manager.py index d79a59e..a8cf7d8 100644 --- a/tests/asyncio/test_asyncio_redis_manager.py +++ b/tests/asyncio/test_asyncio_redis_manager.py @@ -1,9 +1,10 @@ import sys import unittest -from socketio import asyncio_redis_manager import pytest +from socketio import asyncio_redis_manager + @unittest.skipIf(sys.version_info < (3, 5), 'only for Python 3.5+') class TestAsyncRedisManager(unittest.TestCase): diff --git a/tests/asyncio/test_asyncio_server.py b/tests/asyncio/test_asyncio_server.py index 545531f..254c944 100644 --- a/tests/asyncio/test_asyncio_server.py +++ b/tests/asyncio/test_asyncio_server.py @@ -3,20 +3,15 @@ import json import logging import sys import unittest +from unittest import mock -import six - -if six.PY3: - from unittest import mock -else: - import mock +import pytest from socketio import asyncio_server from socketio import asyncio_namespace from socketio import exceptions from socketio import namespace from socketio import packet -import pytest def AsyncMock(*args, **kwargs): @@ -912,7 +907,7 @@ class TestAsyncServer(unittest.TestCase): pkt = packet.Packet( packet_type=packet.EVENT, - data={six.text_type('foo'): six.text_type('bar')}, + data={'foo': 'bar'}, ) assert pkt.encode() == '2*** encoded ***' pkt2 = packet.Packet(encoded_packet=pkt.encode()) diff --git a/tests/common/test_base_manager.py b/tests/common/test_base_manager.py index 0bcba82..9518a46 100644 --- a/tests/common/test_base_manager.py +++ b/tests/common/test_base_manager.py @@ -1,11 +1,5 @@ import unittest - -import six - -if six.PY3: - from unittest import mock -else: - import mock +from unittest import mock from socketio import base_manager diff --git a/tests/common/test_client.py b/tests/common/test_client.py index 7e2a037..f7bee9a 100644 --- a/tests/common/test_client.py +++ b/tests/common/test_client.py @@ -2,26 +2,17 @@ import json import logging import sys import unittest - -import six - -if six.PY3: - from unittest import mock -else: - import mock +from unittest import mock from engineio import exceptions as engineio_exceptions from engineio import packet as engineio_packet +import pytest -if six.PY3: - from socketio import asyncio_namespace -else: - asyncio_namespace = None +from socketio import asyncio_namespace from socketio import client from socketio import exceptions from socketio import namespace from socketio import packet -import pytest class TestClient(unittest.TestCase): @@ -474,6 +465,7 @@ class TestClient(unittest.TestCase): def test_call(self): c = client.Client() c.namespaces = {'/': '1'} + def fake_event_wait(timeout=None): assert timeout == 60 c._generate_ack_id.call_args_list[0][0][1]('foo', 321) @@ -495,6 +487,7 @@ class TestClient(unittest.TestCase): def test_call_with_timeout(self): c = client.Client() c.namespaces = {'/': '1'} + def fake_event_wait(timeout=None): assert timeout == 12 return False diff --git a/tests/common/test_middleware.py b/tests/common/test_middleware.py index 2edf2f5..8611a04 100644 --- a/tests/common/test_middleware.py +++ b/tests/common/test_middleware.py @@ -1,11 +1,5 @@ import unittest - -import six - -if six.PY3: - from unittest import mock -else: - import mock +from unittest import mock from socketio import middleware diff --git a/tests/common/test_namespace.py b/tests/common/test_namespace.py index 3c10949..1478c97 100644 --- a/tests/common/test_namespace.py +++ b/tests/common/test_namespace.py @@ -1,10 +1,5 @@ import unittest -import six - -if six.PY3: - from unittest import mock -else: - import mock +from unittest import mock from socketio import namespace diff --git a/tests/common/test_packet.py b/tests/common/test_packet.py index 2f859cd..0623817 100644 --- a/tests/common/test_packet.py +++ b/tests/common/test_packet.py @@ -1,9 +1,8 @@ import unittest -import six +import pytest from socketio import packet -import pytest class TestPacket(unittest.TestCase): @@ -22,7 +21,7 @@ class TestPacket(unittest.TestCase): def test_encode_text_event_packet(self): pkt = packet.Packet( - packet_type=packet.EVENT, data=[six.text_type('foo')] + packet_type=packet.EVENT, data=['foo'] ) assert pkt.packet_type == packet.EVENT assert pkt.data == ['foo'] @@ -58,7 +57,7 @@ class TestPacket(unittest.TestCase): def test_encode_text_ack_packet(self): pkt = packet.Packet( - packet_type=packet.ACK, data=[six.text_type('foo')] + packet_type=packet.ACK, data=['foo'] ) assert pkt.packet_type == packet.ACK assert pkt.data == ['foo'] @@ -92,7 +91,7 @@ class TestPacket(unittest.TestCase): def test_encode_namespace(self): pkt = packet.Packet( packet_type=packet.EVENT, - data=[six.text_type('foo')], + data=['foo'], namespace='/bar', ) assert pkt.namespace == '/bar' @@ -122,7 +121,7 @@ class TestPacket(unittest.TestCase): def test_encode_namespace_with_hyphens(self): pkt = packet.Packet( packet_type=packet.EVENT, - data=[six.text_type('foo')], + data=['foo'], namespace='/b-a-r', ) assert pkt.namespace == '/b-a-r' @@ -135,7 +134,7 @@ class TestPacket(unittest.TestCase): def test_encode_event_with_hyphens(self): pkt = packet.Packet( - packet_type=packet.EVENT, data=[six.text_type('f-o-o')] + packet_type=packet.EVENT, data=['f-o-o'] ) assert pkt.namespace is None assert pkt.encode() == '2["f-o-o"]' @@ -147,7 +146,7 @@ class TestPacket(unittest.TestCase): def test_encode_id(self): pkt = packet.Packet( - packet_type=packet.EVENT, data=[six.text_type('foo')], id=123 + packet_type=packet.EVENT, data=['foo'], id=123 ) assert pkt.id == 123 assert pkt.encode() == '2123["foo"]' @@ -172,7 +171,7 @@ class TestPacket(unittest.TestCase): def test_encode_namespace_and_id(self): pkt = packet.Packet( packet_type=packet.EVENT, - data=[six.text_type('foo')], + data=['foo'], namespace='/bar', id=123, ) @@ -189,7 +188,7 @@ class TestPacket(unittest.TestCase): def test_encode_many_binary(self): pkt = packet.Packet( packet_type=packet.EVENT, - data={'a': six.text_type('123'), 'b': b'456', 'c': [b'789', 123]}, + data={'a': '123', 'b': b'456', 'c': [b'789', 123]}, ) assert pkt.packet_type == packet.BINARY_EVENT ep = pkt.encode() @@ -200,7 +199,7 @@ class TestPacket(unittest.TestCase): def test_encode_many_binary_ack(self): pkt = packet.Packet( packet_type=packet.ACK, - data={'a': six.text_type('123'), 'b': b'456', 'c': [b'789', 123]}, + data={'a': '123', 'b': b'456', 'c': [b'789', 123]}, ) assert pkt.packet_type == packet.BINARY_ACK ep = pkt.encode() @@ -250,14 +249,14 @@ class TestPacket(unittest.TestCase): def test_data_is_binary_list(self): pkt = packet.Packet() - assert not pkt._data_is_binary([six.text_type('foo')]) + assert not pkt._data_is_binary(['foo']) assert not pkt._data_is_binary([]) assert pkt._data_is_binary([b'foo']) - assert pkt._data_is_binary([six.text_type('foo'), b'bar']) + assert pkt._data_is_binary(['foo', b'bar']) def test_data_is_binary_dict(self): pkt = packet.Packet() - assert not pkt._data_is_binary({'a': six.text_type('foo')}) + assert not pkt._data_is_binary({'a': 'foo'}) assert not pkt._data_is_binary({}) assert pkt._data_is_binary({'a': b'foo'}) - assert pkt._data_is_binary({'a': six.text_type('foo'), 'b': b'bar'}) + assert pkt._data_is_binary({'a': 'foo', 'b': b'bar'}) diff --git a/tests/common/test_pubsub_manager.py b/tests/common/test_pubsub_manager.py index 3347e17..5a47612 100644 --- a/tests/common/test_pubsub_manager.py +++ b/tests/common/test_pubsub_manager.py @@ -1,17 +1,12 @@ import functools -import unittest import logging +import unittest +from unittest import mock -import six - -if six.PY3: - from unittest import mock -else: - import mock +import pytest from socketio import base_manager from socketio import pubsub_manager -import pytest class TestBaseManager(unittest.TestCase): diff --git a/tests/common/test_server.py b/tests/common/test_server.py index 4332cba..d8221e3 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -1,19 +1,14 @@ import json import logging import unittest +from unittest import mock -import six - -if six.PY3: - from unittest import mock -else: - import mock +import pytest from socketio import exceptions from socketio import namespace from socketio import packet from socketio import server -import pytest @mock.patch('socketio.server.engineio.Server', **{ @@ -790,7 +785,7 @@ class TestServer(unittest.TestCase): pkt = packet.Packet( packet_type=packet.EVENT, - data={six.text_type('foo'): six.text_type('bar')}, + data={'foo': 'bar'}, ) assert pkt.encode() == '2*** encoded ***' pkt2 = packet.Packet(encoded_packet=pkt.encode())