From fb3af94919a9ee18ba1c35f927f19837f057fa1f Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 25 Jul 2016 19:05:26 +0300 Subject: [PATCH] Use print function for Py3 compatibility --- m_lib/clock/mkclock.py | 9 ++++---- m_lib/clock/tstclock.py | 5 ++-- m_lib/defenc.py | 11 +++++---- m_lib/flad/test/test1.py | 41 +++++++++++++++++---------------- m_lib/flad/test/test2.py | 9 ++++---- m_lib/flad/test/test3.py | 5 ++-- m_lib/flad/test/test4.py | 7 +++--- m_lib/flad/test/test5.py | 7 +++--- m_lib/flad/test/test6.py | 5 ++-- m_lib/flad/test/test7.py | 7 +++--- m_lib/hash/test/test-mk1.py | 3 ++- m_lib/hash/test/test-mk2.py | 17 +++++++------- m_lib/hash/test/test-mk3.py | 9 ++++---- m_lib/hash/test/test-shelve2.py | 3 ++- m_lib/hash/test/test-shelve3.py | 3 ++- m_lib/hash/test/test-shelve4.py | 3 ++- m_lib/hash/test/test-shelve5.py | 7 +++--- m_lib/hash/test/test-shelve6.py | 7 +++--- m_lib/hash/test/test-zh.py | 27 +++++++++++----------- m_lib/m_path.py | 3 ++- m_lib/m_shutil.py | 5 ++-- m_lib/mcrypt.py | 7 +++--- m_lib/md5wrapper.py | 11 +++++---- m_lib/net/ftp/ftpparse.py | 39 ++++++++++++++++--------------- m_lib/net/ftp/ftpscan.py | 11 +++++---- m_lib/net/www/util.py | 21 +++++++++-------- m_lib/opdate.py | 34 ++++++++++++++------------- m_lib/opstring.py | 13 ++++++----- m_lib/pbar/test/ind_test.py | 5 ++-- m_lib/pbar/test/test1.py | 7 +++--- m_lib/pbar/test/test2.py | 7 +++--- m_lib/pbar/test/test3.py | 7 +++--- m_lib/pbar/test/test4.py | 3 ++- m_lib/rus/lat2rus.py | 8 ++++--- m_lib/rus/rus2lat.py | 8 ++++--- m_lib/tty_menu.py | 9 ++++---- 36 files changed, 211 insertions(+), 172 deletions(-) diff --git a/m_lib/clock/mkclock.py b/m_lib/clock/mkclock.py index 7841ec8..db69be6 100755 --- a/m_lib/clock/mkclock.py +++ b/m_lib/clock/mkclock.py @@ -1,20 +1,21 @@ #! /usr/bin/env python """Test if current interpreter do not have clock() and define it as need""" +from __future__ import print_function import sys, time -print "Testing...", +print("Testing...", end=' ') sys.stdout.flush() time.sleep(3) -print '\n' + " "*len("Testing...") + '\n', +print('\n' + " "*len("Testing...") + '\n', end=' ') need_clock = time.clock() <> 3 outfile = open("clock.py", 'w') if need_clock: - print "Generaing clock.py with custom clock()" + print("Generaing clock.py with custom clock()") outfile.write("""\"\"\" Define clock() for systems that do not have it \"\"\" @@ -26,7 +27,7 @@ def clock(): return int(time() - _clock) """) else: - print "Generaing clock.py with standard clock()" + print("Generaing clock.py with standard clock()") outfile.write("""\"\"\" Define clock() shim \"\"\" diff --git a/m_lib/clock/tstclock.py b/m_lib/clock/tstclock.py index 5dd1737..2c1df4c 100755 --- a/m_lib/clock/tstclock.py +++ b/m_lib/clock/tstclock.py @@ -1,9 +1,10 @@ #! /usr/bin/env python """Define clock() for systems that do not have it""" +from __future__ import print_function from clock import clock from time import sleep -print "Testing..." +print("Testing...") sleep(3) -print "Clock:", clock() +print("Clock:", clock()) diff --git a/m_lib/defenc.py b/m_lib/defenc.py index 90add9d..43b102f 100755 --- a/m_lib/defenc.py +++ b/m_lib/defenc.py @@ -1,8 +1,7 @@ #! /usr/bin/env python """Get default encoding""" -__all__ = ['default_encoding'] - +from __future__ import print_function import sys try: @@ -11,12 +10,14 @@ try: except ImportError: use_locale = False +__all__ = ['default_encoding'] + if use_locale: # Get the default charset. try: lcAll = locale.getdefaultlocale() except locale.Error, err: - print >>sys.stderr, "WARNING:", err + print("WARNING:", err, file=sys.stderr) lcAll = [] if len(lcAll) == 2 and lcAll[0] is not None: @@ -25,7 +26,7 @@ if use_locale: try: default_encoding = locale.getpreferredencoding() except locale.Error, err: - print >>sys.stderr, "WARNING:", err + print("WARNING:", err, file=sys.stderr) default_encoding = sys.getdefaultencoding() else: default_encoding = sys.getdefaultencoding() @@ -33,4 +34,4 @@ else: default_encoding = default_encoding.lower() if __name__ == "__main__": - print default_encoding + print(default_encoding) diff --git a/m_lib/flad/test/test1.py b/m_lib/flad/test/test1.py index 5ac6217..16c7bb3 100755 --- a/m_lib/flad/test/test1.py +++ b/m_lib/flad/test/test1.py @@ -1,53 +1,54 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import fladm def test(): print - print "Test 1:", + print("Test 1:", end=' ') fladm.load_from_file("test.txt", fladm.check_record, None, None) - print "Ok" + print("Ok") - print "Test 2:", + print("Test 2:", end=' ') fladm.load_from_file("test.txt", fladm.check_record, ["Type"], None) - print "Ok" + print("Ok") - print "Test 3:", + print("Test 3:", end=' ') fladm.load_from_file("test.txt", fladm.check_record, ["Type", "Name"], None) - print "Ok" + print("Ok") - print "Test 4:", + print("Test 4:", end=' ') fladm.load_from_file("test.txt", fladm.check_record, ["Type"], ["Name"]) - print "Ok" + print("Ok") - print "Test 5:", + print("Test 5:", end=' ') try: # Note! This must raise KeyError - "Name" key is not listed fladm.load_from_file("test.txt", fladm.check_record, ["Type"], [""]) except KeyError: - print "Ok" + print("Ok") else: - print "Error!" + print("Error!") - print "Test 6:", + print("Test 6:", end=' ') fladm.load_from_file("test.txt", fladm.check_record, None, ["Type", "Name"]) - print "Ok" + print("Ok") - print "Test 7:", + print("Test 7:", end=' ') try: # Note! This must raise KeyError - "Error" key is listed in must field fladm.load_from_file("test.txt", fladm.check_record, ["Error"], ["Type"]) except KeyError: - print "Ok" + print("Ok") else: - print "Error!" + print("Error!") - print "Test 8:", + print("Test 8:", end=' ') datalist = fladm.load_from_file("test.txt", fladm.check_record, None, ["Type", "Name", "Error"]) - print "Ok" + print("Ok") - print "\nLast but not test: just printing loaded list" - print datalist + print("\nLast but not test: just printing loaded list") + print(datalist) print diff --git a/m_lib/flad/test/test2.py b/m_lib/flad/test/test2.py index 15035ee..0011669 100755 --- a/m_lib/flad/test/test2.py +++ b/m_lib/flad/test/test2.py @@ -1,19 +1,20 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import flad def test(): - print "Test 1:", + print("Test 1:", end=' ') datalist = flad.load_from_file("test.txt") datalist.store_to_file("test2.o1") - print "Ok" + print("Ok") - print "Test 2:", + print("Test 2:", end=' ') datalist = flad.load_from_file("comment.txt") datalist.store_to_file("test2.o2") - print "Ok" + print("Ok") if __name__ == "__main__": diff --git a/m_lib/flad/test/test3.py b/m_lib/flad/test/test3.py index cf0cf3e..6e967af 100755 --- a/m_lib/flad/test/test3.py +++ b/m_lib/flad/test/test3.py @@ -1,14 +1,15 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import fladm def test(): - print "Test:", + print("Test:", end=' ') datalist = fladm.load_file("test.txt", fladm.check_record, ["Type"], ["Name"]) datalist.store_to_file("test3.out") - print "Ok" + print("Ok") if __name__ == "__main__": diff --git a/m_lib/flad/test/test4.py b/m_lib/flad/test/test4.py index 8103ed9..c42d782 100755 --- a/m_lib/flad/test/test4.py +++ b/m_lib/flad/test/test4.py @@ -1,15 +1,16 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import fladc def test(): - print "Test:", + print("Test:", end=' ') conf = fladc.load_file("test.cfg") - print "Ok" + print("Ok") - print "Property 'Type' is", conf["Type"] + print("Property 'Type' is", conf["Type"]) if __name__ == "__main__": diff --git a/m_lib/flad/test/test5.py b/m_lib/flad/test/test5.py index 45b70aa..9edc5b4 100755 --- a/m_lib/flad/test/test5.py +++ b/m_lib/flad/test/test5.py @@ -1,18 +1,19 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import fladc def test(): - print "Test:", + print("Test:", end=' ') try: # Note! This must raise fladc.error - too many records in the file conf = fladc.load_file("test.txt") except fladc.error: - print "Ok" + print("Ok") else: - print "Error!" + print("Error!") if __name__ == "__main__": diff --git a/m_lib/flad/test/test6.py b/m_lib/flad/test/test6.py index ae1131b..7e8b133 100755 --- a/m_lib/flad/test/test6.py +++ b/m_lib/flad/test/test6.py @@ -1,14 +1,15 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import fladc def test(): - print "Test:", + print("Test:", end=' ') conf = fladc.load_file("test.cfg", ["Type", "Name"]) conf.store_to_file("test6.out") - print "Ok" + print("Ok") if __name__ == "__main__": diff --git a/m_lib/flad/test/test7.py b/m_lib/flad/test/test7.py index 4e75952..31d7709 100755 --- a/m_lib/flad/test/test7.py +++ b/m_lib/flad/test/test7.py @@ -1,16 +1,17 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.flad import fladw def test(): - print "Test:", + print("Test:", end=' ') ini = fladw.load_file("C:\\WINDOWS\\WIN.INI") ini.store_to_file("test7.out") - print "Ok" + print("Ok") - print "windows/BorderWidth =", ini.get_keyvalue("windows", "BorderWidth") + print("windows/BorderWidth =", ini.get_keyvalue("windows", "BorderWidth")) if __name__ == "__main__": diff --git a/m_lib/hash/test/test-mk1.py b/m_lib/hash/test/test-mk1.py index bd11165..8a11547 100755 --- a/m_lib/hash/test/test-mk1.py +++ b/m_lib/hash/test/test-mk1.py @@ -1,10 +1,11 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import MKhash -print "Making..." +print("Making...") db = MKhash.open("db", 'c') db["test"] = "Test Ok!" db.close() diff --git a/m_lib/hash/test/test-mk2.py b/m_lib/hash/test/test-mk2.py index d0ffe76..8a7710c 100755 --- a/m_lib/hash/test/test-mk2.py +++ b/m_lib/hash/test/test-mk2.py @@ -1,17 +1,18 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import MKhash -print "Testing..." +print("Testing...") db = MKhash.open("db", 'w') -print db["test"] -print len(db) -print db.keys() -print db.has_key("test") -print db.has_key("Test") -print db.get("test", "Yes") -print db.get("Test", "No") +print(db["test"]) +print(len(db)) +print(db.keys()) +print(db.has_key("test")) +print(db.has_key("Test")) +print(db.get("test", "Yes")) +print(db.get("Test", "No")) del db["test"] db.close() diff --git a/m_lib/hash/test/test-mk3.py b/m_lib/hash/test/test-mk3.py index 10bcb24..65005ab 100755 --- a/m_lib/hash/test/test-mk3.py +++ b/m_lib/hash/test/test-mk3.py @@ -1,12 +1,13 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import MKhash -print "Testing (more)..." +print("Testing (more)...") db = MKhash.open("db", 'r') -print len(db) -print db.keys() -print db.has_key("test") +print(len(db)) +print(db.keys()) +print(db.has_key("test")) db.close() diff --git a/m_lib/hash/test/test-shelve2.py b/m_lib/hash/test/test-shelve2.py index 883e891..418dd8b 100755 --- a/m_lib/hash/test/test-shelve2.py +++ b/m_lib/hash/test/test-shelve2.py @@ -1,8 +1,9 @@ #! /usr/bin/env python +from __future__ import print_function import shelve db = shelve.open("db", 'r') -print db["test"] +print(db["test"]) db.close() diff --git a/m_lib/hash/test/test-shelve3.py b/m_lib/hash/test/test-shelve3.py index e6f76d3..bb2fb5f 100755 --- a/m_lib/hash/test/test-shelve3.py +++ b/m_lib/hash/test/test-shelve3.py @@ -1,6 +1,7 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import zshelve db = zshelve.CompressedShelf("dbz", 'c') @@ -8,5 +9,5 @@ db["test"] = "Test Ok!" db.close() db = zshelve.CompressedShelf("dbz", 'r') -print db["test"] +print(db["test"]) db.close() diff --git a/m_lib/hash/test/test-shelve4.py b/m_lib/hash/test/test-shelve4.py index e084103..6e698bb 100755 --- a/m_lib/hash/test/test-shelve4.py +++ b/m_lib/hash/test/test-shelve4.py @@ -1,6 +1,7 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import zshelve db = zshelve.CompressedKeysShelf("dbz", 'c') @@ -8,5 +9,5 @@ db["test"] = "Test Ok!" db.close() db = zshelve.CompressedKeysShelf("dbz", 'r') -print db["test"] +print(db["test"]) db.close() diff --git a/m_lib/hash/test/test-shelve5.py b/m_lib/hash/test/test-shelve5.py index fb859e4..9618ca2 100755 --- a/m_lib/hash/test/test-shelve5.py +++ b/m_lib/hash/test/test-shelve5.py @@ -1,6 +1,7 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import zshelve db = zshelve.CompressedKeysShelf("dbz", 'n') @@ -8,7 +9,7 @@ db["test"] = "Test Ok!" db.close() db = zshelve.CompressedKeysShelf("dbz", 'r') -print db.has_key("test") -print db.keys() -print db["test"] +print(db.has_key("test")) +print(db.keys()) +print(db["test"]) db.close() diff --git a/m_lib/hash/test/test-shelve6.py b/m_lib/hash/test/test-shelve6.py index 3412bde..1d8de80 100755 --- a/m_lib/hash/test/test-shelve6.py +++ b/m_lib/hash/test/test-shelve6.py @@ -1,6 +1,7 @@ #! /usr/bin/env python +from __future__ import print_function import anydbm, dbhash anydbm._defaultmod = dbhash @@ -12,7 +13,7 @@ db["test"] = "Test Ok!" db.close() db = zshelve.CompressedKeysShelf("dbz", 'r') -print db.has_key("test") -print db.keys() -print db["test"] +print(db.has_key("test")) +print(db.keys()) +print(db["test"]) db.close() diff --git a/m_lib/hash/test/test-zh.py b/m_lib/hash/test/test-zh.py index 3095b14..f49d1c3 100755 --- a/m_lib/hash/test/test-zh.py +++ b/m_lib/hash/test/test-zh.py @@ -1,29 +1,30 @@ #! /usr/bin/env python +from __future__ import print_function from m_lib.hash import ZODBhash -print "Making..." +print("Making...") db = ZODBhash.open("db", 'c') db["test"] = "Test Ok!" db.close() -print "Testing..." +print("Testing...") db = ZODBhash.open("db", 'w') -print db["test"] -print len(db) -print db.keys() -print db.has_key("test") -print db.has_key("Test") -print db.get("test", "Yes") -print db.get("Test", "No") +print(db["test"]) +print(len(db)) +print(db.keys()) +print(db.has_key("test")) +print(db.has_key("Test")) +print(db.get("test", "Yes")) +print(db.get("Test", "No")) del db["test"] db.close() -print "Testing (more)..." +print("Testing (more)...") db = ZODBhash.open("db", 'r') -print len(db) -print db.keys() -print db.has_key("test") +print(len(db)) +print(db.keys()) +print(db.has_key("test")) db.close() diff --git a/m_lib/m_path.py b/m_lib/m_path.py index 0131289..3cc57c5 100755 --- a/m_lib/m_path.py +++ b/m_lib/m_path.py @@ -4,6 +4,7 @@ # useful function(s) for manipulating paths # +from __future__ import print_function _homedir = None @@ -16,7 +17,7 @@ def get_homedir(): def test(): - print get_homedir() + print(get_homedir()) if __name__ == "__main__": diff --git a/m_lib/m_shutil.py b/m_lib/m_shutil.py index e4595c7..c8325d4 100755 --- a/m_lib/m_shutil.py +++ b/m_lib/m_shutil.py @@ -4,6 +4,7 @@ Shell utilities. Additional to shutil.py (standard library module). """ +from __future__ import print_function import os, string @@ -17,11 +18,11 @@ def mkhier(path): # Python implementation of UNIX' mkdir -p /path/to/dir raise mkhier_error, "`%s' is file" % path list_dirs = string.split(path, os.sep) - #print list_dirs + #print(list_dirs) for i in range(0, len(list_dirs)): new_path = string.join(list_dirs[0:i+1], os.sep) if (new_path <> '') and (not os.path.exists(new_path)): - #print "Making", new_path + #print("Making", new_path) os.mkdir(new_path) diff --git a/m_lib/mcrypt.py b/m_lib/mcrypt.py index acbead1..76922a0 100755 --- a/m_lib/mcrypt.py +++ b/m_lib/mcrypt.py @@ -5,6 +5,7 @@ # +from __future__ import print_function import random, crypt @@ -32,7 +33,7 @@ def test(): pwd_file = open("test.pwd", 'w') pwd_file.write("%s:%s" % ("user", encrypted)) pwd_file.close() - print "Password file written" + print("Password file written") import string pwd_file = open("test.pwd", 'r') @@ -40,9 +41,9 @@ def test(): pwd_file.close() if crypt.crypt(encrypted, encrypted): - print "Password verified Ok" + print("Password verified Ok") else: - print "BAD password" + print("BAD password") if __name__ == "__main__": test() diff --git a/m_lib/md5wrapper.py b/m_lib/md5wrapper.py index 1cdac61..d428d55 100755 --- a/m_lib/md5wrapper.py +++ b/m_lib/md5wrapper.py @@ -1,14 +1,15 @@ #! /usr/bin/env python """User wrapper for md5 builtin object""" -__all__ = ['md5wrapper'] - +from __future__ import print_function import sys if sys.version < '2.5': from md5 import md5 else: from hashlib import md5 +__all__ = ['md5wrapper'] + class md5wrapper: def __init__(self, init=None): if init: @@ -44,6 +45,6 @@ class md5wrapper: infile.close() if __name__ == "__main__": - print "This must print exactly the string" - print "Test: 900150983cd24fb0d6963f7d28e17f72" - print "Test:", md5wrapper("abc") + print("This must print exactly the string") + print("Test: 900150983cd24fb0d6963f7d28e17f72") + print("Test:", md5wrapper("abc")) diff --git a/m_lib/net/ftp/ftpparse.py b/m_lib/net/ftp/ftpparse.py index 1dcef0c..ae700c3 100755 --- a/m_lib/net/ftp/ftpparse.py +++ b/m_lib/net/ftp/ftpparse.py @@ -21,6 +21,7 @@ Definitely not covered: """ +from __future__ import print_function try: from mx import DateTime except ImportError: @@ -228,35 +229,35 @@ def ftpparse(line): def test(): #UNIX-style listing, without inum and without blocks - print ftpparse("-rw-r--r-- 1 root other 531 Jan 29 03:26 README") - print ftpparse("dr-xr-xr-x 2 root other 512 Apr 8 1994 etc") - print ftpparse("dr-xr-xr-x 2 root 512 Apr 8 1994 etc") - print ftpparse("lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin") + print(ftpparse("-rw-r--r-- 1 root other 531 Jan 29 03:26 README")) + print(ftpparse("dr-xr-xr-x 2 root other 512 Apr 8 1994 etc")) + print(ftpparse("dr-xr-xr-x 2 root 512 Apr 8 1994 etc")) + print(ftpparse("lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin")) #FTP servers for Windoze: - print ftpparse("---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z") - print ftpparse("d--------- 1 owner group 0 May 9 19:45 Softlib") + print(ftpparse("---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z")) + print(ftpparse("d--------- 1 owner group 0 May 9 19:45 Softlib")) #WFTPD for DOS: - print ftpparse("-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp") + print(ftpparse("-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp")) #NetWare: - print ftpparse("d [R----F--] supervisor 512 Jan 16 18:53 login") - print ftpparse("- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe") + print(ftpparse("d [R----F--] supervisor 512 Jan 16 18:53 login")) + print(ftpparse("- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe")) #NetPresenz for the Mac: - print ftpparse("-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit") - print ftpparse("drwxrwxr-x folder 2 May 10 1996 network") + print(ftpparse("-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit")) + print(ftpparse("drwxrwxr-x folder 2 May 10 1996 network")) #MultiNet (some spaces removed from examples) - print ftpparse("00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)") - print ftpparse("CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)") + print(ftpparse("00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)")) + print(ftpparse("CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)")) #non-MutliNet VMS: - print ftpparse("CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)") + print(ftpparse("CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)")) #DOS format - print ftpparse("04-27-00 09:09PM licensed") - print ftpparse("07-18-00 10:16AM pub") - print ftpparse("04-14-00 03:47PM 589 readme.htm") + print(ftpparse("04-27-00 09:09PM licensed")) + print(ftpparse("07-18-00 10:16AM pub")) + print(ftpparse("04-14-00 03:47PM 589 readme.htm")) - print ftpparse("-rw-r--r-- 1 root other 531 Jan 29 03:26 READ ME") - print ftpparse("-rw-r--r-- 1 root other 531 Jan 29 03:26 DO NOT READ ME ") + print(ftpparse("-rw-r--r-- 1 root other 531 Jan 29 03:26 READ ME")) + print(ftpparse("-rw-r--r-- 1 root other 531 Jan 29 03:26 DO NOT READ ME ")) if __name__ == "__main__": test() diff --git a/m_lib/net/ftp/ftpscan.py b/m_lib/net/ftp/ftpscan.py index 319660b..5eeb1d2 100755 --- a/m_lib/net/ftp/ftpscan.py +++ b/m_lib/net/ftp/ftpscan.py @@ -2,6 +2,7 @@ """Recursive FTP scanners""" +from __future__ import print_function import ftplib from m_lib.net.ftp.ftpparse import ftpparse @@ -217,7 +218,7 @@ def test(ftp_server, func, passive=None, reconnect=False): tree = func(ftp_server, passive=passive, reconnect=reconnect) stop_time = time() - print stop_time - start_time + print(stop_time - start_time) logfname = "%s.list" % ftp_server log = open(logfname, 'w') @@ -268,16 +269,16 @@ if __name__ == "__main__": else: ftp_server = arguments[0] - print "Scanning", ftp_server + print("Scanning", ftp_server) try: test(ftp_server, ftpscanrecursive, passive) except FtpScanError, msg: - print "Rescanning due to the error:", msg + print("Rescanning due to the error:", msg) try: test(ftp_server, ftpscan1, passive) except EOFError: - print "Rescanning due to the error: connection reset by peer" + print("Rescanning due to the error: connection reset by peer") test(ftp_server, ftpscan1, passive, True) except EOFError: - print "Rescanning due to the error: connection reset by peer" + print("Rescanning due to the error: connection reset by peer") test(ftp_server, ftpscan1, passive, True) diff --git a/m_lib/net/www/util.py b/m_lib/net/www/util.py index 1d9d72a..40021b7 100644 --- a/m_lib/net/www/util.py +++ b/m_lib/net/www/util.py @@ -1,21 +1,22 @@ """Common WWW/CGI utilities""" +from __future__ import print_function import sys, os def exception(str = ""): if sys.exc_type == SystemExit: # pass exit() normally return - - print "Content-Type: text/html" - print # Terminate HTTP headers + + # Add the second linefeed to terminate HTTP headers + print("Content-Type: text/html\n") import html - print html.exception() + print(html.exception()) if str: - print str + print(str) sys.exit(1) @@ -24,10 +25,10 @@ def error(err_str): if not err_str: err_str = "Unknown error" - print "Content-Type: text/html" - print # Terminate HTTP headers + # Add the second linefeed to terminate HTTP headers + print("Content-Type: text/html\n") - print str(err_str) + print(str(err_str)) sys.exit(1) @@ -52,7 +53,7 @@ def convert_empty(estr): def gen_html(title, body): - print """ + print(""" @@ -64,7 +65,7 @@ def gen_html(title, body): %s </BODY> </HTML> - """ % (title, body) + """ % (title, body)) def mkexpires(hours=1, minutes=0, seconds=0): diff --git a/m_lib/opdate.py b/m_lib/opdate.py index 13a9d25..b28dec6 100755 --- a/m_lib/opdate.py +++ b/m_lib/opdate.py @@ -7,6 +7,7 @@ # +from __future__ import print_function from string import * from time import * from calendar import * @@ -440,38 +441,39 @@ LongMonthNamesA = [' # def test(): - print "Is 1984 leap year?", IsLeapYear(1984) - print "Is 1990 leap year?", IsLeapYear(1990) + print("Is 1984 leap year?", IsLeapYear(1984)) + print("Is 1990 leap year?", IsLeapYear(1990)) - print "Days in month 8 year 1996:", DaysInMonth(8, 1996) + print("Days in month 8 year 1996:", DaysInMonth(8, 1996)) - print "Is date 8/12/1996 valid?", ValidDate(8, 12, 1996) - print "Is date 40/11/1996 valid?", ValidDate(40, 11, 1996) - print "Is date 8/14/1996 valid?", ValidDate(8, 14, 1996) + print("Is date 8/12/1996 valid?", ValidDate(8, 12, 1996)) + print("Is date 40/11/1996 valid?", ValidDate(40, 11, 1996)) + print("Is date 8/14/1996 valid?", ValidDate(8, 14, 1996)) - print "Date->DMY for 138219:", DateToDMY(138219) + print("Date->DMY for 138219:", DateToDMY(138219)) diff = DateDiff(DMYtoDate(12, 10, 1996), DMYtoDate(12, 10, 1997)) - print "Date 12/10/1996 and date 12/10/1997 diff: %d years, %d months, %d days" % (diff[2], diff[1], diff[0]) + print("Date 12/10/1996 and date 12/10/1997 diff: %d years, %d months, %d days" % (diff[2], diff[1], diff[0])) diff = DateDiff(DMYtoDate(12, 10, 1996), DMYtoDate(12, 11, 1997)) - print "Date 12/10/1996 and date 12/11/1997 diff: %d years, %d months, %d days" % (diff[2], diff[1], diff[0]) + print("Date 12/10/1996 and date 12/11/1997 diff: %d years, %d months, %d days" % (diff[2], diff[1], diff[0])) diff = DateDiff(DMYtoDate(31, 1, 1996), DMYtoDate(1, 3, 1996)) - print "Date 31/01/1996 and date 01/03/1996 diff: %d years, %d months, %d days" % (diff[2], diff[1], diff[0]) + print("Date 31/01/1996 and date 01/03/1996 diff: %d years, %d months, %d days" % (diff[2], diff[1], diff[0])) - #print "November is %dth month" % MonthStringToMonth("November") + #print("November is %dth month" % MonthStringToMonth("November")) - print "Today is", Today() - print "Now is", CurrentTime() + print("Today is", Today()) + print("Now is", CurrentTime()) - print "My birthday 21 Dec 1967 is (must be Thursday):", day_name[DayOfWeekDMY(21, 12, 67)] + print("My birthday 21 Dec 1967 is (must be Thursday):", day_name[DayOfWeekDMY(21, 12, 67)]) gmt = DateTimeToGMT(DMYtoDate(21, 12, 1967), HMStoTime(23, 45, 0)) - print "21 Dec 1967, 23:45:00 --", gmtime(gmt) # DOS version of gmtime has error processing dates before 1/1/1970 :( + # DOS version of gmtime has error processing dates before 1/1/1970 :( + print("21 Dec 1967, 23:45:00 --", gmtime(gmt)) D, T = GMTtoDateTime(gmt) - print "(gmt) --", DateToDMY(D), TimeToHMS(T) + print("(gmt) --", DateToDMY(D), TimeToHMS(T)) if __name__ == "__main__": test() diff --git a/m_lib/opstring.py b/m_lib/opstring.py index e01a043..8bd864a 100755 --- a/m_lib/opstring.py +++ b/m_lib/opstring.py @@ -7,6 +7,7 @@ # +from __future__ import print_function from string import * @@ -143,14 +144,14 @@ def koi2win(s, errors = "strict"): # def test(): - print "bin(0x6) =", bin(0x6) - print "bin(0xC) =", bin(0xC) + print("bin(0x6) =", bin(0x6)) + print("bin(0xC) =", bin(0xC)) - print "'Test' left-padded :", LeftPad("Test", 20) - print "'Test' right-padded:", PadCh("Test", '*', 20) - print "'Test' centered :", CenterCh("Test", '=', 20) + print("'Test' left-padded :", LeftPad("Test", 20)) + print("'Test' right-padded:", PadCh("Test", '*', 20)) + print("'Test' centered :", CenterCh("Test", '=', 20)) - print "'ïÌÅÇ':", koi2win(win2koi("ïÌÅÇ")) + print("'ïÌÅÇ':", koi2win(win2koi("ïÌÅÇ"))) if __name__ == "__main__": test() diff --git a/m_lib/pbar/test/ind_test.py b/m_lib/pbar/test/ind_test.py index 727633f..585b7e1 100755 --- a/m_lib/pbar/test/ind_test.py +++ b/m_lib/pbar/test/ind_test.py @@ -1,12 +1,13 @@ #! /usr/bin/env python +from __future__ import print_function import sys from time import sleep from m_lib.pbar.tty_pbar import ttyProgressBar def test(): - print "Test: ", + print("Test: ", end=' ') sys.stdout.flush() x1 = 217 @@ -18,7 +19,7 @@ def test(): sleep(0.05) pbar.erase() - print "Ok" + print("Ok") if __name__ == "__main__": diff --git a/m_lib/pbar/test/test1.py b/m_lib/pbar/test/test1.py index ed15ce6..0276f48 100755 --- a/m_lib/pbar/test/test1.py +++ b/m_lib/pbar/test/test1.py @@ -3,21 +3,22 @@ Test N1 to time file reading """ +from __future__ import print_function import sys from clock import clock def test(): - print "Test: ", + print("Test: ", end=' ') sys.stdout.flush() infile = open(sys.argv[1]) lines = infile.readlines() infile.close() - print "Ok" + print("Ok") if __name__ == "__main__": test() - print "Overall time:", clock() + print("Overall time:", clock()) diff --git a/m_lib/pbar/test/test2.py b/m_lib/pbar/test/test2.py index 80dea23..ebc4ef3 100755 --- a/m_lib/pbar/test/test2.py +++ b/m_lib/pbar/test/test2.py @@ -3,12 +3,13 @@ Test N2 to time file reading """ +from __future__ import print_function import sys from clock import clock def test(): - print "Test: ", + print("Test: ", end=' ') sys.stdout.flush() infile = open(sys.argv[1]) @@ -19,9 +20,9 @@ def test(): lines.append(line) infile.close() - print "Ok" + print("Ok") if __name__ == "__main__": test() - print "Overall time:", clock() + print("Overall time:", clock()) diff --git a/m_lib/pbar/test/test3.py b/m_lib/pbar/test/test3.py index 84a56c3..77979a1 100755 --- a/m_lib/pbar/test/test3.py +++ b/m_lib/pbar/test/test3.py @@ -3,13 +3,14 @@ Test N3 to time file reading """ +from __future__ import print_function import sys, os from clock import clock from m_lib.pbar.tty_pbar import ttyProgressBar def test(): - print "Test: ", + print("Test: ", end=' ') sys.stdout.flush() size = os.path.getsize(sys.argv[1]) @@ -36,9 +37,9 @@ def test(): infile.close() pbar.erase() - print "Ok" + print("Ok") if __name__ == "__main__": test() - print "Overall time:", clock() + print("Overall time:", clock()) diff --git a/m_lib/pbar/test/test4.py b/m_lib/pbar/test/test4.py index 1ce821c..9387175 100755 --- a/m_lib/pbar/test/test4.py +++ b/m_lib/pbar/test/test4.py @@ -3,6 +3,7 @@ Test N4: earse()/redraw() """ +from __future__ import print_function import sys from time import sleep from m_lib.pbar.tty_pbar import ttyProgressBar @@ -27,7 +28,7 @@ def test(): sleep(2) del pbar - print "Ok" + print("Ok") if __name__ == "__main__": diff --git a/m_lib/rus/lat2rus.py b/m_lib/rus/lat2rus.py index 4076fa2..4e3d580 100755 --- a/m_lib/rus/lat2rus.py +++ b/m_lib/rus/lat2rus.py @@ -1,6 +1,8 @@ #! /usr/bin/env python # -*- coding: koi8-r -*- +from __future__ import print_function + # # Lat -> Rus translation # @@ -110,6 +112,6 @@ def lat2win(instr): if __name__ == "__main__": Test = "Ghbdtn nt,t^ ghtrhfcysq vbh!" - print "Test:", Test - print "ôÅÓÔ:", lat2koi(Test) - print "ôÅÓÔ:", unicode(lat2win(Test), "cp1251").encode("koi8-r") + print("Test:", Test) + print("ôÅÓÔ:", lat2koi(Test)) + print("ôÅÓÔ:", unicode(lat2win(Test), "cp1251").encode("koi8-r")) diff --git a/m_lib/rus/rus2lat.py b/m_lib/rus/rus2lat.py index b2677b2..7fbbf06 100755 --- a/m_lib/rus/rus2lat.py +++ b/m_lib/rus/rus2lat.py @@ -1,6 +1,8 @@ #! /usr/bin/env python # -*- coding: koi8-r -*- +from __future__ import print_function + # # Rus -> Lat transliteration (koi2lat and win2lat) # @@ -99,6 +101,6 @@ def win2lat(instr): if __name__ == "__main__": Test = "ýÅÒÂÁËÏ× éÇÏÒØ çÒÉÇÏÒØÅ×ÉÞ. áâ÷ xyz ÁÂ× øøüàñ ßØÜÀÑ" - print "Test:", Test - print "ôÅÓÔ:", koi2lat(Test) - print "ôÅÓÔ:", win2lat(unicode(Test, "koi8-r").encode("cp1251")) + print("Test:", Test) + print("ôÅÓÔ:", koi2lat(Test)) + print("ôÅÓÔ:", win2lat(unicode(Test, "koi8-r").encode("cp1251"))) diff --git a/m_lib/tty_menu.py b/m_lib/tty_menu.py index 0c41c86..897ecc9 100755 --- a/m_lib/tty_menu.py +++ b/m_lib/tty_menu.py @@ -2,6 +2,7 @@ """tty menus""" +from __future__ import print_function import string @@ -25,7 +26,7 @@ def vmenu(item_list, prompt, format = "%d. %s"): returns selected number. Returns -1, if user enter non-numeric string. """ for i in range(len(item_list)): - print format % (i, item_list[i]) + print(format % (i, item_list[i])) print result = raw_input(prompt) @@ -40,14 +41,14 @@ def vmenu(item_list, prompt, format = "%d. %s"): def test(): result = hmenu("Select: d)aily, w)eekly, m)onthly, c)ancel: ", "dwmc") - print "Answer is '%s'\n" % result + print("Answer is '%s'\n" % result) os_list = ["DOS", "Windows", "UNIX"] result = vmenu(os_list, "Select OS: ") if 0 <= result < len(os_list): - print "Answer is '%s'\n" % os_list[result] + print("Answer is '%s'\n" % os_list[result]) else: - print "Wrong selection" + print("Wrong selection") if __name__ == "__main__": test() -- 2.39.2