@@ -299,7 +299,7 @@ def _try_handshake(self):
299
299
return False
300
300
301
301
def _try_authenticate (self ):
302
- assert self .config ['api_version' ] >= ( 0 , 10 ) or self .config ['api_version' ] is None
302
+ assert self .config ['api_version' ] is None or self .config ['api_version' ] >= ( 0 , 10 )
303
303
304
304
if self ._sasl_auth_future is None :
305
305
# Build a SaslHandShakeRequest message
@@ -311,7 +311,7 @@ def _try_authenticate(self):
311
311
self ._sasl_auth_future = future
312
312
self ._recv ()
313
313
if self ._sasl_auth_future .failed ():
314
- raise self ._sasl_auth_future .exception
314
+ raise self ._sasl_auth_future .exception # pylint: disable-msg=raising-bad-type
315
315
return self ._sasl_auth_future .succeeded ()
316
316
317
317
def _handle_sasl_handshake_response (self , future , response ):
@@ -345,25 +345,24 @@ def _try_authenticate_plain(self, future):
345
345
346
346
# The server will send a zero sized message (that is Int32(0)) on success.
347
347
# The connection is closed on failure
348
- received_bytes = 0
349
- while received_bytes < 4 :
350
- data += self ._sock .recv (4 - received_bytes )
351
- received_bytes += len (data )
352
- if not data :
348
+ while len (data ) < 4 :
349
+ fragment = self ._sock .recv (4 - len (data ))
350
+ if not fragment :
353
351
log .error ('%s: Authentication failed for user %s' , self , self .config ['sasl_plain_username' ])
354
352
error = Errors .AuthenticationFailedError (
355
353
'Authentication failed for user {0}' .format (
356
354
self .config ['sasl_plain_username' ]))
357
355
future .failure (error )
358
356
raise error
357
+ data += fragment
359
358
self ._sock .setblocking (False )
360
359
except (AssertionError , ConnectionError ) as e :
361
360
log .exception ("%s: Error receiving reply from server" , self )
362
361
error = Errors .ConnectionError ("%s: %s" % (str (self ), e ))
363
362
future .failure (error )
364
363
self .close (error = error )
365
364
366
- if data != '\x00 \x00 \x00 \x00 ' :
365
+ if data != b '\x00 \x00 \x00 \x00 ' :
367
366
return future .failure (Errors .AuthenticationFailedError ())
368
367
369
368
return future .success (True )
0 commit comments