2020import errno
2121import os
2222
23- from six .moves import StringIO
23+ import six
24+ from six import BytesIO
2425
2526from socket import error as socket_error
2627
@@ -57,28 +58,28 @@ def make_connection(self):
5758 return c
5859
5960 def make_header_prefix (self , message_class , version = 2 , stream_id = 0 ):
60- return '' .join (map (uint8_pack , [
61+ return six . binary_type () .join (map (uint8_pack , [
6162 0xff & (HEADER_DIRECTION_TO_CLIENT | version ),
6263 0 , # flags (compression)
6364 stream_id ,
6465 message_class .opcode # opcode
6566 ]))
6667
6768 def make_options_body (self ):
68- options_buf = StringIO ()
69+ options_buf = BytesIO ()
6970 write_stringmultimap (options_buf , {
7071 'CQL_VERSION' : ['3.0.1' ],
7172 'COMPRESSION' : []
7273 })
7374 return options_buf .getvalue ()
7475
7576 def make_error_body (self , code , msg ):
76- buf = StringIO ()
77+ buf = BytesIO ()
7778 write_int (buf , code )
7879 write_string (buf , msg )
7980 return buf .getvalue ()
8081
81- def make_msg (self , header , body = "" ):
82+ def make_msg (self , header , body = six . binary_type () ):
8283 return header + uint32_pack (len (body )) + body
8384
8485 def test_successful_connection (self , * args ):
@@ -107,12 +108,12 @@ def test_egain_on_buffer_size(self, *args):
107108 # get a connection that's already fully started
108109 c = self .test_successful_connection ()
109110
110- header = '\x00 \x00 \x00 \x00 ' + int32_pack (20000 )
111+ header = six . b ( '\x00 \x00 \x00 \x00 ' ) + int32_pack (20000 )
111112 responses = [
112- header + ('a' * (4096 - len (header ))),
113- 'a' * 4096 ,
113+ header + (six . b ( 'a' ) * (4096 - len (header ))),
114+ six . b ( 'a' ) * 4096 ,
114115 socket_error (errno .EAGAIN ),
115- 'a' * 100 ,
116+ six . b ( 'a' ) * 100 ,
116117 socket_error (errno .EAGAIN )]
117118
118119 def side_effect (* args ):
@@ -240,13 +241,13 @@ def test_partial_header_read(self, *args):
240241 message = self .make_msg (header , options )
241242
242243 # read in the first byte
243- c ._socket .recv .return_value = message [0 ]
244+ c ._socket .recv .return_value = message [0 : 1 ]
244245 c .handle_read (None , 0 )
245- self .assertEqual (c ._iobuf .getvalue (), message [0 ])
246+ self .assertEqual (c ._iobuf .getvalue (), message [0 : 1 ])
246247
247248 c ._socket .recv .return_value = message [1 :]
248249 c .handle_read (None , 0 )
249- self .assertEqual ("" , c ._iobuf .getvalue ())
250+ self .assertEqual (six . binary_type () , c ._iobuf .getvalue ())
250251
251252 # let it write out a StartupMessage
252253 c .handle_write (None , 0 )
@@ -273,7 +274,7 @@ def test_partial_message_read(self, *args):
273274 # ... then read in the rest
274275 c ._socket .recv .return_value = message [9 :]
275276 c .handle_read (None , 0 )
276- self .assertEqual ("" , c ._iobuf .getvalue ())
277+ self .assertEqual (six . binary_type () , c ._iobuf .getvalue ())
277278
278279 # let it write out a StartupMessage
279280 c .handle_write (None , 0 )
0 commit comments