This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
gnutoo gerrit-no-reply at lists.osmocom.orggnutoo has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/15502
Change subject: python3 conversion: Use braces around print calls
......................................................................
python3 conversion: Use braces around print calls
This is required to run under python3.
Without it we have errors that looks like that:
$ python3 pySim-read.py
File "pySim-read.py", line 132
print "HPLMNAcT: Can't read file -- " + str(e)
SyntaxError: invalid syntax
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
Change-Id: Ia472baa8c14b87fe917ea52a998d5ccda66d20d1
---
M pySim-prog.py
M pySim-read.py
M pySim/cards.py
M pySim/commands.py
M pySim/transport/__init__.py
M pySim/transport/serial.py
6 files changed, 132 insertions(+), 132 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/02/15502/1
diff --git a/pySim-prog.py b/pySim-prog.py
index 8abce0a..bb7160e 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -127,7 +127,7 @@
)
parser.add_option("--acc", dest="acc",
help="Set ACC bits (Access Control Code). not all card types are supported",
- )
+ )
parser.add_option("--read-imsi", dest="read_imsi", action="store_true",
help="Read the IMSI from the CARD", default=False
)
@@ -167,11 +167,11 @@
if options.type == 'list':
for kls in _cards_classes:
- print kls.name
+ print(kls.name)
sys.exit(0)
- if options.probe:
- return options
+ if options.probe:
+ return options
if options.source == 'csv':
if (options.imsi is None) and (options.batch_mode is False) and (options.read_imsi is False) and (options.read_iccid is False):
@@ -393,7 +393,7 @@
else:
raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
- if opts.pin_adm_hex is not None:
+ if opts.pin_adm_hex is not None:
if len(opts.pin_adm_hex) == 16:
pin_adm = opts.pin_adm_hex
# Ensure that it's hex-encoded
@@ -452,8 +452,8 @@
f = open(opts.read_csv, 'r')
cr = csv.DictReader(f)
i = 0
- if not 'iccid' in cr.fieldnames:
- raise Exception("CSV file in wrong format!")
+ if not 'iccid' in cr.fieldnames:
+ raise Exception("CSV file in wrong format!")
for row in cr:
if opts.num is not None and opts.read_iccid is False and opts.read_imsi is False:
if opts.num == i:
@@ -534,7 +534,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 ...
@@ -542,7 +542,7 @@
return
if not os.path.isfile(opts.batch_state):
- print "No state file yet"
+ print("No state file yet")
return
# Get stored data
@@ -575,12 +575,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":
@@ -632,7 +632,7 @@
if opts.dry_run is False:
# Connect transport
- print "Insert card now (or CTRL-C to cancel)"
+ print("Insert card now (or CTRL-C to cancel)")
sl.wait_for_card(newcardonly=not first)
# Not the first anymore !
@@ -648,13 +648,13 @@
else:
sys.exit(-1)
- # Probe only
- if opts.probe:
- break;
+ # Probe only
+ if opts.probe:
+ break;
# Erase if requested
if opts.erase:
- print "Formatting ..."
+ print("Formatting ...")
card.erase()
card.reset()
@@ -662,20 +662,20 @@
if opts.source == 'cmdline':
cp = gen_parameters(opts)
elif opts.source == 'csv':
- imsi = None
- iccid = None
+ imsi = None
+ iccid = None
if opts.read_iccid:
if opts.dry_run:
# Connect transport
- print "Insert card now (or CTRL-C to cancel)"
+ print("Insert card now (or CTRL-C to cancel)")
sl.wait_for_card(newcardonly=not first)
(res,_) = scc.read_binary(['3f00', '2fe2'], length=10)
iccid = dec_iccid(res)
- print iccid
- elif opts.read_imsi:
+ print(iccid)
+ elif opts.read_imsi:
if opts.dry_run:
# Connect transport
- print "Insert card now (or CTRL-C to cancel)"
+ print("Insert card now (or CTRL-C to cancel)")
sl.wait_for_card(newcardonly=not first)
(res,_) = scc.read_binary(EF['IMSI'])
imsi = swap_nibbles(res)[3:]
@@ -683,17 +683,17 @@
imsi = opts.imsi
cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
if cp is None:
- print "Error reading parameters\n"
+ print("Error reading parameters\n")
sys.exit(2)
print_parameters(cp)
if opts.dry_run is False:
# Program the card
- print "Programming ..."
+ print("Programming ...")
if opts.dry_run is not True:
card.program(cp)
else:
- print "Dry Run: NOT PROGRAMMING!"
+ print("Dry Run: NOT PROGRAMMING!")
# Write parameters permanently
write_parameters(opts, cp)
@@ -704,7 +704,7 @@
save_batch(opts)
# Done for this card and maybe for everything ?
- print "Done !\n"
+ print("Done !\n")
if not opts.batch_mode:
done = True
diff --git a/pySim-read.py b/pySim-read.py
index 17fce61..6b2fed6 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -123,43 +123,43 @@
# EF.PLMNsel
try:
- (res, sw) = scc.read_binary(EF['PLMNsel'])
- if sw == '9000':
- print("PLMNsel: %s" % (res))
- else:
- print("PLMNsel: Can't read, response code = %s" % (sw,))
+ (res, sw) = scc.read_binary(EF['PLMNsel'])
+ if sw == '9000':
+ print("PLMNsel: %s" % (res))
+ 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:
- (res, sw) = scc.read_binary(EF['PLMNwAcT'])
- if sw == '9000':
- print("PLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
- else:
- print("PLMNwAcT: Can't read, response code = %s" % (sw,))
+ try:
+ (res, sw) = scc.read_binary(EF['PLMNwAcT'])
+ if sw == '9000':
+ print("PLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
+ 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:
- (res, sw) = scc.read_binary(EF['OPLMNwAcT'])
- if sw == '9000':
- print("OPLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
- else:
- print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
+ try:
+ (res, sw) = scc.read_binary(EF['OPLMNwAcT'])
+ if sw == '9000':
+ print("OPLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
+ 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:
- (res, sw) = scc.read_binary(EF['HPLMNAcT'])
- if sw == '9000':
- print("HPLMNAcT:\n%s" % (format_xplmn_w_act(res)))
- else:
- print("HPLMNAcT: Can't read, response code = %s" % (sw,))
+ try:
+ (res, sw) = scc.read_binary(EF['HPLMNAcT'])
+ if sw == '9000':
+ print("HPLMNAcT:\n%s" % (format_xplmn_w_act(res)))
+ 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'])
@@ -180,7 +180,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'])
@@ -190,4 +190,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/cards.py b/pySim/cards.py
index cda337a..41723c4 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -85,11 +85,11 @@
def update_oplmn_act(self, mcc, mnc, access_tech='FFFF'):
"""
- See note in update_hplmn_act()
+ See note in update_hplmn_act()
"""
# get size and write EF.OPLMNwAcT
- data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
- size = len(data[0])/2
+ data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
+ size = len(data[0])/2
hplmn = enc_plmn(mcc, mnc)
content = hplmn + access_tech
data, sw = self._scc.update_binary(EF['OPLMNwAcT'], content + 'ffffff0000' * (size/5-1))
@@ -97,19 +97,19 @@
def update_plmn_act(self, mcc, mnc, access_tech='FFFF'):
"""
- See note in update_hplmn_act()
+ See note in update_hplmn_act()
"""
# get size and write EF.PLMNwAcT
- data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
- size = len(data[0])/2
+ data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
+ size = len(data[0])/2
hplmn = enc_plmn(mcc, mnc)
content = hplmn + access_tech
data, sw = self._scc.update_binary(EF['PLMNwAcT'], content + 'ffffff0000' * (size/5-1))
return sw
- def update_plmnsel(self, mcc, mnc):
- data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
- size = len(data[0])/2
+ def update_plmnsel(self, mcc, mnc):
+ data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
+ size = len(data[0])/2
hplmn = enc_plmn(mcc, mnc)
data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
return sw
@@ -119,16 +119,16 @@
return sw
def update_ad(self, mnc):
- #See also: 3GPP TS 31.102, chapter 4.2.18
- mnclen = len(str(mnc))
- if mnclen == 1:
- mnclen = 2
- if mnclen > 3:
+ #See also: 3GPP TS 31.102, chapter 4.2.18
+ mnclen = len(str(mnc))
+ if mnclen == 1:
+ mnclen = 2
+ if mnclen > 3:
raise RuntimeError('unable to calculate proper mnclen')
- data = self._scc.read_binary(EF['AD'], length=None, offset=0)
- size = len(data[0])/2
- content = data[0][0:6] + "%02X" % mnclen
+ data = self._scc.read_binary(EF['AD'], length=None, offset=0)
+ size = len(data[0])/2
+ content = data[0][0:6] + "%02X" % mnclen
data, sw = self._scc.update_binary(EF['AD'], content)
return sw
@@ -394,7 +394,7 @@
data, sw = self._scc.update_binary('6f78', lpad(p['acc'], 4))
# EF.SMSP
- if p.get('smsp'):
+ if p.get('smsp'):
r = self._scc.select_file(['3f00', '7f10', '6f42'])
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
@@ -426,7 +426,7 @@
"""
name = 'sysmosim-gr1'
- @classmethod
+ @classmethod
def autodetect(kls, scc):
try:
# Look for ATR
@@ -536,7 +536,7 @@
r = self._scc.select_file(['3f00', '7f10'])
# write EF.SMSP
- if p.get('smsp'):
+ if p.get('smsp'):
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
def erase(self):
@@ -592,25 +592,25 @@
data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
# EF.PLMNsel
- if p.get('mcc') and p.get('mnc'):
- sw = self.update_plmnsel(p['mcc'], p['mnc'])
- if sw != '9000':
+ if p.get('mcc') and p.get('mnc'):
+ sw = self.update_plmnsel(p['mcc'], p['mnc'])
+ if sw != '9000':
print("Programming PLMNsel failed with code %s"%sw)
- # EF.PLMNwAcT
- if p.get('mcc') and p.get('mnc'):
+ # EF.PLMNwAcT
+ if p.get('mcc') and p.get('mnc'):
sw = self.update_plmn_act(p['mcc'], p['mnc'])
if sw != '9000':
print("Programming PLMNwAcT failed with code %s"%sw)
- # EF.OPLMNwAcT
- if p.get('mcc') and p.get('mnc'):
+ # EF.OPLMNwAcT
+ if p.get('mcc') and p.get('mnc'):
sw = self.update_oplmn_act(p['mcc'], p['mnc'])
if sw != '9000':
print("Programming OPLMNwAcT failed with code %s"%sw)
- # EF.AD
- if p.get('mcc') and p.get('mnc'):
+ # EF.AD
+ if p.get('mcc') and p.get('mnc'):
sw = self.update_ad(p['mnc'])
if sw != '9000':
print("Programming AD failed with code %s"%sw)
@@ -848,28 +848,28 @@
if sw != '9000':
raise RuntimeError('Failed to authenticate with ADM key %s'%(p['pin_adm'],))
- # EF.ICCID
- # TODO: Add programming of the ICCID
- if p.get('iccid'):
+ # EF.ICCID
+ # TODO: Add programming of the ICCID
+ if p.get('iccid'):
print("Warning: Programming of the ICCID is not implemented for this type of card.")
- # KI (Presumably a propritary file)
- # TODO: Add programming of KI
- if p.get('ki'):
+ # KI (Presumably a propritary file)
+ # TODO: Add programming of KI
+ if p.get('ki'):
print("Warning: Programming of the KI is not implemented for this type of card.")
- # OPc (Presumably a propritary file)
- # TODO: Add programming of OPc
- if p.get('opc'):
+ # OPc (Presumably a propritary file)
+ # TODO: Add programming of OPc
+ if p.get('opc'):
print("Warning: Programming of the OPc is not implemented for this type of card.")
- # EF.SMSP
+ # EF.SMSP
if p.get('smsp'):
sw = self.update_smsp(p['smsp'])
if sw != '9000':
print("Programming SMSP failed with code %s"%sw)
- # EF.IMSI
+ # EF.IMSI
if p.get('imsi'):
sw = self.update_imsi(p['imsi'])
if sw != '9000':
@@ -882,30 +882,30 @@
print("Programming ACC failed with code %s"%sw)
# EF.PLMNsel
- if p.get('mcc') and p.get('mnc'):
- sw = self.update_plmnsel(p['mcc'], p['mnc'])
- if sw != '9000':
+ if p.get('mcc') and p.get('mnc'):
+ sw = self.update_plmnsel(p['mcc'], p['mnc'])
+ if sw != '9000':
print("Programming PLMNsel failed with code %s"%sw)
- # EF.PLMNwAcT
- if p.get('mcc') and p.get('mnc'):
+ # EF.PLMNwAcT
+ if p.get('mcc') and p.get('mnc'):
sw = self.update_plmn_act(p['mcc'], p['mnc'])
if sw != '9000':
print("Programming PLMNwAcT failed with code %s"%sw)
- # EF.OPLMNwAcT
- if p.get('mcc') and p.get('mnc'):
+ # EF.OPLMNwAcT
+ if p.get('mcc') and p.get('mnc'):
sw = self.update_oplmn_act(p['mcc'], p['mnc'])
if sw != '9000':
print("Programming OPLMNwAcT failed with code %s"%sw)
- # EF.AD
- if p.get('mcc') and p.get('mnc'):
+ # EF.AD
+ if p.get('mcc') and p.get('mnc'):
sw = self.update_ad(p['mnc'])
if sw != '9000':
print("Programming AD failed with code %s"%sw)
- return None
+ return None
def erase(self):
return
diff --git a/pySim/commands.py b/pySim/commands.py
index 3d17903..03540b6 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -34,7 +34,7 @@
def __get_len_from_tlv(self, fcp):
# see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF,
# DF or ADF
- from pytlv.TLV import TLV
+ from pytlv.TLV import TLV
tlvparser = TLV(['82', '83', '84', 'a5', '8a', '8b', '8c', '80', 'ab', 'c6', '81', '88'])
# pytlv is case sensitive!
@@ -62,24 +62,24 @@
return int(tlv_parsed['80'], 16)
- # Tell the length of a record by the card response
- # USIMs respond with an FCP template, which is different
- # from what SIMs responds. See also:
- # USIM: ETSI TS 102 221, chapter 11.1.1.3 Response Data
- # SIM: GSM 11.11, chapter 9.2.1 SELECT
+ # Tell the length of a record by the card response
+ # USIMs respond with an FCP template, which is different
+ # from what SIMs responds. See also:
+ # USIM: ETSI TS 102 221, chapter 11.1.1.3 Response Data
+ # SIM: GSM 11.11, chapter 9.2.1 SELECT
def __record_len(self, r):
- if self.sel_ctrl == "0004":
- return self.__get_len_from_tlv(r[-1])
- else:
- return int(r[-1][28:30], 16)
+ if self.sel_ctrl == "0004":
+ return self.__get_len_from_tlv(r[-1])
+ else:
+ return int(r[-1][28:30], 16)
- # Tell the length of a binary file. See also comment
- # above.
+ # Tell the length of a binary file. See also comment
+ # above.
def __len(self, r):
- if self.sel_ctrl == "0004":
- return self.__get_len_from_tlv(r[-1])
- else:
- return int(r[-1][4:8], 16)
+ if self.sel_ctrl == "0004":
+ return self.__get_len_from_tlv(r[-1])
+ else:
+ return int(r[-1][4:8], 16)
def get_atr(self):
return self._tp.get_atr()
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 4b932cd..69e2fe9 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -28,7 +28,7 @@
timeout : Maximum wait time (None=no timeout)
newcardonly : Should we wait for a new card, or an already
- inserted one ?
+ inserted one ?
"""
pass
@@ -52,8 +52,8 @@
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
return : tuple(data, sw), where
- data : string (in hex) of returned data (ex. "074F4EFFFF")
- sw : string (in hex) of status word (ex. "9000")
+ data : string (in hex) of returned data (ex. "074F4EFFFF")
+ sw : string (in hex) of status word (ex. "9000")
"""
pass
@@ -62,8 +62,8 @@
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
return : tuple(data, sw), where
- data : string (in hex) of returned data (ex. "074F4EFFFF")
- sw : string (in hex) of status word (ex. "9000")
+ data : string (in hex) of returned data (ex. "074F4EFFFF")
+ sw : string (in hex) of status word (ex. "9000")
"""
data, sw = self.send_apdu_raw(pdu)
@@ -84,15 +84,15 @@
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
sw : string of 4 hexadecimal characters (ex. "9000"). The
- user may mask out certain digits using a '?' to add some
- ambiguity if needed.
+ user may mask out certain digits using a '?' to add some
+ ambiguity if needed.
return : tuple(data, sw), where
- data : string (in hex) of returned data (ex. "074F4EFFFF")
- sw : string (in hex) of status word (ex. "9000")
+ data : string (in hex) of returned data (ex. "074F4EFFFF")
+ sw : string (in hex) of status word (ex. "9000")
"""
rv = self.send_apdu(pdu)
- # Create a masked version of the returned status word
+ # Create a masked version of the returned status word
sw_masked = ""
for i in range(0, 4):
if sw.lower()[i] == '?':
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)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/15502
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia472baa8c14b87fe917ea52a998d5ccda66d20d1
Gerrit-Change-Number: 15502
Gerrit-PatchSet: 1
Gerrit-Owner: gnutoo <GNUtoo at cyberdimension.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190912/4e96bd4c/attachment.htm>