Skip to content

Commit 7672b9a

Browse files
committed
Baby steps (2 to 3 at a time)
1 parent 17b79cd commit 7672b9a

36 files changed

+139
-139
lines changed

extra/icmpsh/icmpsh_m.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def main(src, dst):
128128
try:
129129
# Send it to the target host
130130
sock.sendto(ip.get_packet(), (dst, 0))
131-
except socket.error, ex:
131+
except socket.error as ex:
132132
sys.stderr.write("'%s'\n" % ex)
133133
sys.stderr.flush()
134134

extra/wafdetectify/wafdetectify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_page(get=None, url=None, host=None, data=None):
4848
conn = urllib2.urlopen(req, timeout=TIMEOUT)
4949
page = conn.read()
5050
headers = conn.info()
51-
except Exception, ex:
51+
except Exception as ex:
5252
code = getattr(ex, "code", None)
5353
page = ex.read() if hasattr(ex, "read") else getattr(ex, "msg", "")
5454
headers = ex.info() if hasattr(ex, "info") else {}

lib/controller/action.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ def action():
7575
if conf.getPasswordHashes:
7676
try:
7777
conf.dumper.userSettings("database management system users password hashes", conf.dbmsHandler.getPasswordHashes(), "password hash", CONTENT_TYPE.PASSWORDS)
78-
except SqlmapNoneDataException, ex:
78+
except SqlmapNoneDataException as ex:
7979
logger.critical(ex)
8080
except:
8181
raise
8282

8383
if conf.getPrivileges:
8484
try:
8585
conf.dumper.userSettings("database management system users privileges", conf.dbmsHandler.getPrivileges(), "privilege", CONTENT_TYPE.PRIVILEGES)
86-
except SqlmapNoneDataException, ex:
86+
except SqlmapNoneDataException as ex:
8787
logger.critical(ex)
8888
except:
8989
raise
9090

9191
if conf.getRoles:
9292
try:
9393
conf.dumper.userSettings("database management system users roles", conf.dbmsHandler.getRoles(), "role", CONTENT_TYPE.ROLES)
94-
except SqlmapNoneDataException, ex:
94+
except SqlmapNoneDataException as ex:
9595
logger.critical(ex)
9696
except:
9797
raise

lib/controller/checks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ def _(*args, **kwargs):
14401440
try:
14411441
logger.debug("checking for WAF/IPS product '%s'" % product)
14421442
found = function(_)
1443-
except Exception, ex:
1443+
except Exception as ex:
14441444
errMsg = "exception occurred while running "
14451445
errMsg += "WAF script for '%s' ('%s')" % (product, getSafeExString(ex))
14461446
logger.critical(errMsg)
@@ -1543,11 +1543,11 @@ def checkConnection(suppressOutput=False):
15431543
except socket.gaierror:
15441544
errMsg = "host '%s' does not exist" % conf.hostname
15451545
raise SqlmapConnectionException(errMsg)
1546-
except socket.error, ex:
1546+
except socket.error as ex:
15471547
errMsg = "problem occurred while "
15481548
errMsg += "resolving a host name '%s' ('%s')" % (conf.hostname, getSafeExString(ex))
15491549
raise SqlmapConnectionException(errMsg)
1550-
except UnicodeError, ex:
1550+
except UnicodeError as ex:
15511551
errMsg = "problem occurred while "
15521552
errMsg += "handling a host name '%s' ('%s')" % (conf.hostname, getSafeExString(ex))
15531553
raise SqlmapDataException(errMsg)
@@ -1591,7 +1591,7 @@ def checkConnection(suppressOutput=False):
15911591
port = match.group(1) if match else 443
15921592
conf.url = re.sub(r":\d+(/|\Z)", ":%s\g<1>" % port, conf.url)
15931593

1594-
except SqlmapConnectionException, ex:
1594+
except SqlmapConnectionException as ex:
15951595
if conf.ipv6:
15961596
warnMsg = "check connection to a provided "
15971597
warnMsg += "IPv6 address with a tool like ping6 "

lib/controller/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _saveToResultsFile():
257257
conf.resultsFP.write(line)
258258

259259
conf.resultsFP.flush()
260-
except IOError, ex:
260+
except IOError as ex:
261261
errMsg = "unable to write to the results file '%s' ('%s'). " % (conf.resultsFilename, getSafeExString(ex))
262262
raise SqlmapSystemException(errMsg)
263263

@@ -689,7 +689,7 @@ def start():
689689
except SqlmapSilentQuitException:
690690
raise
691691

692-
except SqlmapBaseException, ex:
692+
except SqlmapBaseException as ex:
693693
errMsg = getSafeExString(ex)
694694

695695
if conf.multipleTargets:

lib/controller/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def setHandler():
105105

106106
if sqlalchemy.connector:
107107
conf.dbmsConnector = sqlalchemy
108-
except Exception, ex:
108+
except Exception as ex:
109109
exception = ex
110110

