Browse Source

Remove dependency on the six package

pull/599/head
Miguel Grinberg 4 years ago
parent
commit
f6eeedb767
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 1
      setup.py
  2. 7
      socketio/asyncio_client.py
  3. 3
      socketio/asyncio_pubsub_manager.py
  4. 3
      socketio/asyncio_server.py
  5. 9
      socketio/base_manager.py
  6. 7
      socketio/client.py
  7. 18
      socketio/packet.py
  8. 3
      socketio/pubsub_manager.py
  9. 1
      socketio/server.py
  10. 3
      socketio/zmq_manager.py
  11. 10
      tests/asyncio/test_asyncio_client.py
  12. 8
      tests/asyncio/test_asyncio_manager.py
  13. 8
      tests/asyncio/test_asyncio_namespace.py
  14. 9
      tests/asyncio/test_asyncio_pubsub_manager.py
  15. 3
      tests/asyncio/test_asyncio_redis_manager.py
  16. 11
      tests/asyncio/test_asyncio_server.py
  17. 8
      tests/common/test_base_manager.py
  18. 17
      tests/common/test_client.py
  19. 8
      tests/common/test_middleware.py
  20. 7
      tests/common/test_namespace.py
  21. 29
      tests/common/test_packet.py
  22. 11
      tests/common/test_pubsub_manager.py
  23. 11
      tests/common/test_server.py

1
setup.py

