Fix compatibility with Python 3: print() is a function
Change-Id: I5dd8e5daf420fc8667c5156bfacc8763d8895993
diff --git a/README.md b/README.md
index 85b9a57..7074ffa 100644
--- a/README.md
+++ b/README.md
@@ -101,7 +101,7 @@
sl.wait_for_card()
# Print IMSI
-print sc.read_binary(['3f00', '7f20', '6f07'])
+print(sc.read_binary(['3f00', '7f20', '6f07']))
# Run A3/A8
-print sc.run_gsm('00112233445566778899aabbccddeeff')
+print(sc.run_gsm('00112233445566778899aabbccddeeff'))
diff --git a/pySim-prog.py b/pySim-prog.py
index b070c5e..bfb40b2 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -173,7 +173,7 @@
if options.type == 'list':
for kls in _cards_classes:
- print kls.name
+ print(kls.name)
sys.exit(0)
if options.probe:
@@ -560,7 +560,7 @@
for k in BATCH_INCOMPATIBLE:
if getattr(opts, k):
- print "Incompatible option with batch_state: %s" % (k,)
+ print("Incompatible option with batch_state: %s" % (k,))
sys.exit(-1)
# Don't load state if there is none ...
@@ -568,7 +568,7 @@
return
if not os.path.isfile(opts.batch_state):
- print "No state file yet"
+ print("No state file yet")
return
# Get stored data
@@ -601,12 +601,12 @@
for kls in _cards_classes:
card = kls.autodetect(scc)
if card:
- print "Autodetected card type: %s" % card.name
+ print("Autodetected card type: %s" % card.name)
card.reset()
break
if card is None:
- print "Autodetection failed"
+ print("Autodetection failed")
return
if opts.type == "auto_once":
@@ -631,7 +631,7 @@
# Get card
card = card_detect(opts, scc)
if card is None:
- print "No card detected!"
+ print("No card detected!")
return -1
# Probe only
@@ -640,7 +640,7 @@
# Erase if requested
if opts.erase:
- print "Formatting ..."
+ print("Formatting ...")
card.erase()
card.reset()
@@ -666,16 +666,16 @@
imsi = opts.imsi
cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
if cp is None:
- print "Error reading parameters from CSV file!\n"
+ print("Error reading parameters from CSV file!\n")
return 2
print_parameters(cp)
if opts.dry_run is False:
# Program the card
- print "Programming ..."
+ print("Programming ...")
card.program(cp)
else:
- print "Dry Run: NOT PROGRAMMING!"
+ print("Dry Run: NOT PROGRAMMING!")
# Write parameters permanently
write_parameters(opts, cp)
@@ -716,9 +716,9 @@
# If we use a CSV file as data input, check if the CSV file exists.
if opts.source == 'csv':
- print "Using CSV file as data input: " + str(opts.read_csv)
+ print("Using CSV file as data input: " + str(opts.read_csv))
if not os.path.isfile(opts.read_csv):
- print "CSV file not found!"
+ print("CSV file not found!")
sys.exit(1)
# Batch mode init
@@ -737,18 +737,18 @@
try:
rc = process_card(opts, first, card_handler)
except (KeyboardInterrupt):
- print ""
- print "Terminated by user!"
+ print("")
+ print("Terminated by user!")
sys.exit(0)
except (SystemExit):
raise
except:
- print ""
- print "Card programming failed with an execption:"
- print "---------------------8<---------------------"
+ print("")
+ print("Card programming failed with an execption:")
+ print("---------------------8<---------------------")
traceback.print_exc()
- print "---------------------8<---------------------"
- print ""
+ print("---------------------8<---------------------")
+ print("")
rc = -1
# Something did not work as well as expected, however, lets
diff --git a/pySim-read.py b/pySim-read.py
index 662ee54..b59b7f3 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -140,7 +140,7 @@
else:
print("PLMNsel: Can't read, response code = %s" % (sw,))
except Exception as e:
- print "HPLMNAcT: Can't read file -- " + str(e)
+ print("HPLMNAcT: Can't read file -- " + str(e))
# EF.PLMNwAcT
try:
@@ -150,7 +150,7 @@
else:
print("PLMNwAcT: Can't read, response code = %s" % (sw,))
except Exception as e:
- print "PLMNwAcT: Can't read file -- " + str(e)
+ print("PLMNwAcT: Can't read file -- " + str(e))
# EF.OPLMNwAcT
try:
@@ -160,7 +160,7 @@
else:
print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
except Exception as e:
- print "OPLMNwAcT: Can't read file -- " + str(e)
+ print("OPLMNwAcT: Can't read file -- " + str(e))
# EF.HPLMNAcT
try:
@@ -170,7 +170,7 @@
else:
print("HPLMNAcT: Can't read, response code = %s" % (sw,))
except Exception as e:
- print "HPLMNAcT: Can't read file -- " + str(e)
+ print("HPLMNAcT: Can't read file -- " + str(e))
# EF.ACC
(res, sw) = scc.read_binary(['3f00', '7f20', '6f78'])
@@ -191,7 +191,7 @@
else:
print("MSISDN: Can't read, response code = %s" % (sw,))
except Exception as e:
- print "MSISDN: Can't read file -- " + str(e)
+ print("MSISDN: Can't read file -- " + str(e))
# EF.AD
(res, sw) = scc.read_binary(['3f00', '7f20', '6fad'])
@@ -201,4 +201,4 @@
print("AD: Can't read, response code = %s" % (sw,))
# Done for this card and maybe for everything ?
- print "Done !\n"
+ print("Done !\n")
diff --git a/pySim/card_handler.py b/pySim/card_handler.py
index 46ec93e..bb33833 100644
--- a/pySim/card_handler.py
+++ b/pySim/card_handler.py
@@ -36,16 +36,16 @@
self.sl = sl
def get(self, first = False):
- print "Ready for Programming: Insert card now (or CTRL-C to cancel)"
+ print("Ready for Programming: Insert card now (or CTRL-C to cancel)")
self.sl.wait_for_card(newcardonly=not first)
def error(self):
- print "Programming failed: Remove card from reader"
- print ""
+ print("Programming failed: Remove card from reader")
+ print("")
def done(self):
- print "Programming successful: Remove card from reader"
- print ""
+ print("Programming successful: Remove card from reader")
+ print("")
# Automatic card handler: A machine is used to handle the cards.
class card_handler_auto:
@@ -55,7 +55,7 @@
verbose = True
def __init__(self, sl, config_file):
- print "Card handler Config-file: " + str(config_file)
+ print("Card handler Config-file: " + str(config_file))
self.sl = sl
with open(config_file) as cfg:
self.cmds = yaml.load(cfg, Loader=yaml.FullLoader)
@@ -63,22 +63,22 @@
self.verbose = (self.cmds.get('verbose') == True)
def __print_outout(self,out):
- print ""
- print "Card handler output:"
- print "---------------------8<---------------------"
+ print("")
+ print("Card handler output:")
+ print("---------------------8<---------------------")
stdout = out[0].strip()
if len(stdout) > 0:
- print "stdout:"
- print stdout
+ print("stdout:")
+ print(stdout)
stderr = out[1].strip()
if len(stderr) > 0:
- print "stderr:"
- print stderr
- print "---------------------8<---------------------"
- print ""
+ print("stderr:")
+ print(stderr)
+ print("---------------------8<---------------------")
+ print("")
def __exec_cmd(self, command):
- print "Card handler Commandline: " + str(command)
+ print("Card handler Commandline: " + str(command))
proc = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out = proc.communicate()
@@ -88,21 +88,21 @@
self.__print_outout(out)
if rc != 0:
- print ""
- print "Error: Card handler failure! (rc=" + str(rc) + ")"
+ print("")
+ print("Error: Card handler failure! (rc=" + str(rc) + ")")
sys.exit(rc)
def get(self, first = False):
- print "Ready for Programming: Transporting card into the reader-bay..."
+ print("Ready for Programming: Transporting card into the reader-bay...")
self.__exec_cmd(self.cmds['get'])
self.sl.connect()
def error(self):
- print "Programming failed: Transporting card to the error-bin..."
+ print("Programming failed: Transporting card to the error-bin...")
self.__exec_cmd(self.cmds['error'])
- print ""
+ print("")
def done(self):
- print "Programming successful: Transporting card into the collector bin..."
+ print("Programming successful: Transporting card into the collector bin...")
self.__exec_cmd(self.cmds['done'])
- print ""
+ print("")
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index 7a2bfd3..f672be2 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -162,7 +162,7 @@
def _dbg_print(self, s):
if self._debug:
- print s
+ print(s)
def _tx_byte(self, b):
self._sl.write(b)