Skip to content

Commit f6eeedb

Browse files
Remove dependency on the six package
1 parent cc9b3e9 commit f6eeedb

23 files changed

+62
-133
lines changed

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
include_package_data=True,
3030
platforms='any',
3131
install_requires=[
32-
'six>=1.9.0',
3332
'bidict>=0.21.0',
3433
'python-engineio>=3.13.0,<4'
3534
],

socketio/asyncio_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import random
44

55
import engineio
6-
import six
76

87
from . import client
98
from . import exceptions
@@ -100,7 +99,7 @@ async def connect(self, url, headers={}, transports=None,
10099
set(self.namespace_handlers.keys())))
101100
if len(namespaces) == 0:
102101
namespaces = ['/']
103-
elif isinstance(namespaces, six.string_types):
102+
elif isinstance(namespaces, str):
104103
namespaces = [namespaces]
105104
self.connection_namespaces = namespaces
106105
try:
@@ -111,7 +110,7 @@ async def connect(self, url, headers={}, transports=None,
111110
await self._trigger_event(
112111
'connect_error', '/',
113112
exc.args[1] if len(exc.args) > 1 else exc.args[0])
114-
six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
113+
raise exceptions.ConnectionError(exc.args[0]) from None
115114
self.connected = True
116115

117116
async def wait(self):
@@ -237,7 +236,7 @@ def event_callback(*args):
237236
try:
238237
await asyncio.wait_for(callback_event.wait(), timeout)
239238
except asyncio.TimeoutError:
240-
six.raise_from(exceptions.TimeoutError(), None)
239+
raise exceptions.TimeoutError() from None
241240
return callback_args[0] if len(callback_args[0]) > 1 \
242241
else callback_args[0][0] if len(callback_args[0]) == 1 \
243242
else None

socketio/asyncio_pubsub_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import json
55
import pickle
6-
import six
76

87
from .asyncio_manager import AsyncManager
98

@@ -157,7 +156,7 @@ async def _thread(self):
157156
if isinstance(message, dict):
158157
data = message
159158
else:
160-
if isinstance(message, six.binary_type): # pragma: no cover
159+
if isinstance(message, bytes): # pragma: no cover
161160
try:
162161
data = pickle.loads(message)
163162
except:

socketio/asyncio_server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22

33
import engineio
4-
import six
54

65
from . import asyncio_manager
76
from . import exceptions
@@ -228,7 +227,7 @@ def event_callback(*args):
228227
try:
229228
await asyncio.wait_for(callback_event.wait(), timeout)
230229
except asyncio.TimeoutError:
231-
six.raise_from(exceptions.TimeoutError(), None)
230+
raise exceptions.TimeoutError() from None
232231
return callback_args[0] if len(callback_args[0]) > 1 \
233232
else callback_args[0][0] if len(callback_args[0]) == 1 \
234233
else None

socketio/base_manager.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33

44
from bidict import bidict
5-
import six
65

76
default_logger = logging.getLogger('socketio')
87

@@ -35,7 +34,7 @@ def initialize(self):
3534

3635
def get_namespaces(self):
3736
"""Return an iterable with the active namespace names."""
38-
return six.iterkeys(self.rooms)
37+
return self.rooms.keys()
3938

4039
def get_participants(self, namespace, room):
4140
"""Return an iterable with the active participants in a room."""
@@ -83,7 +82,7 @@ def disconnect(self, sid, namespace):
8382
if namespace not in self.rooms:
8483
return
8584
rooms = []
86-
for room_name, room in six.iteritems(self.rooms[namespace].copy()):
85+
for room_name, room in self.rooms[namespace].copy().items():
8786
if sid in room:
8887
rooms.append(room_name)
8988
for room in rooms:
@@ -129,7 +128,7 @@ def get_rooms(self, sid, namespace):
129128
"""Return the rooms a client is in."""
130129
r = []
131130
try:
132-
for room_name, room in six.iteritems(self.rooms[namespace]):
131+
for room_name, room in self.rooms[namespace].items():
133132
if room_name is not None and sid in room:
134133
r.append(room_name)
135134
except KeyError:
@@ -169,7 +168,7 @@ def _generate_ack_id(self, sid, callback):
169168
"""Generate a unique identifier for an ACK packet."""
170169
if sid not in self.callbacks:
171170
self.callbacks[sid] = {0: itertools.count(1)}
172-
id = six.next(self.callbacks[sid][0])
171+
id = next(self.callbacks[sid][0])
173172
self.callbacks[sid][id] = callback
174173
return id
175174

socketio/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import threading
66

77
import engineio
8-
import six
98

109
from . import exceptions
1110
from . import namespace
@@ -268,7 +267,7 @@ def connect(self, url, headers={}, transports=None,
268267
set(self.namespace_handlers.keys())))
269268
if len(namespaces) == 0:
270269
namespaces = ['/']
271-
elif isinstance(namespaces, six.string_types):
270+
elif isinstance(namespaces, str):
272271
namespaces = [namespaces]
273272
self.connection_namespaces = namespaces
274273
try:
@@ -278,7 +277,7 @@ def connect(self, url, headers={}, transports=None,
278277
self._trigger_event(
279278
'connect_error', '/',
280279
exc.args[1] if len(exc.args) > 1 else exc.args[0])
281-
six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
280+
raise exceptions.ConnectionError(exc.args[0]) from None
282281
self.connected = True
283282

284283
def wait(self):
@@ -471,7 +470,7 @@ def _generate_ack_id(self, namespace, callback):
471470
namespace = namespace or '/'
472471
if namespace not in self.callbacks:
473472
self.callbacks[namespace] = {0: itertools.count(1)}
474-
id = six.next(self.callbacks[namespace][0])
473+
id = next(self.callbacks[namespace][0])
475474
self.callbacks[namespace][id] = callback
476475
return id
477476

socketio/packet.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import functools
22
import json as _json
33

4-
import six
5-
64
(CONNECT, DISCONNECT, EVENT, ACK, CONNECT_ERROR, BINARY_EVENT, BINARY_ACK) = \
75
(0, 1, 2, 3, 4, 5, 6)
86
packet_names = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'CONNECT_ERROR',
@@ -49,10 +47,10 @@ def encode(self):
4947
of packets where the first is the original packet with placeholders for
5048
the binary components and the remaining ones the binary attachments.
5149
"""
52-
encoded_packet = six.text_type(self.packet_type)
50+
encoded_packet = str(self.packet_type)
5351
if self.packet_type == BINARY_EVENT or self.packet_type == BINARY_ACK:
5452
data, attachments = self._deconstruct_binary(self.data)
55-
encoded_packet += six.text_type(len(attachments)) + '-'
53+
encoded_packet += str(len(attachments)) + '-'
5654
else:
5755
data = self.data
5856
attachments = None
@@ -64,7 +62,7 @@ def encode(self):
6462
if needs_comma:
6563
encoded_packet += ','
6664
needs_comma = False
67-
encoded_packet += six.text_type(self.id)
65+
encoded_packet += str(self.id)
6866
if data is not None:
6967
if needs_comma:
7068
encoded_packet += ','
@@ -139,7 +137,7 @@ def _reconstruct_binary_internal(self, data, attachments):
139137
else:
140138
return {key: self._reconstruct_binary_internal(value,
141139
attachments)
142-
for key, value in six.iteritems(data)}
140+
for key, value in data.items()}
143141
else:
144142
return data
145143

@@ -150,21 +148,21 @@ def _deconstruct_binary(self, data):
150148
return data, attachments
151149

152150
def _deconstruct_binary_internal(self, data, attachments):
153-
if isinstance(data, six.binary_type):
151+
if isinstance(data, bytes):
154152
attachments.append(data)
155153
return {'_placeholder': True, 'num': len(attachments) - 1}
156154
elif isinstance(data, list):
157155
return [self._deconstruct_binary_internal(item, attachments)
158156
for item in data]
159157
elif isinstance(data, dict):
160158
return {key: self._deconstruct_binary_internal(value, attachments)
161-
for key, value in six.iteritems(data)}
159+
for key, value in data.items()}
162160
else:
163161
return data
164162

165163
def _data_is_binary(self, data):
166164
"""Check if the data contains binary components."""
167-
if isinstance(data, six.binary_type):
165+
if isinstance(data, bytes):
168166
return True
169167
elif isinstance(data, list):
170168
return functools.reduce(
@@ -173,7 +171,7 @@ def _data_is_binary(self, data):
173171
elif isinstance(data, dict):
174172
return functools.reduce(
175173
lambda a, b: a or b, [self._data_is_binary(item)
176-
for item in six.itervalues(data)],
174+
for item in data.values()],
177175
False)
178176
else:
179177
return False

socketio/pubsub_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import json
55
import pickle
6-
import six
76

87
from .base_manager import BaseManager
98

@@ -148,7 +147,7 @@ def _thread(self):
148147
if isinstance(message, dict):
149148
data = message
150149
else:
151-
if isinstance(message, six.binary_type): # pragma: no cover
150+
if isinstance(message, bytes): # pragma: no cover
152151
try:
153152
data = pickle.loads(message)
154153
except:

socketio/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
import engineio
4-
import six
54

65
from . import base_manager
76
from . import exceptions

socketio/zmq_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import eventlet.green.zmq as zmq
66
except ImportError:
77
zmq = None
8-
import six
98

109
from .pubsub_manager import PubSubManager
1110

@@ -98,7 +97,7 @@ def zmq_listen(self):
9897

9998
def _listen(self):
10099
for message in self.zmq_listen():
101-
if isinstance(message, six.binary_type):
100+
if isinstance(message, bytes):
102101
try:
103102
message = pickle.loads(message)
104103
except Exception:

0 commit comments

Comments
 (0)