@ -29,7 +29,6 @@ setup(
include_package_data=True, include_package_data=True,
platforms='any', platforms='any',
install_requires=[ install_requires=[
'six>=1.9.0',
'bidict>=0.21.0', 'bidict>=0.21.0',
'python-engineio>=3.13.0,<4' 'python-engineio>=3.13.0,<4'
], ],

7
socketio/asyncio_client.py

@ -3,7 +3,6 @@ import logging
import random import random
import engineio import engineio
import six
from . import client from . import client
from . import exceptions from . import exceptions
@ -100,7 +99,7 @@ class AsyncClient(client.Client):
set(self.namespace_handlers.keys()))) set(self.namespace_handlers.keys())))
if len(namespaces) == 0: if len(namespaces) == 0:
namespaces = ['/'] namespaces = ['/']
elif isinstance(namespaces, six.string_types): elif isinstance(namespaces, str):
namespaces = [namespaces] namespaces = [namespaces]
self.connection_namespaces = namespaces self.connection_namespaces = namespaces
try: try:
@ -111,7 +110,7 @@ class AsyncClient(client.Client):
await self._trigger_event( await self._trigger_event(
'connect_error', '/', 'connect_error', '/',
exc.args[1] if len(exc.args) > 1 else exc.args[0]) 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 self.connected = True
async def wait(self): async def wait(self):
@ -237,7 +236,7 @@ class AsyncClient(client.Client):
try: try:
await asyncio.wait_for(callback_event.wait(), timeout) await asyncio.wait_for(callback_event.wait(), timeout)
except asyncio.TimeoutError: except asyncio.TimeoutError:
six.raise_from(exceptions.TimeoutError(), None) raise exceptions.TimeoutError() from None
return callback_args[0] if len(callback_args[0]) > 1 \ return callback_args[0] if len(callback_args[0]) > 1 \
else callback_args[0][0] if len(callback_args[0]) == 1 \ else callback_args[0][0] if len(callback_args[0]) == 1 \
else None else None

3
socketio/asyncio_pubsub_manager.py

@ -3,7 +3,6 @@ import uuid
import json import json
import pickle import pickle
import six
from .asyncio_manager import AsyncManager from .asyncio_manager import AsyncManager
@ -157,7 +156,7 @@ class AsyncPubSubManager(AsyncManager):
if isinstance(message, dict): if isinstance(message, dict):
data = message data = message
else: else:
if isinstance(message, six.binary_type): # pragma: no cover if isinstance(message, bytes): # pragma: no cover
try: try:
data = pickle.loads(message) data = pickle.loads(message)
except: except:

3
socketio/asyncio_server.py

@ -1,7 +1,6 @@
import asyncio import asyncio
import engineio import engineio
import six
from . import asyncio_manager from . import asyncio_manager
from . import exceptions from . import exceptions
@ -228,7 +227,7 @@ class AsyncServer(server.Server):
try: try:
await asyncio.wait_for(callback_event.wait(), timeout) await asyncio.wait_for(callback_event.wait(), timeout)
except asyncio.TimeoutError: except asyncio.TimeoutError:
six.raise_from(exceptions.TimeoutError(), None) raise exceptions.TimeoutError() from None
return callback_args[0] if len(callback_args[0]) > 1 \ return callback_args[0] if len(callback_args[0]) > 1 \
else callback_args[0][0] if len(callback_args[0]) == 1 \ else callback_args[0][0] if len(callback_args[0]) == 1 \
else None else None

9
socketio/base_manager.py

@ -2,7 +2,6 @@ import itertools
import logging import logging
from bidict import bidict from bidict import bidict
import six
default_logger = logging.getLogger('socketio') default_logger = logging.getLogger('socketio')
@ -35,7 +34,7 @@ class BaseManager(object):
def get_namespaces(self): def get_namespaces(self):
"""Return an iterable with the active namespace names.""" """Return an iterable with the active namespace names."""
return six.iterkeys(self.rooms) return self.rooms.keys()
def get_participants(self, namespace, room): def get_participants(self, namespace, room):
"""Return an iterable with the active participants in a room.""" """Return an iterable with the active participants in a room."""
@ -83,7 +82,7 @@ class BaseManager(object):
if namespace not in self.rooms: if namespace not in self.rooms:
return return
rooms = [] 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: if sid in room:
rooms.append(room_name) rooms.append(room_name)
for room in rooms: for room in rooms:
@ -129,7 +128,7 @@ class BaseManager(object):
"""Return the rooms a client is in.""" """Return the rooms a client is in."""
r = [] r = []
try: 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: if room_name is not None and sid in room:
r.append(room_name) r.append(room_name)
except KeyError: except KeyError:
@ -169,7 +168,7 @@ class BaseManager(object):
"""Generate a unique identifier for an ACK packet.""" """Generate a unique identifier for an ACK packet."""
if sid not in self.callbacks: if sid not in self.callbacks:
self.callbacks[sid] = {0: itertools.count(1)} 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 self.callbacks[sid][id] = callback
return id return id

7
socketio/client.py

@ -5,7 +5,6 @@ import signal
import threading import threading
import engineio import engineio
import six
from . import exceptions from . import exceptions
from . import namespace from . import namespace
@ -268,7 +267,7 @@ class Client(object):
set(self.namespace_handlers.keys()))) set(self.namespace_handlers.keys())))
if len(namespaces) == 0: if len(namespaces) == 0:
namespaces = ['/'] namespaces = ['/']
elif isinstance(namespaces, six.string_types): elif isinstance(namespaces, str):
namespaces = [namespaces] namespaces = [namespaces]
self.connection_namespaces = namespaces self.connection_namespaces = namespaces
try: try:
@ -278,7 +277,7 @@ class Client(object):
self._trigger_event( self._trigger_event(
'connect_error', '/', 'connect_error', '/',
exc.args[1] if len(exc.args) > 1 else exc.args[0]) 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 self.connected = True
def wait(self): def wait(self):
@ -471,7 +470,7 @@ class Client(object):
namespace = namespace or '/' namespace = namespace or '/'
if namespace not in self.callbacks: if namespace not in self.callbacks:
self.callbacks[namespace] = {0: itertools.count(1)} 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 self.callbacks[namespace][id] = callback
return id return id

18
socketio/packet.py

@ -1,8 +1,6 @@
import functools import functools
import json as _json import json as _json
import six
(CONNECT, DISCONNECT, EVENT, ACK, CONNECT_ERROR, BINARY_EVENT, BINARY_ACK) = \ (CONNECT, DISCONNECT, EVENT, ACK, CONNECT_ERROR, BINARY_EVENT, BINARY_ACK) = \
(0, 1, 2, 3, 4, 5, 6) (0, 1, 2, 3, 4, 5, 6)
packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'CONNECT_ERROR', 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 of packets where the first is the original packet with placeholders for
the binary components and the remaining ones the binary attachments. 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: if self.packet_type == BINARY_EVENT or self.packet_type == BINARY_ACK:
data, attachments = self._deconstruct_binary(self.data) data, attachments = self._deconstruct_binary(self.data)
encoded_packet += six.text_type(len(attachments)) + '-' encoded_packet += str(len(attachments)) + '-'
else: else:
data = self.data data = self.data
attachments = None attachments = None
@ -64,7 +62,7 @@ class Packet(object):
if needs_comma: if needs_comma:
encoded_packet += ',' encoded_packet += ','
needs_comma = False needs_comma = False
encoded_packet += six.text_type(self.id) encoded_packet += str(self.id)
if data is not None: if data is not None:
if needs_comma: if needs_comma:
encoded_packet += ',' encoded_packet += ','
@ -139,7 +137,7 @@ class Packet(object):
else: else:
return {key: self._reconstruct_binary_internal(value, return {key: self._reconstruct_binary_internal(value,
attachments) attachments)
for key, value in six.iteritems(data)} for key, value in data.items()}
else: else:
return data return data
@ -150,7 +148,7 @@ class Packet(object):
return data, attachments return data, attachments
def _deconstruct_binary_internal(self, data, attachments): def _deconstruct_binary_internal(self, data, attachments):
if isinstance(data, six.binary_type): if isinstance(data, bytes):
attachments.append(data) attachments.append(data)
return {'_placeholder': True, 'num': len(attachments) - 1} return {'_placeholder': True, 'num': len(attachments) - 1}
elif isinstance(data, list): elif isinstance(data, list):
@ -158,13 +156,13 @@ class Packet(object):
for item in data] for item in data]
elif isinstance(data, dict): elif isinstance(data, dict):
return {key: self._deconstruct_binary_internal(value, attachments) return {key: self._deconstruct_binary_internal(value, attachments)
for key, value in six.iteritems(data)} for key, value in data.items()}
else: else:
return data return data
def _data_is_binary(self, data): def _data_is_binary(self, data):
"""Check if the data contains binary components.""" """Check if the data contains binary components."""
if isinstance(data, six.binary_type): if isinstance(data, bytes):
return True return True
elif isinstance(data, list): elif isinstance(data, list):
return functools.reduce( return functools.reduce(
@ -173,7 +171,7 @@ class Packet(object):
elif isinstance(data, dict): elif isinstance(data, dict):
return functools.reduce( return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item) lambda a, b: a or b, [self._data_is_binary(item)
for item in six.itervalues(data)], for item in data.values()],
False) False)
else: else:
return False return False

