@@ -157,17 +157,8 @@ class ConnectionError(socket.error):
157157 """Class for errors communication with clamd"""
158158
159159
160- # Python 2/3 compatibility
161- try :
162- basestring # attempt to evaluate basestring
163-
164- def isstr (s ):
165- return isinstance (s , basestring )
166-
167- except NameError :
168-
169- def isstr (s ):
170- return isinstance (s , str )
160+ def isstr (s ):
161+ return isinstance (s , str )
171162
172163
173164############################################################################
@@ -311,9 +302,9 @@ def scan_file(self, file):
311302 - socket.timeout: if timeout has expired
312303 """
313304
314- assert isstr (
315- file
316- ), "Wrong type for [file], should be a string [was {0}]" . format ( type ( file ))
305+ assert isstr (file ), (
306+ "Wrong type for [ file], should be a string [was {0}]" . format ( type ( file ))
307+ )
317308
318309 try :
319310 self ._init_socket ()
@@ -359,9 +350,9 @@ def multiscan_file(self, file):
359350 May raise:
360351 - ConnectionError: in case of communication problem
361352 """
362- assert isstr (
363- file
364- ), "Wrong type for [file], should be a string [was {0}]" . format ( type ( file ))
353+ assert isstr (file ), (
354+ "Wrong type for [ file], should be a string [was {0}]" . format ( type ( file ))
355+ )
365356
366357 try :
367358 self ._init_socket ()
@@ -407,9 +398,9 @@ def allmatchscan(self, file):
407398 - ConnectionError: in case of communication problem
408399 - socket.timeout: if timeout has expired
409400 """
410- assert isstr (
411- file
412- ), "Wrong type for [file], should be a string [was {0}]" . format ( type ( file ))
401+ assert isstr (file ), (
402+ "Wrong type for [ file], should be a string [was {0}]" . format ( type ( file ))
403+ )
413404
414405 dr = {}
415406
@@ -469,9 +460,9 @@ def contscan_file(self, file):
469460 May raise:
470461 - ConnectionError: in case of communication problem
471462 """
472- assert isstr (
473- file
474- ), "Wrong type for [file], should be a string [was {0}]" . format ( type ( file ))
463+ assert isstr (file ), (
464+ "Wrong type for [ file], should be a string [was {0}]" . format ( type ( file ))
465+ )
475466
476467 try :
477468 self ._init_socket ()
@@ -521,17 +512,17 @@ def scan_stream(self, stream, chunk_size=4096):
521512 """
522513 if sys .version_info [0 ] <= 2 :
523514 # Python2
524- assert hasattr (stream , "read" ) or isinstance (
525- stream , str
526- ), "Wrong type for [stream], should be str/file-like [was {0}]" . format (
527- type ( stream )
515+ assert hasattr (stream , "read" ) or isinstance (stream , str ), (
516+ "Wrong type for [ stream], should be str/file-like [was {0}]" . format (
517+ type ( stream )
518+ )
528519 )
529520 else :
530521 # Python3
531- assert hasattr (stream , "read" ) or isinstance (
532- stream , ( bytes , bytearray )
533- ), "Wrong type for [stream], should be bytes/bytearray/file-like [was {0}]" . format (
534- type ( stream )
522+ assert hasattr (stream , "read" ) or isinstance (stream , ( bytes , bytearray )), (
523+ "Wrong type for [ stream], should be bytes/ bytearray/file-like [was {0}]" . format (
524+ type ( stream )
525+ )
535526 )
536527
537528 is_file_like = hasattr (stream , "read" )
@@ -580,7 +571,6 @@ def scan_stream(self, stream, chunk_size=4096):
580571 raise ConnectionError ("Unable to scan stream" )
581572
582573 if len (result ) > 0 :
583-
584574 if result == "INSTREAM size limit exceeded. ERROR" :
585575 raise BufferTooLongError (result )
586576
@@ -693,7 +683,11 @@ def __init__(self, filename=None, timeout=None):
693683
694684 # try to get unix socket from clamd.conf
695685 if filename is None :
696- for clamdpath in ["/etc/clamav/clamd.conf" , "/etc/clamd.conf" , "/opt/homebrew/etc/clamav/clamd.conf" ]:
686+ for clamdpath in [
687+ "/etc/clamav/clamd.conf" ,
688+ "/etc/clamd.conf" ,
689+ "/opt/homebrew/etc/clamav/clamd.conf" ,
690+ ]:
697691 if os .path .isfile (clamdpath ):
698692 break
699693 else :
@@ -715,13 +709,13 @@ def __init__(self, filename=None, timeout=None):
715709 "Could not find clamd unix socket from /etc/clamav/clamd.conf or /etc/clamd.conf"
716710 )
717711
718- assert isstr (
719- filename
720- ), "Wrong type for [file], should be a string [was {0}]" . format ( type ( file ))
721- assert (
722- isinstance ( timeout , ( float , int )) or timeout is None
723- ), "Wrong type for [timeout], should be either None or a float [was {0}]" . format (
724- type ( timeout )
712+ assert isstr (filename ), (
713+ "Wrong type for [file], should be a string [was {0}]" . format ( type ( filename ))
714+ )
715+ assert isinstance ( timeout , ( float , int )) or timeout is None , (
716+ "Wrong type for [ timeout], should be either None or a float [was {0}]" . format (
717+ type ( timeout )
718+ )
725719 )
726720
727721 _ClamdGeneric .__init__ (self )
@@ -740,7 +734,7 @@ def _init_socket(self):
740734 internal use only
741735 """
742736 self .clamd_socket = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
743- if not self .timeout is None :
737+ if self .timeout :
744738 self .clamd_socket .settimeout (self .timeout )
745739
746740 try :
@@ -770,16 +764,16 @@ def __init__(self, host="127.0.0.1", port=3310, timeout=None):
770764 timeout (float or None) : socket timeout
771765 """
772766
773- assert isinstance (
774- host , str
775- ), "Wrong type for [host], should be a string [was {0}]" . format ( type ( host ))
776- assert isinstance (
777- port , int
778- ), "Wrong type for [port], should be an int [was {0}]" . format ( type ( port ))
779- assert (
780- isinstance ( timeout , ( float , int )) or timeout is None
781- ), "Wrong type for [timeout], should be either None or a float [was {0}]" . format (
782- type ( timeout )
767+ assert isinstance (host , str ), (
768+ "Wrong type for [ host], should be a string [was {0}]" . format ( type ( host ))
769+ )
770+ assert isinstance (port , int ), (
771+ "Wrong type for [ port], should be an int [was {0}]" . format ( type ( port ))
772+ )
773+ assert isinstance ( timeout , ( float , int )) or timeout is None , (
774+ "Wrong type for [ timeout], should be either None or a float [was {0}]" . format (
775+ type ( timeout )
776+ )
783777 )
784778
785779 _ClamdGeneric .__init__ (self )
@@ -799,7 +793,7 @@ def _init_socket(self):
799793 internal use only
800794 """
801795 self .clamd_socket = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
802- if not self .timeout is None :
796+ if self .timeout :
803797 self .clamd_socket .settimeout (self .timeout )
804798 try :
805799 self .clamd_socket .connect ((self .host , self .port ))
@@ -920,7 +914,6 @@ def _print_doc():
920914
921915# MAIN -------------------
922916if __name__ == "__main__" :
923-
924917 _non_regression_test ()
925918
926919
0 commit comments