1
1
import functools
2
2
import json as _json
3
3
4
- import six
5
-
6
4
(CONNECT , DISCONNECT , EVENT , ACK , CONNECT_ERROR , BINARY_EVENT , BINARY_ACK ) = \
7
5
(0 , 1 , 2 , 3 , 4 , 5 , 6 )
8
6
packet_names = ['CONNECT' , 'DISCONNECT' , 'EVENT' , 'ACK' , 'CONNECT_ERROR' ,
@@ -49,10 +47,10 @@ def encode(self):
49
47
of packets where the first is the original packet with placeholders for
50
48
the binary components and the remaining ones the binary attachments.
51
49
"""
52
- encoded_packet = six . text_type (self .packet_type )
50
+ encoded_packet = str (self .packet_type )
53
51
if self .packet_type == BINARY_EVENT or self .packet_type == BINARY_ACK :
54
52
data , attachments = self ._deconstruct_binary (self .data )
55
- encoded_packet += six . text_type (len (attachments )) + '-'
53
+ encoded_packet += str (len (attachments )) + '-'
56
54
else :
57
55
data = self .data
58
56
attachments = None
@@ -64,7 +62,7 @@ def encode(self):
64
62
if needs_comma :
65
63
encoded_packet += ','
66
64
needs_comma = False
67
- encoded_packet += six . text_type (self .id )
65
+ encoded_packet += str (self .id )
68
66
if data is not None :
69
67
if needs_comma :
70
68
encoded_packet += ','
@@ -139,7 +137,7 @@ def _reconstruct_binary_internal(self, data, attachments):
139
137
else :
140
138
return {key : self ._reconstruct_binary_internal (value ,
141
139
attachments )
142
- for key , value in six . iteritems ( data )}
140
+ for key , value in data . items ( )}
143
141
else :
144
142
return data
145
143
@@ -150,21 +148,21 @@ def _deconstruct_binary(self, data):
150
148
return data , attachments
151
149
152
150
def _deconstruct_binary_internal (self , data , attachments ):
153
- if isinstance (data , six . binary_type ):
151
+ if isinstance (data , bytes ):
154
152
attachments .append (data )
155
153
return {'_placeholder' : True , 'num' : len (attachments ) - 1 }
156
154
elif isinstance (data , list ):
157
155
return [self ._deconstruct_binary_internal (item , attachments )
158
156
for item in data ]
159
157
elif isinstance (data , dict ):
160
158
return {key : self ._deconstruct_binary_internal (value , attachments )
161
- for key , value in six . iteritems ( data )}
159
+ for key , value in data . items ( )}
162
160
else :
163
161
return data
164
162
165
163
def _data_is_binary (self , data ):
166
164
"""Check if the data contains binary components."""
167
- if isinstance (data , six . binary_type ):
165
+ if isinstance (data , bytes ):
168
166
return True
169
167
elif isinstance (data , list ):
170
168
return functools .reduce (
@@ -173,7 +171,7 @@ def _data_is_binary(self, data):
173
171
elif isinstance (data , dict ):
174
172
return functools .reduce (
175
173
lambda a , b : a or b , [self ._data_is_binary (item )
176
- for item in six . itervalues ( data )],
174
+ for item in data . values ( )],
177
175
False )
178
176
else :
179
177
return False
0 commit comments