111111
if not dialect or exception:
112112
try:
113113
conf.dbmsConnector.connect()
114-
except Exception, ex:
114+
except Exception as ex:
115115
if exception:
116116
raise exception
117117
else:

lib/core/bigarray.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def pop(self):
8787
try:
8888
with open(self.chunks[-1], "rb") as f:
8989
self.chunks[-1] = pickle.loads(bz2.decompress(f.read()))
90-
except IOError, ex:
90+
except IOError as ex:
9191
errMsg = "exception occurred while retrieving data "
9292
errMsg += "from a temporary file ('%s')" % ex.message
9393
raise SqlmapSystemException(errMsg)
@@ -109,7 +109,7 @@ def _dump(self, chunk):
109109
with open(filename, "w+b") as f:
110110
f.write(bz2.compress(pickle.dumps(chunk, pickle.HIGHEST_PROTOCOL), BIGARRAY_COMPRESS_LEVEL))
111111
return filename
112-
except (OSError, IOError), ex:
112+
except (OSError, IOError) as ex:
113113
errMsg = "exception occurred while storing data "
114114
errMsg += "to a temporary file ('%s'). Please " % ex.message
115115
errMsg += "make sure that there is enough disk space left. If problem persists, "
@@ -126,7 +126,7 @@ def _checkcache(self, index):
126126
try:
127127
with open(self.chunks[index], "rb") as f:
128128
self.cache = Cache(index, pickle.loads(bz2.decompress(f.read())), False)
129-
except Exception, ex:
129+
except Exception as ex:
130130
errMsg = "exception occurred while retrieving data "
131131
errMsg += "from a temporary file ('%s')" % ex.message
132132
raise SqlmapSystemException(errMsg)

lib/core/common.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def dataToTrafficFile(data):
943943
try:
944944
conf.trafficFP.write(data)
945945
conf.trafficFP.flush()
946-
except IOError, ex:
946+
except IOError as ex:
947947
errMsg = "something went wrong while trying "
948948
errMsg += "to write to the traffic file '%s' ('%s')" % (conf.trafficFile, getSafeExString(ex))
949949
raise SqlmapSystemException(errMsg)
@@ -952,7 +952,7 @@ def dataToDumpFile(dumpFile, data):
952952
try:
953953
dumpFile.write(data)
954954
dumpFile.flush()
955-
except IOError, ex:
955+
except IOError as ex:
956956
if "No space left" in getUnicode(ex):
957957
errMsg = "no space left on output device"
958958
logger.error(errMsg)
@@ -972,15 +972,15 @@ def dataToOutFile(filename, data):
972972
try:
973973
with open(retVal, "w+b") as f: # has to stay as non-codecs because data is raw ASCII encoded data
974974
f.write(unicodeencode(data))
975-
except UnicodeEncodeError, ex:
975+
except UnicodeEncodeError as ex:
976976
_ = normalizeUnicode(filename)
977977
if filename != _:
978978
filename = _
979979
else:
980980
errMsg = "couldn't write to the "
981981
errMsg += "output file ('%s')" % getSafeExString(ex)
982982
raise SqlmapGenericException(errMsg)
983-
except IOError, ex:
983+
except IOError as ex:
984984
errMsg = "something went wrong while trying to write "
985985
errMsg += "to the output file ('%s')" % getSafeExString(ex)
986986
raise SqlmapGenericException(errMsg)
@@ -1446,7 +1446,7 @@ def parseTargetUrl():
14461446

