diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2020-02-27 01:40:14 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2020-02-27 02:19:27 +0700 |
commit | edf873d04a0951b44598f781cd962e08476d7d0a (patch) | |
tree | f8adccff981979fe99d0e2b03d512b8201da7bcc | |
parent | fa617ac20d224fe65b84a44e0f1bb5e1a3535695 (diff) |
commands: Python 3 fix: properly distinguish str and list
Unlike Python 2, in Python 3 strings also have attribute '__iter__'.
Because of that, a string could be passed to select_file(), that
actually expects a list as the first parameter.
P.S. Madness, Python 3 is just a new different language...
P.P.S. They should have renamed it not to confuse people.
Change-Id: I92af47abb6adff0271c55e7f278e8c5188f2be75
Fixes: OS#4419
-rw-r--r-- | pySim/commands.py | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/pySim/commands.py b/pySim/commands.py index ff64ed2..cc7acc6 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -102,6 +102,8 @@ class SimCardCommands(object): def select_file(self, dir_list): rv = [] + if type(dir_list) is not list: + dir_list = [dir_list] for i in dir_list: data, sw = self._tp.send_apdu_checksw(self.cla_byte + "a4" + self.sel_ctrl + "02" + i) rv.append(data) @@ -112,8 +114,6 @@ class SimCardCommands(object): return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid) def read_binary(self, ef, length=None, offset=0): - if not hasattr(type(ef), '__iter__'): - ef = [ef] r = self.select_file(ef) if len(r[-1]) == 0: return (None, None) @@ -123,23 +123,17 @@ class SimCardCommands(object): return self._tp.send_apdu(pdu) def update_binary(self, ef, data, offset=0): - if not hasattr(type(ef), '__iter__'): - ef = [ef] self.select_file(ef) 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): - if not hasattr(type(ef), '__iter__'): - ef = [ef] r = self.select_file(ef) rec_length = self.__record_len(r) pdu = self.cla_byte + 'b2%02x04%02x' % (rec_no, rec_length) return self._tp.send_apdu(pdu) def update_record(self, ef, rec_no, data, force_len=False): - if not hasattr(type(ef), '__iter__'): - ef = [ef] r = self.select_file(ef) if not force_len: rec_length = self.__record_len(r) |