3434 except ImportError :
3535 sqlite = None
3636
37- try :
38- basestring
39- except NameError :
40- basestring = str
41-
42- PY3 = sys .version_info [0 ] >= 3
43-
4437
4538class StorageServer :
4639 def __init__ (self , table = None , timeout = 24 , instance = False ):
@@ -297,8 +290,7 @@ def _recv(self, sock):
297290 recv_buffer = sock .recv (self .network_buffer_size )
298291 idle = False
299292 i += 1
300- if PY3 :
301- recv_buffer = recv_buffer .decode ('utf-8' , 'ignore' )
293+ recv_buffer = recv_buffer .decode ('utf-8' , 'ignore' )
302294 self ._log (u"got data : " + str (i ) + u" - " + repr (idle ) + u" - " +
303295 str (len (data )) + u" + " + str (len (recv_buffer )) + u" | " +
304296 repr (recv_buffer )[len (recv_buffer ) - 5 :])
@@ -307,15 +299,13 @@ def _recv(self, sock):
307299 elif not idle :
308300 if data [len (data ) - 2 :] == "\r \n " :
309301 content = "COMPLETE\r \n " + (" " * (15 - len ("COMPLETE\r \n " )))
310- if PY3 :
311- content = content .encode ('utf-8' , 'ignore' )
302+ content = content .encode ('utf-8' , 'ignore' )
312303 sock .send (content )
313304 idle = True
314305 self ._log (u"sent COMPLETE " + str (i ))
315306 elif len (recv_buffer ) > 0 :
316307 content = "ACK\r \n " + (" " * (15 - len ("ACK\r \n " )))
317- if PY3 :
318- content = content .encode ('utf-8' , 'ignore' )
308+ content = content .encode ('utf-8' , 'ignore' )
319309 sock .send (content )
320310 idle = True
321311 self ._log (u"sent ACK " + str (i ))
@@ -351,8 +341,7 @@ def _send(self, sock, data):
351341 send_buffer = data [:self .network_buffer_size ]
352342 else :
353343 send_buffer = data + "\r \n "
354- if PY3 :
355- send_buffer = send_buffer .encode ('utf-8' , 'ignore' )
344+ send_buffer = send_buffer .encode ('utf-8' , 'ignore' )
356345 result = sock .send (send_buffer )
357346 i += 1
358347 idle = False
@@ -361,8 +350,7 @@ def _send(self, sock, data):
361350 status = ""
362351 while status .find ("COMPLETE\r \n " ) == - 1 and status .find ("ACK\r \n " ) == - 1 :
363352 status = sock .recv (15 )
364- if PY3 :
365- status = status .decode ('utf-8' , 'ignore' )
353+ status = status .decode ('utf-8' , 'ignore' )
366354 i -= 1
367355
368356 idle = True
@@ -543,35 +531,28 @@ def _generateKey(self, funct, *args):
543531 for key in sorted (params .keys ()):
544532 if key not in ["new_results_function" ]:
545533 val = params [key ]
546- if not isinstance (val , basestring ):
534+ if not isinstance (val , str ):
547535 val = str (val )
548- if PY3 :
549- if isinstance (key , str ):
550- key = key .encode ('utf-8' )
551- if isinstance (val , str ):
552- val = val .encode ('utf-8' )
553- key_val_pair = b"'%s'='%s'" % (key , val )
554- else :
555- key_val_pair = "'%s'='%s'" % (key , val )
536+ if isinstance (key , str ):
537+ key = key .encode ('utf-8' )
538+ if isinstance (val , str ):
539+ val = val .encode ('utf-8' )
540+ key_val_pair = b"'%s'='%s'" % (key , val )
556541 keyhash .update (key_val_pair )
557542 elif isinstance (params , list ):
558- if PY3 :
559- hash_list = []
560- for el in params :
561- if not isinstance (el , basestring ):
562- el = str (el )
563- if isinstance (el , str ):
564- el = el .encode ('utf-8' )
565- hash_list .append (el )
566- keyhash .update (b"," .join ([b"%s" % el for el in hash_list ]))
567- else :
568- keyhash .update ("," .join (["%s" % el for el in params ]))
543+ hash_list = []
544+ for el in params :
545+ if not isinstance (el , str ):
546+ el = str (el )
547+ if isinstance (el , str ):
548+ el = el .encode ('utf-8' )
549+ hash_list .append (el )
550+ keyhash .update (b"," .join ([b"%s" % el for el in hash_list ]))
569551 else :
570- if not isinstance (params , basestring ):
552+ if not isinstance (params , str ):
571553 params = str (params )
572- if PY3 :
573- if isinstance (params , str ):
574- params = params .encode ('utf-8' )
554+ if isinstance (params , str ):
555+ params = params .encode ('utf-8' )
575556 keyhash .update (params )
576557
577558 name += "|" + keyhash .hexdigest () + "|"
@@ -805,8 +786,6 @@ def _log(self, description):
805786def to_unicode (text ):
806787 if isinstance (text , bytes ):
807788 return text .decode ('utf-8' )
808- if sys .version_info [0 ] == 2 and isinstance (text , str ):
809- return text .decode ('utf-8' )
810789 return text
811790
812791
0 commit comments