@@ -1333,7 +1333,10 @@ def isZipFile(filename):
13331333
13341334 checkFile (filename )
13351335
1336- return openFile (filename , "rb" , encoding = None ).read (len (ZIP_HEADER )) == ZIP_HEADER
1336+ with openFile (filename , "rb" , encoding = None ) as f :
1337+ header = f .read (len (ZIP_HEADER ))
1338+
1339+ return header == ZIP_HEADER
13371340
13381341def isDigit (value ):
13391342 """
@@ -2533,21 +2536,22 @@ def initCommonOutputs():
25332536 kb .commonOutputs = {}
25342537 key = None
25352538
2536- for line in openFile (paths .COMMON_OUTPUTS , 'r' ):
2537- if line .find ('#' ) != - 1 :
2538- line = line [:line .find ('#' )]
2539+ with openFile (paths .COMMON_OUTPUTS , 'r' ) as f :
2540+ for line in f :
2541+ if line .find ('#' ) != - 1 :
2542+ line = line [:line .find ('#' )]
25392543
2540- line = line .strip ()
2544+ line = line .strip ()
25412545
2542- if len (line ) > 1 :
2543- if line .startswith ('[' ) and line .endswith (']' ):
2544- key = line [1 :- 1 ]
2545- elif key :
2546- if key not in kb .commonOutputs :
2547- kb .commonOutputs [key ] = set ()
2546+ if len (line ) > 1 :
2547+ if line .startswith ('[' ) and line .endswith (']' ):
2548+ key = line [1 :- 1 ]
2549+ elif key :
2550+ if key not in kb .commonOutputs :
2551+ kb .commonOutputs [key ] = set ()
25482552
2549- if line not in kb .commonOutputs [key ]:
2550- kb .commonOutputs [key ].add (line )
2553+ if line not in kb .commonOutputs [key ]:
2554+ kb .commonOutputs [key ].add (line )
25512555
25522556def getFileItems (filename , commentPrefix = '#' , unicoded = True , lowercase = False , unique = False ):
25532557 """
@@ -5594,7 +5598,9 @@ def checkSums():
55945598 expected , filename = match .groups ()
55955599 filepath = os .path .join (paths .SQLMAP_ROOT_PATH , filename ).replace ('/' , os .path .sep )
55965600 checkFile (filepath )
5597- if not hashlib .sha256 (open (filepath , "rb" ).read ()).hexdigest () == expected :
5601+ with open (filepath , "rb" ) as f :
5602+ content = f .read ()
5603+ if not hashlib .sha256 (content ).hexdigest () == expected :
55985604 retVal &= False
55995605 break
56005606
0 commit comments