From c67c483fdb24c11ab2ff6b17a0c255f4001556b9 Mon Sep 17 00:00:00 2001 From: akun <6awkun@gmail.com> Date: Thu, 1 Feb 2018 21:12:43 +0800 Subject: [PATCH] Refactoring for Python 3 `print` * 2to3 `ls | grep -v thirdparty` -f print --- extra/cloak/cloak.py | 4 ++-- extra/dbgtool/dbgtool.py | 6 +++--- extra/mssqlsig/update.py | 8 ++++---- extra/safe2bin/safe2bin.py | 2 +- extra/shutils/duplicates.py | 2 +- extra/shutils/pylint.py | 18 +++++++++--------- extra/shutils/regressiontest.py | 2 +- extra/sqlharvest/sqlharvest.py | 6 +++--- lib/core/threads.py | 6 +++--- lib/parse/cmdline.py | 4 ++-- lib/request/dns.py | 4 ++-- lib/request/inject.py | 2 +- lib/takeover/abstraction.py | 4 ++-- lib/takeover/metasploit.py | 2 +- lib/techniques/error/use.py | 2 +- lib/utils/api.py | 2 +- lib/utils/hash.py | 4 ++-- plugins/generic/custom.py | 4 ++-- sqlmap.py | 14 +++++++------- 19 files changed, 48 insertions(+), 48 deletions(-) diff --git a/extra/cloak/cloak.py b/extra/cloak/cloak.py index cc95e5a99..d1fe2db1f 100644 --- a/extra/cloak/cloak.py +++ b/extra/cloak/cloak.py @@ -38,7 +38,7 @@ def decloak(inputFile=None, data=None): try: data = zlib.decompress(hideAscii(data)) except: - print 'ERROR: the provided input file \'%s\' does not contain valid cloaked content' % inputFile + print('ERROR: the provided input file \'%s\' does not contain valid cloaked content' % inputFile) sys.exit(1) finally: f.close() @@ -63,7 +63,7 @@ def main(): parser.error(e) if not os.path.isfile(args.inputFile): - print 'ERROR: the provided input file \'%s\' is non existent' % args.inputFile + print('ERROR: the provided input file \'%s\' is non existent' % args.inputFile) sys.exit(1) if not args.decrypt: diff --git a/extra/dbgtool/dbgtool.py b/extra/dbgtool/dbgtool.py index 9a27a60b4..1f5ff92ef 100644 --- a/extra/dbgtool/dbgtool.py +++ b/extra/dbgtool/dbgtool.py @@ -19,7 +19,7 @@ def convert(inputFile): fileSize = fileStat.st_size if fileSize > 65280: - print "ERROR: the provided input file '%s' is too big for debug.exe" % inputFile + print("ERROR: the provided input file '%s' is too big for debug.exe" % inputFile) sys.exit(1) script = "n %s\nr cx\n" % os.path.basename(inputFile.replace(".", "_")) @@ -59,7 +59,7 @@ def convert(inputFile): def main(inputFile, outputFile): if not os.path.isfile(inputFile): - print "ERROR: the provided input file '%s' is not a regular file" % inputFile + print("ERROR: the provided input file '%s' is not a regular file" % inputFile) sys.exit(1) script = convert(inputFile) @@ -70,7 +70,7 @@ def main(inputFile, outputFile): sys.stdout.write(script) sys.stdout.close() else: - print script + print(script) if __name__ == "__main__": usage = "%s -i [-o ]" % sys.argv[0] diff --git a/extra/mssqlsig/update.py b/extra/mssqlsig/update.py index 5e0addab1..d8d3da6bd 100644 --- a/extra/mssqlsig/update.py +++ b/extra/mssqlsig/update.py @@ -22,11 +22,11 @@ MSSQL_VERSIONS_URL = "http://www.sqlsecurity.com/FAQs/SQLServerVersionDatabase/t def updateMSSQLXML(): if not os.path.exists(MSSQL_XML): errMsg = "[ERROR] file '%s' does not exist. Please run the script from its parent directory" % MSSQL_XML - print errMsg + print(errMsg) return infoMsg = "[INFO] retrieving data from '%s'" % MSSQL_VERSIONS_URL - print infoMsg + print(infoMsg) try: req = urllib2.Request(MSSQL_VERSIONS_URL) @@ -39,7 +39,7 @@ def updateMSSQLXML(): warnMsg = "[WARNING] sqlmap was unable to connect to %s," % __mssqlHostname warnMsg += " check your Internet connection and retry" - print warnMsg + print(warnMsg) return @@ -131,7 +131,7 @@ def updateMSSQLXML(): mssqlXml.close() infoMsg = "[INFO] done. retrieved data parsed and saved into '%s'" % MSSQL_XML - print infoMsg + print(infoMsg) if __name__ == "__main__": updateMSSQLXML() diff --git a/extra/safe2bin/safe2bin.py b/extra/safe2bin/safe2bin.py index 19c9784a9..96ae07e77 100644 --- a/extra/safe2bin/safe2bin.py +++ b/extra/safe2bin/safe2bin.py @@ -112,7 +112,7 @@ def main(): parser.error(e) if not os.path.isfile(args.inputFile): - print 'ERROR: the provided input file \'%s\' is not a regular file' % args.inputFile + print('ERROR: the provided input file \'%s\' is not a regular file' % args.inputFile) sys.exit(1) f = open(args.inputFile, 'r') diff --git a/extra/shutils/duplicates.py b/extra/shutils/duplicates.py index 1795299b3..af81cb9f6 100755 --- a/extra/shutils/duplicates.py +++ b/extra/shutils/duplicates.py @@ -17,7 +17,7 @@ if len(sys.argv) > 0: str.encode(item) if item in items: if item: - print item + print(item) else: items.append(item) except: diff --git a/extra/shutils/pylint.py b/extra/shutils/pylint.py index e6b475351..62907c7bc 100755 --- a/extra/shutils/pylint.py +++ b/extra/shutils/pylint.py @@ -17,26 +17,26 @@ def check(module): if module[-3:] == ".py": - print "CHECKING ", module + print("CHECKING ", module) pout = os.popen("pylint --rcfile=/dev/null %s" % module, 'r') for line in pout: if re.match(r"\AE:", line): - print line.strip() + print(line.strip()) if __RATING__ and "Your code has been rated at" in line: - print line + print(line) score = re.findall(r"\d.\d\d", line)[0] total += float(score) count += 1 if __name__ == "__main__": try: - print sys.argv + print(sys.argv) BASE_DIRECTORY = sys.argv[1] except IndexError: - print "no directory specified, defaulting to current working directory" + print("no directory specified, defaulting to current working directory") BASE_DIRECTORY = os.getcwd() - print "looking for *.py scripts in subdirectories of ", BASE_DIRECTORY + print("looking for *.py scripts in subdirectories of ", BASE_DIRECTORY) for root, dirs, files in os.walk(BASE_DIRECTORY): if any(_ in root for _ in ("extra", "thirdparty")): continue @@ -45,6 +45,6 @@ if __name__ == "__main__": check(filepath) if __RATING__: - print "==" * 50 - print "%d modules found" % count - print "AVERAGE SCORE = %.02f" % (total / count) + print("==" * 50) + print("%d modules found" % count) + print("AVERAGE SCORE = %.02f" % (total / count)) diff --git a/extra/shutils/regressiontest.py b/extra/shutils/regressiontest.py index 6ff94d156..66593266b 100755 --- a/extra/shutils/regressiontest.py +++ b/extra/shutils/regressiontest.py @@ -57,7 +57,7 @@ def send_email(msg): s.quit() # Catch all for SMTP exceptions except smtplib.SMTPException, e: - print "Failure to send email: %s" % str(e) + print("Failure to send email: %s" % str(e)) def failure_email(msg): msg = prepare_email(msg) diff --git a/extra/sqlharvest/sqlharvest.py b/extra/sqlharvest/sqlharvest.py index 7c7aa56ed..3152c93d5 100644 --- a/extra/sqlharvest/sqlharvest.py +++ b/extra/sqlharvest/sqlharvest.py @@ -76,7 +76,7 @@ def main(): raise except Exception, msg: - print msg + print(msg) if abort: break @@ -86,7 +86,7 @@ def main(): sys.stdout.write("---------------\n") for sqlfile in files: - print sqlfile + print(sqlfile) try: req = urllib2.Request(sqlfile) @@ -119,7 +119,7 @@ def main(): raise except Exception, msg: - print msg + print(msg) else: i += 1 diff --git a/lib/core/threads.py b/lib/core/threads.py index c1e05cb14..1b6e3af4d 100644 --- a/lib/core/threads.py +++ b/lib/core/threads.py @@ -167,7 +167,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio time.sleep(0.1) except (KeyboardInterrupt, SqlmapUserQuitException), ex: - print + print() kb.threadContinue = False kb.threadException = True @@ -184,7 +184,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio raise except (SqlmapConnectionException, SqlmapValueException), ex: - print + print() kb.threadException = True logger.error("thread %s: %s" % (threading.currentThread().getName(), ex.message)) @@ -194,7 +194,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio except: from lib.core.common import unhandledExceptionMessage - print + print() kb.threadException = True errMsg = unhandledExceptionMessage() logger.error("thread %s: %s" % (threading.currentThread().getName(), errMsg)) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 83161b686..bd1a64294 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -886,7 +886,7 @@ def cmdLineParser(argv=None): command = raw_input("sqlmap-shell> ").strip() command = getUnicode(command, encoding=sys.stdin.encoding) except (KeyboardInterrupt, EOFError): - print + print() raise SqlmapShellQuitException if not command: @@ -930,7 +930,7 @@ def cmdLineParser(argv=None): argv[i] = argv[i][:-1] conf.skipThreadCheck = True elif argv[i] == "--version": - print VERSION_STRING.split('/')[-1] + print(VERSION_STRING.split('/')[-1]) raise SystemExit elif argv[i] in ("-h", "--help"): advancedHelp = False diff --git a/lib/request/dns.py b/lib/request/dns.py index 2cf11fe83..07ead1334 100644 --- a/lib/request/dns.py +++ b/lib/request/dns.py @@ -145,13 +145,13 @@ if __name__ == "__main__": if _ is None: break else: - print "[i] %s" % _ + print("[i] %s" % _) time.sleep(1) except socket.error, ex: if 'Permission' in str(ex): - print "[x] Please run with sudo/Administrator privileges" + print("[x] Please run with sudo/Administrator privileges") else: raise except KeyboardInterrupt: diff --git a/lib/request/inject.py b/lib/request/inject.py index 485b835c4..32c3849ec 100644 --- a/lib/request/inject.py +++ b/lib/request/inject.py @@ -276,7 +276,7 @@ def _goInferenceProxy(expression, fromUser=False, batch=False, unpack=True, char raise SqlmapDataException(errMsg) except KeyboardInterrupt: - print + print() warnMsg = "user aborted during dumping phase" logger.warn(warnMsg) diff --git a/lib/takeover/abstraction.py b/lib/takeover/abstraction.py index 5a50ea986..ac7fb0085 100644 --- a/lib/takeover/abstraction.py +++ b/lib/takeover/abstraction.py @@ -130,11 +130,11 @@ class Abstraction(Web, UDF, XP_cmdshell): command = raw_input("os-shell> ") command = getUnicode(command, encoding=sys.stdin.encoding) except KeyboardInterrupt: - print + print() errMsg = "user aborted" logger.error(errMsg) except EOFError: - print + print() errMsg = "exit" logger.error(errMsg) break diff --git a/lib/takeover/metasploit.py b/lib/takeover/metasploit.py index 5813ca336..0d026794f 100644 --- a/lib/takeover/metasploit.py +++ b/lib/takeover/metasploit.py @@ -492,7 +492,7 @@ class Metasploit: send_all(proc, "getuid\n") if conf.privEsc: - print + print() infoMsg = "trying to escalate privileges using Meterpreter " infoMsg += "'getsystem' command which tries different " diff --git a/lib/techniques/error/use.py b/lib/techniques/error/use.py index 769e0991a..ef9f2c6ff 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -239,7 +239,7 @@ def _errorFields(expression, expressionFields, expressionFieldsList, num=None, e if not suppressOutput: if kb.fileReadMode and output and output.strip(): - print + print() elif output is not None and not (threadData.resumed and kb.suppressResumeInfo) and not (emptyFields and field in emptyFields): status = "[%s] [INFO] %s: %s" % (time.strftime("%X"), "resumed" if threadData.resumed else "retrieved", output if kb.safeCharEncode else safecharencode(output)) diff --git a/lib/utils/api.py b/lib/utils/api.py index 28f0a6c26..82d48ea6c 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -769,7 +769,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non command = raw_input("api%s> " % (" (%s)" % taskid if taskid else "")).strip() command = re.sub(r"\A(\w+)", lambda match: match.group(1).lower(), command) except (EOFError, KeyboardInterrupt): - print + print() break if command in ("data", "log", "status", "stop", "kill"): diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 508d3a9ca..a9509ce90 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -1061,7 +1061,7 @@ def dictionaryAttack(attack_dict): _bruteProcessVariantA(attack_info, hash_regex, suffix, retVal, 0, 1, kb.wordlists, custom_wordlist, conf.api) except KeyboardInterrupt: - print + print() processException = True warnMsg = "user aborted during dictionary-based attack phase (Ctrl+C was pressed)" logger.warn(warnMsg) @@ -1155,7 +1155,7 @@ def dictionaryAttack(attack_dict): found = found_.value except KeyboardInterrupt: - print + print() processException = True warnMsg = "user aborted during dictionary-based attack phase (Ctrl+C was pressed)" logger.warn(warnMsg) diff --git a/plugins/generic/custom.py b/plugins/generic/custom.py index b314410db..ccb284b0c 100644 --- a/plugins/generic/custom.py +++ b/plugins/generic/custom.py @@ -89,11 +89,11 @@ class Custom: query = raw_input("sql-shell> ") query = getUnicode(query, encoding=sys.stdin.encoding) except KeyboardInterrupt: - print + print() errMsg = "user aborted" logger.error(errMsg) except EOFError: - print + print() errMsg = "exit" logger.error(errMsg) break diff --git a/sqlmap.py b/sqlmap.py index d8c236da1..956006274 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -185,7 +185,7 @@ def main(): raise SystemExit except KeyboardInterrupt: - print + print() errMsg = "user aborted" try: @@ -194,7 +194,7 @@ def main(): pass except EOFError: - print + print() errMsg = "exit" try: @@ -206,7 +206,7 @@ def main(): pass except: - print + print() errMsg = unhandledExceptionMessage() excMsg = traceback.format_exc() valid = checkIntegrity() @@ -217,13 +217,13 @@ def main(): errMsg += "You should retrieve the latest development version from official GitHub " errMsg += "repository at '%s'" % GIT_PAGE logger.critical(errMsg) - print + print() dataToStdout(excMsg) raise SystemExit elif any(_ in excMsg for _ in ("tamper/", "waf/")): logger.critical(errMsg) - print + print() dataToStdout(excMsg) raise SystemExit @@ -299,7 +299,7 @@ def main(): elif "url = url.strip()" in excMsg: dataToStdout(excMsg) - print + print() errMsg = "please contact 'miroslav@sqlmap.org' with details for this issue " errMsg += "as he is trying to reproduce it for long time" logger.error(errMsg) @@ -391,4 +391,4 @@ if __name__ == "__main__": main() else: # cancelling postponed imports (because of Travis CI checks) - from lib.controller.controller import start \ No newline at end of file + from lib.controller.controller import start