aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2020-02-15 05:03:09 +0700
committerlaforge <laforge@osmocom.org>2020-02-15 19:11:50 +0000
commit99affe1529a6f8863275a8f0a7996f7f5bf3ab0b (patch)
tree2abf74fd2f10a9dbd0c59490ab6e651e29f8f630
parent4133080ced5f13c1bdc7523e8c16e5020a521a36 (diff)
Py2 -> Py3: use the floor division operator // where possible
In Python 3, traditional division operator returns a float, while we need a floor integer in the most cases. Change-Id: I5565eb64a1ddea7075cbb142eaacaa5d494c87bb
-rw-r--r--pySim/cards.py8
-rw-r--r--pySim/commands.py14
-rw-r--r--pySim/transport/serial.py2
3 files changed, 12 insertions, 12 deletions
diff --git a/pySim/cards.py b/pySim/cards.py
index b4b5fdf..053ea98 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -89,7 +89,7 @@ class Card(object):
"""
# get size and write EF.OPLMNwAcT
data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
- size = len(data[0])/2
+ 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))
@@ -101,7 +101,7 @@ class Card(object):
"""
# get size and write EF.PLMNwAcT
data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
- size = len(data[0])/2
+ 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))
@@ -109,7 +109,7 @@ class Card(object):
def update_plmnsel(self, mcc, mnc):
data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
- size = len(data[0])/2
+ size = len(data[0]) // 2
hplmn = enc_plmn(mcc, mnc)
data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
return sw
@@ -127,7 +127,7 @@ class Card(object):
raise RuntimeError('unable to calculate proper mnclen')
data = self._scc.read_binary(EF['AD'], length=None, offset=0)
- size = len(data[0])/2
+ size = len(data[0]) // 2
content = data[0][0:6] + "%02X" % mnclen
data, sw = self._scc.update_binary(EF['AD'], content)
return sw
diff --git a/pySim/commands.py b/pySim/commands.py
index 385cacf..ff64ed2 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -49,11 +49,11 @@ class SimCardCommands(object):
# what we get in the length field.
# See also ETSI TS 102 221, chapter 11.1.1.3.0 Base coding.
exp_tlv_len = int(fcp[2:4], 16)
- if len(fcp[4:])/2 == exp_tlv_len:
+ if len(fcp[4:]) // 2 == exp_tlv_len:
skip = 4
else:
exp_tlv_len = int(fcp[2:6], 16)
- if len(fcp[4:])/2 == exp_tlv_len:
+ if len(fcp[4:]) // 2 == exp_tlv_len:
skip = 6
# Skip FCP tag and length
@@ -108,7 +108,7 @@ class SimCardCommands(object):
return rv
def select_adf(self, aid):
- aidlen = ("0" + format(len(aid)/2, 'x'))[-2:]
+ aidlen = ("0" + format(len(aid) // 2, 'x'))[-2:]
return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid)
def read_binary(self, ef, length=None, offset=0):
@@ -126,7 +126,7 @@ class SimCardCommands(object):
if not hasattr(type(ef), '__iter__'):
ef = [ef]
self.select_file(ef)
- pdu = self.cla_byte + 'd6%04x%02x' % (offset, len(data)/2) + data
+ pdu = self.cla_byte + 'd6%04x%02x' % (offset, len(data) // 2) + data
return self._tp.send_apdu_checksw(pdu)
def read_record(self, ef, rec_no):
@@ -143,10 +143,10 @@ class SimCardCommands(object):
r = self.select_file(ef)
if not force_len:
rec_length = self.__record_len(r)
- if (len(data)/2 != rec_length):
- raise ValueError('Invalid data length (expected %d, got %d)' % (rec_length, len(data)/2))
+ if (len(data) // 2 != rec_length):
+ raise ValueError('Invalid data length (expected %d, got %d)' % (rec_length, len(data) // 2))
else:
- rec_length = len(data)/2
+ rec_length = len(data) // 2
pdu = (self.cla_byte + 'dc%02x04%02x' % (rec_no, rec_length)) + data
return self._tp.send_apdu_checksw(pdu)
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index f672be2..11fcd6a 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -213,7 +213,7 @@ class SerialSimLink(LinkBase):
self._tx_string(pdu[5:])
# Receive data (including SW !)
- # length = [P3 - tx_data (=len(pdu)-len(hdr)) + 2 (SW1/2) ]
+ # length = [P3 - tx_data (=len(pdu)-len(hdr)) + 2 (SW1//2) ]
to_recv = data_len - len(pdu) + 5 + 2
data = ''