14471447
try:
14481448
urlSplit = urlparse.urlsplit(conf.url)
1449-
except ValueError, ex:
1449+
except ValueError as ex:
14501450
errMsg = "invalid URL '%s' has been given ('%s'). " % (conf.url, getSafeExString(ex))
14511451
errMsg += "Please be sure that you don't have any leftover characters (e.g. '[' or ']') "
14521452
errMsg += "in the hostname part"
@@ -2038,7 +2038,7 @@ def parseXmlFile(xmlFile, handler):
20382038
try:
20392039
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
20402040
parse(stream, handler)
2041-
except (SAXParseException, UnicodeError), ex:
2041+
except (SAXParseException, UnicodeError) as ex:
20422042
errMsg = "something appears to be wrong with "
20432043
errMsg += "the file '%s' ('%s'). Please make " % (xmlFile, getSafeExString(ex))
20442044
errMsg += "sure that you haven't made any changes to it"
@@ -2104,7 +2104,7 @@ def readCachedFileContent(filename, mode="rb"):
21042104
try:
21052105
with openFile(filename, mode) as f:
21062106
kb.cache.content[filename] = f.read()
2107-
except (IOError, OSError, MemoryError), ex:
2107+
except (IOError, OSError, MemoryError) as ex:
21082108
errMsg = "something went wrong while trying "
21092109
errMsg += "to read the content of file '%s' ('%s')" % (filename, getSafeExString(ex))
21102110
raise SqlmapSystemException(errMsg)
@@ -2218,7 +2218,7 @@ def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, un
22182218
retVal[line] = True
22192219
else:
22202220
retVal.append(line)
2221-
except (IOError, OSError, MemoryError), ex:
2221+
except (IOError, OSError, MemoryError) as ex:
22222222
errMsg = "something went wrong while trying "
22232223
errMsg += "to read the content of file '%s' ('%s')" % (filename, getSafeExString(ex))
22242224
raise SqlmapSystemException(errMsg)
@@ -2351,7 +2351,7 @@ def getUnicode(value, encoding=None, noneToNull=False):
23512351
while True:
23522352
try:
23532353
return unicode(value, encoding or (kb.get("pageEncoding") if kb.get("originalPage") else None) or UNICODE_ENCODING)
2354-
except UnicodeDecodeError, ex:
2354+
except UnicodeDecodeError as ex:
23552355
try:
23562356
return unicode(value, UNICODE_ENCODING)
23572357
except:
@@ -2407,7 +2407,7 @@ def pushValue(value):
24072407
getCurrentThreadData().valueStack.append(copy.deepcopy(value))
24082408
success = True
24092409
break
2410-
except Exception, ex:
2410+
except Exception as ex:
24112411
_ = ex
24122412

24132413
if not success:
@@ -3095,7 +3095,7 @@ def saveConfig(conf, filename):
30953095
with openFile(filename, "wb") as f:
30963096
try:
30973097
config.write(f)
3098-
except IOError, ex:
3098+
except IOError as ex:
30993099
errMsg = "something went wrong while trying "
31003100
errMsg += "to write to the configuration file '%s' ('%s')" % (filename, getSafeExString(ex))
31013101
raise SqlmapSystemException(errMsg)
@@ -3442,7 +3442,7 @@ def createGithubIssue(errMsg, excMsg):
34423442

34433443
try:
34443444
content = urllib2.urlopen(req).read()
3445-
except Exception, ex:
3445+
except Exception as ex:
34463446
content = None
34473447

34483448
issueUrl = re.search(r"https://github.com/sqlmapproject/sqlmap/issues/\d+", content or "")
@@ -4063,7 +4063,7 @@ def geturl(self):
40634063
continue
40644064

40654065
request = form.click()
4066-
except (ValueError, TypeError), ex:
4066+
except (ValueError, TypeError) as ex:
40674067
errMsg = "there has been a problem while "
40684068
errMsg += "processing page forms ('%s')" % getSafeExString(ex)
40694069
if raise_:
@@ -4193,7 +4193,7 @@ def evaluateCode(code, variables=None):
41934193
exec(code, variables)
41944194
except KeyboardInterrupt:
41954195
raise
4196-
except Exception, ex:
4196+
except Exception as ex:
41974197
errMsg = "an error occurred while evaluating provided code ('%s') " % getSafeExString(ex)
41984198
raise SqlmapGenericException(errMsg)
41994199

@@ -4715,7 +4715,7 @@ def _parseBurpLog(content):
47154715
try:
47164716
with openFile(reqFile, "rb") as f:
47174717
content = f.read()
4718-
except (IOError, OSError, MemoryError), ex:
4718+
except (IOError, OSError, MemoryError) as ex:
47194719
errMsg = "something went wrong while trying "
47204720
errMsg += "to read the content of file '%s' ('%s')" % (reqFile, getSafeExString(ex))
47214721
raise SqlmapSystemException(errMsg)

lib/core/dump.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _write(self, data, newline=True, console=True, content_type=None):
7979

8080
try:
8181
self._outputFP.write(text)
82-
except IOError, ex:
82+
except IOError as ex:
8383
errMsg = "error occurred while writing to log file ('%s')" % getSafeExString(ex)
8484
raise SqlmapGenericException(errMsg)
8585

@@ -99,7 +99,7 @@ def setOutputFile(self):
9999
self._outputFile = os.path.join(conf.outputPath, "log")
100100
try:
101101
self._outputFP = openFile(self._outputFile, "ab" if not conf.flushSession else "wb")
102-
except IOError, ex:
102+
except IOError as ex:
103103
errMsg = "error occurred while opening log file ('%s')" % getSafeExString(ex)
104104
raise SqlmapGenericException(errMsg)
105105

@@ -426,7 +426,7 @@ def dbTableValues(self, tableValues):
426426
if not os.path.isdir(dumpDbPath):
427427
try:
428428
os.makedirs(dumpDbPath)
429-
except Exception, ex:
429+
except Exception as ex:
430430
try:
431431
tempDir = tempfile.mkdtemp(prefix="sqlmapdb")
432432
except IOError, _:

0 commit comments

Comments
 (0)