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/.
fixeria gerrit-no-reply at lists.osmocom.orgfixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/17152 ) Change subject: Py2 -> Py3: use the floor division operator // where possible ...................................................................... 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 --- M pySim/cards.py M pySim/commands.py M pySim/transport/serial.py 3 files changed, 12 insertions(+), 12 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/52/17152/1 diff --git a/pySim/cards.py b/pySim/cards.py index faaeca3..b30e449 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -89,7 +89,7 @@ """ # 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 @@ """ # 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 @@ 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 @@ 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 @@ # 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 @@ 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 @@ 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 @@ 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 @@ 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 = '' -- To view, visit https://gerrit.osmocom.org/c/pysim/+/17152 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I5565eb64a1ddea7075cbb142eaacaa5d494c87bb Gerrit-Change-Number: 17152 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <axilirator at gmail.com> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200214/0ce9899f/attachment.htm>