11import functools
22import 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 )
86packet_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
0 commit comments