From 1b03ce2a3c36df3e1f040924e5dfad82e366afa2 Mon Sep 17 00:00:00 2001 From: akun <6awkun@gmail.com> Date: Thu, 1 Feb 2018 22:41:50 +0800 Subject: [PATCH] Refactoring for Python 3 `raise` * 2to3 `ls | grep -v thirdparty` -f raise --- lib/core/bigarray.py | 6 +++--- lib/core/common.py | 2 +- lib/core/convert.py | 2 +- lib/core/option.py | 12 ++++++------ lib/core/wordlist.py | 4 ++-- lib/parse/cmdline.py | 2 +- lib/parse/payloads.py | 4 ++-- lib/parse/sitemap.py | 2 +- lib/request/connect.py | 2 +- lib/utils/api.py | 2 +- lib/utils/hashdb.py | 2 +- lib/utils/sqlalchemy.py | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/core/bigarray.py b/lib/core/bigarray.py index 005be9d35..db549cb47 100644 --- a/lib/core/bigarray.py +++ b/lib/core/bigarray.py @@ -90,7 +90,7 @@ class BigArray(list): except IOError as ex: errMsg = "exception occurred while retrieving data " errMsg += "from a temporary file ('%s')" % ex.message - raise SqlmapSystemException, errMsg + raise SqlmapSystemException(errMsg) return self.chunks[-1].pop() @@ -115,7 +115,7 @@ class BigArray(list): errMsg += "make sure that there is enough disk space left. If problem persists, " errMsg += "try to set environment variable 'TEMP' to a location " errMsg += "writeable by the current user" - raise SqlmapSystemException, errMsg + raise SqlmapSystemException(errMsg) def _checkcache(self, index): if (self.cache and self.cache.index != index and self.cache.dirty): @@ -129,7 +129,7 @@ class BigArray(list): except IOError as ex: errMsg = "exception occurred while retrieving data " errMsg += "from a temporary file ('%s')" % ex.message - raise SqlmapSystemException, errMsg + raise SqlmapSystemException(errMsg) def __getstate__(self): return self.chunks, self.filenames diff --git a/lib/core/common.py b/lib/core/common.py index fc4766bc6..3be821a2b 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -2005,7 +2005,7 @@ def parseXmlFile(xmlFile, handler): errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (xmlFile, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" - raise SqlmapInstallationException, errMsg + raise SqlmapInstallationException(errMsg) def getSQLSnippet(dbms, sfile, **variables): """ diff --git a/lib/core/convert.py b/lib/core/convert.py index 5a5701c23..c8ebaa0b3 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -80,7 +80,7 @@ def base64unpickle(value, unsafe=False): if len(self.stack) > 1: func = self.stack[-2] if func not in PICKLE_REDUCE_WHITELIST: - raise Exception, "abusing reduce() is bad, Mkay!" + raise Exception("abusing reduce() is bad, Mkay!") self.load_reduce() def loads(str): diff --git a/lib/core/option.py b/lib/core/option.py index c4e8e5051..f8254914f 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -337,7 +337,7 @@ def _feedTargetsDict(reqFile, addedTargetUrls): if not host: errMsg = "invalid format of a request file" - raise SqlmapSyntaxException, errMsg + raise SqlmapSyntaxException(errMsg) if not url.startswith("http"): url = "%s://%s:%s%s" % (scheme or "http", host, port or "80", url) @@ -402,7 +402,7 @@ def _loadQueries(): errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (paths.QUERIES_XML, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" - raise SqlmapInstallationException, errMsg + raise SqlmapInstallationException(errMsg) for node in tree.findall("*"): queries[node.attrib['value']] = iterate(node) @@ -1128,7 +1128,7 @@ def _setHTTPHandlers(): _ = urlparse.urlsplit(conf.proxy) except Exception as ex: errMsg = "invalid proxy address '%s' ('%s')" % (conf.proxy, getSafeExString(ex)) - raise SqlmapSyntaxException, errMsg + raise SqlmapSyntaxException(errMsg) hostnamePort = _.netloc.split(":") @@ -1255,7 +1255,7 @@ def _setSafeVisit(): kb.safeReq.post = None else: errMsg = "invalid format of a safe request file" - raise SqlmapSyntaxException, errMsg + raise SqlmapSyntaxException(errMsg) else: if not re.search(r"\Ahttp[s]*://", conf.safeUrl): if ":443/" in conf.safeUrl: @@ -1580,7 +1580,7 @@ def _createTemporaryDirectory(): except (OSError, IOError) as ex: errMsg = "there has been a problem while accessing " errMsg += "temporary directory location(s) ('%s')" % getSafeExString(ex) - raise SqlmapSystemException, errMsg + raise SqlmapSystemException(errMsg) else: try: if not os.path.isdir(tempfile.gettempdir()): @@ -1607,7 +1607,7 @@ def _createTemporaryDirectory(): except (OSError, IOError, WindowsError) as ex: errMsg = "there has been a problem while setting " errMsg += "temporary directory location ('%s')" % getSafeExString(ex) - raise SqlmapSystemException, errMsg + raise SqlmapSystemException(errMsg) def _cleanupOptions(): """ diff --git a/lib/core/wordlist.py b/lib/core/wordlist.py index 2f2d81b69..29905fea2 100644 --- a/lib/core/wordlist.py +++ b/lib/core/wordlist.py @@ -47,7 +47,7 @@ class Wordlist(object): errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" - raise SqlmapInstallationException, errMsg + raise SqlmapInstallationException(errMsg) if len(_.namelist()) == 0: errMsg = "no file(s) inside '%s'" % self.current raise SqlmapDataException(errMsg) @@ -73,7 +73,7 @@ class Wordlist(object): errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" - raise SqlmapInstallationException, errMsg + raise SqlmapInstallationException(errMsg) except StopIteration: self.adjust() retVal = self.iter.next().rstrip() diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index ec8465f6b..f1b8f62e9 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -910,7 +910,7 @@ def cmdLineParser(argv=None): for arg in shlex.split(command): argv.append(getUnicode(arg, encoding=sys.stdin.encoding)) except ValueError as ex: - raise SqlmapSyntaxException, "something went wrong during command line parsing ('%s')" % ex.message + raise SqlmapSyntaxException("something went wrong during command line parsing ('%s')" % ex.message) for i in xrange(len(argv)): if argv[i] == "-hh": diff --git a/lib/parse/payloads.py b/lib/parse/payloads.py index 89d280532..39921cc75 100644 --- a/lib/parse/payloads.py +++ b/lib/parse/payloads.py @@ -78,7 +78,7 @@ def loadBoundaries(): errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (paths.BOUNDARIES_XML, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" - raise SqlmapInstallationException, errMsg + raise SqlmapInstallationException(errMsg) root = doc.getroot() parseXmlNode(root) @@ -93,7 +93,7 @@ def loadPayloads(): errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (payloadFilePath, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" - raise SqlmapInstallationException, errMsg + raise SqlmapInstallationException(errMsg) root = doc.getroot() parseXmlNode(root) diff --git a/lib/parse/sitemap.py b/lib/parse/sitemap.py index 6724ceb0e..3c503f9fb 100644 --- a/lib/parse/sitemap.py +++ b/lib/parse/sitemap.py @@ -32,7 +32,7 @@ def parseSitemap(url, retVal=None): content = Request.getPage(url=url, raise404=True)[0] if not abortedFlag else "" except httplib.InvalidURL: errMsg = "invalid URL given for sitemap ('%s')" % url - raise SqlmapSyntaxException, errMsg + raise SqlmapSyntaxException(errMsg) for match in re.finditer(r"\s*([^<]+)", content or ""): if abortedFlag: diff --git a/lib/request/connect.py b/lib/request/connect.py index d5628ffaf..f014c550e 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -982,7 +982,7 @@ class Connect(object): if not conf.csrfUrl: errMsg += ". You can try to rerun by providing " errMsg += "a valid value for option '--csrf-url'" - raise SqlmapTokenException, errMsg + raise SqlmapTokenException(errMsg) if token: token = token.strip("'\"") diff --git a/lib/utils/api.py b/lib/utils/api.py index c96b34269..3f0418c43 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -278,7 +278,7 @@ def setRestAPILog(): conf.databaseCursor = Database(conf.database) conf.databaseCursor.connect("client") except sqlite3.OperationalError as ex: - raise SqlmapConnectionException, "%s ('%s')" % (ex, conf.database) + raise SqlmapConnectionException("%s ('%s')" % (ex, conf.database)) # Set a logging handler that writes log messages to a IPC database logger.removeHandler(LOGGER_HANDLER) diff --git a/lib/utils/hashdb.py b/lib/utils/hashdb.py index 342d06172..bb88502f4 100644 --- a/lib/utils/hashdb.py +++ b/lib/utils/hashdb.py @@ -92,7 +92,7 @@ class HashDB(object): except sqlite3.DatabaseError as ex: errMsg = "error occurred while accessing session file '%s' ('%s'). " % (self.filepath, getSafeExString(ex)) errMsg += "If the problem persists please rerun with `--flush-session`" - raise SqlmapConnectionException, errMsg + raise SqlmapConnectionException(errMsg) else: break diff --git a/lib/utils/sqlalchemy.py b/lib/utils/sqlalchemy.py index cb82e7396..d5f5015fe 100644 --- a/lib/utils/sqlalchemy.py +++ b/lib/utils/sqlalchemy.py @@ -46,7 +46,7 @@ class SQLAlchemy(GenericConnector): try: if not self.port and self.db: if not os.path.exists(self.db): - raise SqlmapFilePathException, "the provided database file '%s' does not exist" % self.db + raise SqlmapFilePathException("the provided database file '%s' does not exist" % self.db) _ = conf.direct.split("//", 1) conf.direct = "%s////%s" % (_[0], os.path.abspath(self.db))