mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-30 02:51:47 +03:00
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
This commit is contained in:
@@ -89,7 +89,7 @@ class Card(object):
|
|||||||
"""
|
"""
|
||||||
# get size and write EF.OPLMNwAcT
|
# get size and write EF.OPLMNwAcT
|
||||||
data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
|
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)
|
hplmn = enc_plmn(mcc, mnc)
|
||||||
content = hplmn + access_tech
|
content = hplmn + access_tech
|
||||||
data, sw = self._scc.update_binary(EF['OPLMNwAcT'], content + 'ffffff0000' * (size/5-1))
|
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
|
# get size and write EF.PLMNwAcT
|
||||||
data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
|
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)
|
hplmn = enc_plmn(mcc, mnc)
|
||||||
content = hplmn + access_tech
|
content = hplmn + access_tech
|
||||||
data, sw = self._scc.update_binary(EF['PLMNwAcT'], content + 'ffffff0000' * (size/5-1))
|
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):
|
def update_plmnsel(self, mcc, mnc):
|
||||||
data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
|
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)
|
hplmn = enc_plmn(mcc, mnc)
|
||||||
data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
|
data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
|
||||||
return sw
|
return sw
|
||||||
@@ -127,7 +127,7 @@ class Card(object):
|
|||||||
raise RuntimeError('unable to calculate proper mnclen')
|
raise RuntimeError('unable to calculate proper mnclen')
|
||||||
|
|
||||||
data = self._scc.read_binary(EF['AD'], length=None, offset=0)
|
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
|
content = data[0][0:6] + "%02X" % mnclen
|
||||||
data, sw = self._scc.update_binary(EF['AD'], content)
|
data, sw = self._scc.update_binary(EF['AD'], content)
|
||||||
return sw
|
return sw
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ class SimCardCommands(object):
|
|||||||
# what we get in the length field.
|
# what we get in the length field.
|
||||||
# See also ETSI TS 102 221, chapter 11.1.1.3.0 Base coding.
|
# See also ETSI TS 102 221, chapter 11.1.1.3.0 Base coding.
|
||||||
exp_tlv_len = int(fcp[2:4], 16)
|
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
|
skip = 4
|
||||||
else:
|
else:
|
||||||
exp_tlv_len = int(fcp[2:6], 16)
|
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 = 6
|
||||||
|
|
||||||
# Skip FCP tag and length
|
# Skip FCP tag and length
|
||||||
@@ -108,7 +108,7 @@ class SimCardCommands(object):
|
|||||||
return rv
|
return rv
|
||||||
|
|
||||||
def select_adf(self, aid):
|
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)
|
return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid)
|
||||||
|
|
||||||
def read_binary(self, ef, length=None, offset=0):
|
def read_binary(self, ef, length=None, offset=0):
|
||||||
@@ -126,7 +126,7 @@ class SimCardCommands(object):
|
|||||||
if not hasattr(type(ef), '__iter__'):
|
if not hasattr(type(ef), '__iter__'):
|
||||||
ef = [ef]
|
ef = [ef]
|
||||||
self.select_file(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)
|
return self._tp.send_apdu_checksw(pdu)
|
||||||
|
|
||||||
def read_record(self, ef, rec_no):
|
def read_record(self, ef, rec_no):
|
||||||
@@ -143,10 +143,10 @@ class SimCardCommands(object):
|
|||||||
r = self.select_file(ef)
|
r = self.select_file(ef)
|
||||||
if not force_len:
|
if not force_len:
|
||||||
rec_length = self.__record_len(r)
|
rec_length = self.__record_len(r)
|
||||||
if (len(data)/2 != rec_length):
|
if (len(data) // 2 != rec_length):
|
||||||
raise ValueError('Invalid data length (expected %d, got %d)' % (rec_length, len(data)/2))
|
raise ValueError('Invalid data length (expected %d, got %d)' % (rec_length, len(data) // 2))
|
||||||
else:
|
else:
|
||||||
rec_length = len(data)/2
|
rec_length = len(data) // 2
|
||||||
pdu = (self.cla_byte + 'dc%02x04%02x' % (rec_no, rec_length)) + data
|
pdu = (self.cla_byte + 'dc%02x04%02x' % (rec_no, rec_length)) + data
|
||||||
return self._tp.send_apdu_checksw(pdu)
|
return self._tp.send_apdu_checksw(pdu)
|
||||||
|
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ class SerialSimLink(LinkBase):
|
|||||||
self._tx_string(pdu[5:])
|
self._tx_string(pdu[5:])
|
||||||
|
|
||||||
# Receive data (including SW !)
|
# 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
|
to_recv = data_len - len(pdu) + 5 + 2
|
||||||
|
|
||||||
data = ''
|
data = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user