3
socketio/pubsub_manager.py

@ -3,7 +3,6 @@ import uuid
import json import json
import pickle import pickle
import six
from .base_manager import BaseManager from .base_manager import BaseManager
@ -148,7 +147,7 @@ class PubSubManager(BaseManager):
if isinstance(message, dict): if isinstance(message, dict):
data = message data = message
else: else:
if isinstance(message, six.binary_type): # pragma: no cover if isinstance(message, bytes): # pragma: no cover
try: try:
data = pickle.loads(message) data = pickle.loads(message)
except: except:

1
socketio/server.py

@ -1,7 +1,6 @@
import logging import logging
import engineio import engineio
import six
from . import base_manager from . import base_manager
from . import exceptions from . import exceptions

3
socketio/zmq_manager.py

@ -5,7 +5,6 @@ try:
import eventlet.green.zmq as zmq import eventlet.green.zmq as zmq
except ImportError: except ImportError:
zmq = None zmq = None
import six
from .pubsub_manager import PubSubManager from .pubsub_manager import PubSubManager
@ -98,7 +97,7 @@ class ZmqManager(PubSubManager): # pragma: no cover
def _listen(self): def _listen(self):
for message in self.zmq_listen(): for message in self.zmq_listen():
if isinstance(message, six.binary_type): if isinstance(message, bytes):
try: try:
message = pickle.loads(message) message = pickle.loads(message)
except Exception: except Exception:

10
tests/asyncio/test_asyncio_client.py

@ -2,20 +2,15 @@ import asyncio
from contextlib import contextmanager from contextlib import contextmanager
import sys import sys
import unittest import unittest
from unittest import mock
import six import pytest
if six.PY3:
from unittest import mock
else:
import mock
from socketio import asyncio_client from socketio import asyncio_client
from socketio import asyncio_namespace from socketio import asyncio_namespace
from engineio import exceptions as engineio_exceptions from engineio import exceptions as engineio_exceptions
from socketio import exceptions from socketio import exceptions
from socketio import packet from socketio import packet
import pytest
def AsyncMock(*args, **kwargs): def AsyncMock(*args, **kwargs):
@ -371,6 +366,7 @@ class TestAsyncClient(unittest.TestCase):
def test_call(self): def test_call(self):
c = asyncio_client.AsyncClient() c = asyncio_client.AsyncClient()
c.namespaces = {'/': '1'} c.namespaces = {'/': '1'}
async def fake_event_wait(): async def fake_event_wait():
c._generate_ack_id.call_args_list[0][0][1]('foo', 321) c._generate_ack_id.call_args_list[0][0][1]('foo', 321)

8
tests/asyncio/test_asyncio_manager.py

@ -1,13 +1,7 @@
import asyncio import asyncio
import sys import sys
import unittest import unittest
from unittest import mock
import six
if six.PY3:
from unittest import mock
else:
import mock
from socketio import asyncio_manager from socketio import asyncio_manager

8
tests/asyncio/test_asyncio_namespace.py

@ -1,13 +1,7 @@
import asyncio import asyncio
import sys import sys
import unittest import unittest
from unittest import mock
import six
if six.PY3:
from unittest import mock
else:
import mock
from socketio import asyncio_namespace from socketio import asyncio_namespace

9
tests/asyncio/test_asyncio_pubsub_manager.py

@ -2,17 +2,12 @@ import asyncio
import functools import functools
import sys import sys
import unittest import unittest
from unittest import mock
import six import pytest
if six.PY3:
from unittest import mock
else:
import mock
from socketio import asyncio_manager from socketio import asyncio_manager
from socketio import asyncio_pubsub_manager from socketio import asyncio_pubsub_manager
import pytest
def AsyncMock(*args, **kwargs): def AsyncMock(*args, **kwargs):

3
tests/asyncio/test_asyncio_redis_manager.py

@ -1,9 +1,10 @@
import sys import sys
import unittest import unittest
from socketio import asyncio_redis_manager
import pytest import pytest
from socketio import asyncio_redis_manager
@unittest.skipIf(sys.version_info < (3, 5), 'only for Python 3.5+') @unittest.skipIf(sys.version_info < (3, 5), 'only for Python 3.5+')
class TestAsyncRedisManager(unittest.TestCase): class TestAsyncRedisManager(unittest.TestCase):

11
tests/asyncio/test_asyncio_server.py

@ -3,20 +3,15 @@ import json
import logging import logging
import sys import sys
import unittest import unittest
from unittest import mock
import six import pytest
if six.PY3:
from unittest import mock
else:
import mock
from socketio import asyncio_server from socketio import asyncio_server
from socketio import asyncio_namespace from socketio import asyncio_namespace
from socketio import exceptions from socketio import exceptions
from socketio import namespace from socketio import namespace
from socketio import packet from socketio import packet
import pytest
def AsyncMock(*args, **kwargs): def AsyncMock(*args, **kwargs):
@ -912,7 +907,7 @@ class TestAsyncServer(unittest.TestCase):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.EVENT, packet_type=packet.EVENT,
data={six.text_type('foo'): six.text_type('bar')}, data={'foo': 'bar'},
) )
assert pkt.encode() == '2*** encoded ***' assert pkt.encode() == '2*** encoded ***'
pkt2 = packet.Packet(encoded_packet=pkt.encode()) pkt2 = packet.Packet(encoded_packet=pkt.encode())

8
tests/common/test_base_manager.py

@ -1,11 +1,5 @@
import unittest import unittest
from unittest import mock
import six
if six.PY3:
from unittest import mock
else:
import mock
from socketio import base_manager from socketio import base_manager

17
tests/common/test_client.py

@ -2,26 +2,17 @@ import json
import logging import logging
import sys import sys
import unittest import unittest
from unittest import mock
import six
if six.PY3:
from unittest import mock
else:
import mock
from engineio import exceptions as engineio_exceptions from engineio import exceptions as engineio_exceptions
from engineio import packet as engineio_packet from engineio import packet as engineio_packet
import pytest
if six.PY3: from socketio import asyncio_namespace
from socketio import asyncio_namespace
else:
asyncio_namespace = None
from socketio import client from socketio import client
from socketio import exceptions from socketio import exceptions
from socketio import namespace from socketio import namespace
from socketio import packet from socketio import packet
import pytest
class TestClient(unittest.TestCase): class TestClient(unittest.TestCase):
@ -474,6 +465,7 @@ class TestClient(unittest.TestCase):
def test_call(self): def test_call(self):
c = client.Client() c = client.Client()
c.namespaces = {'/': '1'} c.namespaces = {'/': '1'}
def fake_event_wait(timeout=None): def fake_event_wait(timeout=None):
assert timeout == 60 assert timeout == 60
c._generate_ack_id.call_args_list[0][0][1]('foo', 321) 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): def test_call_with_timeout(self):
c = client.Client() c = client.Client()
c.namespaces = {'/': '1'} c.namespaces = {'/': '1'}
def fake_event_wait(timeout=None): def fake_event_wait(timeout=None):
assert timeout == 12 assert timeout == 12
return False return False

8
tests/common/test_middleware.py

@ -1,11 +1,5 @@
import unittest import unittest
from unittest import mock
import six
if six.PY3:
from unittest import mock
else:
import mock
from socketio import middleware from socketio import middleware

7
tests/common/test_namespace.py

@ -1,10 +1,5 @@
import unittest import unittest
import six from unittest import mock
if six.PY3:
from unittest import mock
else:
import mock
from socketio import namespace from socketio import namespace

29
tests/common/test_packet.py

@ -1,9 +1,8 @@
import unittest import unittest
import six import pytest
from socketio import packet from socketio import packet
import pytest
class TestPacket(unittest.TestCase): class TestPacket(unittest.TestCase):
@ -22,7 +21,7 @@ class TestPacket(unittest.TestCase):
def test_encode_text_event_packet(self): def test_encode_text_event_packet(self):
pkt = packet.Packet( 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.packet_type == packet.EVENT
assert pkt.data == ['foo'] assert pkt.data == ['foo']
@ -58,7 +57,7 @@ class TestPacket(unittest.TestCase):
def test_encode_text_ack_packet(self): def test_encode_text_ack_packet(self):
pkt = packet.Packet( 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.packet_type == packet.ACK
assert pkt.data == ['foo'] assert pkt.data == ['foo']
@ -92,7 +91,7 @@ class TestPacket(unittest.TestCase):
def test_encode_namespace(self): def test_encode_namespace(self):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.EVENT, packet_type=packet.EVENT,
data=[six.text_type('foo')], data=['foo'],
namespace='/bar', namespace='/bar',
) )
assert pkt.namespace == '/bar' assert pkt.namespace == '/bar'
@ -122,7 +121,7 @@ class TestPacket(unittest.TestCase):
def test_encode_namespace_with_hyphens(self): def test_encode_namespace_with_hyphens(self):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.EVENT, packet_type=packet.EVENT,
data=[six.text_type('foo')], data=['foo'],
namespace='/b-a-r', namespace='/b-a-r',
) )
assert pkt.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): def test_encode_event_with_hyphens(self):
pkt = packet.Packet( 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.namespace is None
assert pkt.encode() == '2["f-o-o"]' assert pkt.encode() == '2["f-o-o"]'
@ -147,7 +146,7 @@ class TestPacket(unittest.TestCase):
def test_encode_id(self): def test_encode_id(self):
pkt = packet.Packet( 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.id == 123
assert pkt.encode() == '2123["foo"]' assert pkt.encode() == '2123["foo"]'
@ -172,7 +171,7 @@ class TestPacket(unittest.TestCase):
def test_encode_namespace_and_id(self): def test_encode_namespace_and_id(self):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.EVENT, packet_type=packet.EVENT,
data=[six.text_type('foo')], data=['foo'],
namespace='/bar', namespace='/bar',
id=123, id=123,
) )
@ -189,7 +188,7 @@ class TestPacket(unittest.TestCase):
def test_encode_many_binary(self): def test_encode_many_binary(self):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.EVENT, 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 assert pkt.packet_type == packet.BINARY_EVENT
ep = pkt.encode() ep = pkt.encode()
@ -200,7 +199,7 @@ class TestPacket(unittest.TestCase):
def test_encode_many_binary_ack(self): def test_encode_many_binary_ack(self):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.ACK, 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 assert pkt.packet_type == packet.BINARY_ACK
ep = pkt.encode() ep = pkt.encode()
@ -250,14 +249,14 @@ class TestPacket(unittest.TestCase):
def test_data_is_binary_list(self): def test_data_is_binary_list(self):
pkt = packet.Packet() 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 not pkt._data_is_binary([])
assert pkt._data_is_binary([b'foo']) 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): def test_data_is_binary_dict(self):
pkt = packet.Packet() 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 not pkt._data_is_binary({})
assert pkt._data_is_binary({'a': b'foo'}) 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'})

11
tests/common/test_pubsub_manager.py

@ -1,17 +1,12 @@
import functools import functools
import unittest
import logging import logging
import unittest
from unittest import mock
import six import pytest
if six.PY3:
from unittest import mock
else:
import mock
from socketio import base_manager from socketio import base_manager
from socketio import pubsub_manager from socketio import pubsub_manager
import pytest
class TestBaseManager(unittest.TestCase): class TestBaseManager(unittest.TestCase):

11
tests/common/test_server.py

@ -1,19 +1,14 @@
import json import json
import logging import logging
import unittest import unittest
from unittest import mock
import six import pytest
if six.PY3:
from unittest import mock
else:
import mock
from socketio import exceptions from socketio import exceptions
from socketio import namespace from socketio import namespace
from socketio import packet from socketio import packet
from socketio import server from socketio import server
import pytest
@mock.patch('socketio.server.engineio.Server', **{ @mock.patch('socketio.server.engineio.Server', **{
@ -790,7 +785,7 @@ class TestServer(unittest.TestCase):
pkt = packet.Packet( pkt = packet.Packet(
packet_type=packet.EVENT, packet_type=packet.EVENT,
data={six.text_type('foo'): six.text_type('bar')}, data={'foo': 'bar'},
) )
assert pkt.encode() == '2*** encoded ***' assert pkt.encode() == '2*** encoded ***'
pkt2 = packet.Packet(encoded_packet=pkt.encode()) pkt2 = packet.Packet(encoded_packet=pkt.encode())

Loading…
Cancel
Save