laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35847?usp=email )
Change subject: pylint: filesystem.py
......................................................................
pylint: filesystem.py
pySim/filesystem.py:823:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
pySim/filesystem.py:849:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
pySim/filesystem.py:43:0: W0401: Wildcard import pySim.exceptions (wildcard-import)
pySim/filesystem.py:74:45: C0121: Comparison 'fid == None' should be 'fid is None' (singleton-comparison)
pySim/filesystem.py:94:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
pySim/filesystem.py:100:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
pySim/filesystem.py:149:8: W0105: String statement has no effect (pointless-string-statement)
pySim/filesystem.py:170:11: C0121: Comparison 'self.parent == None' should be 'self.parent is None' (singleton-comparison)
pySim/filesystem.py:283:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:309:8: W0246: Useless parent or super() delegation in method '__init__' (useless-parent-delegation)
pySim/filesystem.py:314:15: C0117: Consider changing "not 'fid' in kwargs" to "'fid' not in kwargs" (unnecessary-negation)
pySim/filesystem.py:317:24: R1735: Consider using '{}' instead of a call to 'dict'. (use-dict-literal)
pySim/filesystem.py:418:11: C0121: Comparison 'name == None' should be 'name is None' (singleton-comparison)
pySim/filesystem.py:427:11: C0121: Comparison 'sfid == None' should be 'sfid is None' (singleton-comparison)
pySim/filesystem.py:452:28: R1735: Consider using '{}' instead of a call to 'dict'. (use-dict-literal)
pySim/filesystem.py:508:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
pySim/filesystem.py:531:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
pySim/filesystem.py:576:8: W0246: Useless parent or super() delegation in method '__init__' (useless-parent-delegation)
pySim/filesystem.py:599:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:609:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:620:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:633:28: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:642:41: W0613: Unused argument 'opts' (unused-argument)
pySim/filesystem.py:644:24: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:696:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:723:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:749:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:777:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:797:8: W0246: Useless parent or super() delegation in method '__init__' (useless-parent-delegation)
pySim/filesystem.py:822:23: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:838:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:844:34: W0613: Unused argument 'opts' (unused-argument)
pySim/filesystem.py:848:23: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:866:23: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:878:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:893:28: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:910:24: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:967:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:995:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1023:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1051:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1114:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1141:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1167:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1194:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/filesystem.py:1226:8: W0246: Useless parent or super() delegation in method '__init__' (useless-parent-delegation)
pySim/filesystem.py:1236:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:1239:35: W0613: Unused argument 'opts' (unused-argument)
pySim/filesystem.py:1252:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:1263:19: W0612: Unused variable 'sw' (unused-variable)
pySim/filesystem.py:1315:24: R1735: Consider using '{}' instead of a call to 'dict'. (use-dict-literal)
pySim/filesystem.py:35:0: C0411: standard import "import argparse" should be placed before "import cmd2" (wrong-import-order)
pySim/filesystem.py:37:0: C0411: standard import "from typing import cast, Optional, Iterable, List, Dict, Tuple, Union" should be placed before "import cmd2" (wrong-import-order)
pySim/filesystem.py:27:0: W0611: Unused import code (unused-import)
pySim/filesystem.py:34:0: W0611: Unused with_argparser imported from cmd2 (unused-import)
pySim/filesystem.py:41:0: W0611: Unused i2h imported from pySim.utils (unused-import)
pySim/filesystem.py:41:0: W0611: Unused Hexstr imported from pySim.utils (unused-import)
pySim/filesystem.py:44:0: W0611: Unused js_path_find imported from pySim.jsonpath (unused-import)
pySim/filesystem.py:43:0: W0614: Unused import(s) NoCardError, ProtocolError, ReaderError and SwMatchError from wildcard import of pySim.exceptions (unused-wildcard-import)
Change-Id: I94e1f5791e9fc34a60d0254978a35fd6ab2ff8d7
---
M pySim/filesystem.py
1 file changed, 124 insertions(+), 71 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/47/35847/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 47bdb57..4d5fde9 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -24,24 +24,20 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import code
+from typing import cast, Optional, Iterable, List, Dict, Tuple, Union
+import argparse
import tempfile
import json
import abc
import inspect
import cmd2
-from cmd2 import CommandSet, with_default_category, with_argparser
-import argparse
-
-from typing import cast, Optional, Iterable, List, Dict, Tuple, Union
-
+from cmd2 import CommandSet, with_default_category
from smartcard.util import toBytes
-from pySim.utils import sw_match, h2b, b2h, i2h, is_hex, auto_int, auto_uint8, auto_uint16, Hexstr, is_hexstr
+from pySim.utils import sw_match, h2b, b2h, is_hex, auto_int, auto_uint8, auto_uint16, is_hexstr
from pySim.construct import filter_dict, parse_construct, build_construct
-from pySim.exceptions import *
-from pySim.jsonpath import js_path_find, js_path_modify
+from pySim.jsonpath import js_path_modify
from pySim.commands import SimCardCommands
# int: a single service is associated with this file
@@ -71,7 +67,7 @@
profile : Card profile that this file should be part of
service : Service (SST/UST/IST) associated with the file
"""
- if not isinstance(self, CardADF) and fid == None:
+ if not isinstance(self, CardADF) and fid is None:
raise ValueError("fid is mandatory")
if fid:
fid = fid.lower()
@@ -136,6 +132,7 @@
return ret
def build_select_path_to(self, target: 'CardFile') -> Optional[List['CardFile']]:
+ """Build the relative sequence of files we need to traverse to get from us to 'target'."""
# special-case handling for applications. Applications may be selected
# any time from any location. If there is an ADF somewhere in the path,
@@ -146,7 +143,6 @@
return inter_path[i:]
return inter_path
- """Build the relative sequence of files we need to traverse to get from us to 'target'."""
# special-case handling for selecting MF while the MF is selected
if target == target.get_mf():
return [target]
@@ -167,7 +163,7 @@
def get_mf(self) -> Optional['CardMF']:
"""Return the MF (root) of the file system."""
- if self.parent == None:
+ if self.parent is None:
return None
# iterate towards the top. MF has parent == self
node = self
@@ -282,23 +278,22 @@
"""Assuming the provided list of activated services, should this file exist and be activated?."""
if self.service is None:
return None
- elif isinstance(self.service, int):
+ if isinstance(self.service, int):
# a single service determines the result
return self.service in services
- elif isinstance(self.service, list):
+ if isinstance(self.service, list):
# any of the services active -> true
for s in self.service:
if s in services:
return True
return False
- elif isinstance(self.service, tuple):
+ if isinstance(self.service, tuple):
# all of the services active -> true
for s in self.service:
if not s in services:
return False
return True
- else:
- raise ValueError("self.service must be either int or list or tuple")
+ raise ValueError("self.service must be either int or list or tuple")
class CardDF(CardFile):
@@ -306,15 +301,14 @@
@with_default_category('DF/ADF Commands')
class ShellCommands(CommandSet):
- def __init__(self):
- super().__init__()
+ pass
def __init__(self, **kwargs):
if not isinstance(self, CardADF):
- if not 'fid' in kwargs:
+ if 'fid' not in kwargs:
raise TypeError('fid is mandatory for all DF')
super().__init__(**kwargs)
- self.children = dict()
+ self.children = {}
self.shell_commands = [self.ShellCommands()]
# dict of CardFile affected by service(int), indexed by service
self.files_by_service = {}
@@ -415,7 +409,7 @@
def lookup_file_by_name(self, name: Optional[str]) -> Optional[CardFile]:
"""Find a file with given name within current DF."""
- if name == None:
+ if name is None:
return None
for i in self.children.values():
if i.name and i.name == name:
@@ -424,7 +418,7 @@
def lookup_file_by_sfid(self, sfid: Optional[str]) -> Optional[CardFile]:
"""Find a file with given short file ID within current DF."""
- if sfid == None:
+ if sfid is None:
return None
for i in self.children.values():
if i.sfid == int(str(sfid)):
@@ -449,7 +443,7 @@
# cannot be overridden; use assignment
kwargs['parent'] = self
super().__init__(**kwargs)
- self.applications = dict()
+ self.applications = {}
def __str__(self):
return "MF(%s)" % (self.fid)
@@ -573,9 +567,6 @@
class ShellCommands(CommandSet):
"""Shell commands specific for transparent EFs."""
- def __init__(self):
- super().__init__()
-
dec_hex_parser = argparse.ArgumentParser()
dec_hex_parser.add_argument('--oneline', action='store_true',
help='No JSON pretty-printing, dump as a single line')
@@ -596,7 +587,7 @@
@cmd2.with_argparser(read_bin_parser)
def do_read_binary(self, opts):
"""Read binary data from a transparent EF"""
- (data, sw) = self._cmd.lchan.read_binary(opts.length, opts.offset)
+ (data, _sw) = self._cmd.lchan.read_binary(opts.length, opts.offset)
self._cmd.poutput(data)
read_bin_dec_parser = argparse.ArgumentParser()
@@ -606,7 +597,7 @@
@cmd2.with_argparser(read_bin_dec_parser)
def do_read_binary_decoded(self, opts):
"""Read + decode data from a transparent EF"""
- (data, sw) = self._cmd.lchan.read_binary_dec()
+ (data, _sw) = self._cmd.lchan.read_binary_dec()
self._cmd.poutput_json(data, opts.oneline)
upd_bin_parser = argparse.ArgumentParser()
@@ -617,7 +608,7 @@
@cmd2.with_argparser(upd_bin_parser)
def do_update_binary(self, opts):
"""Update (Write) data of a transparent EF"""
- (data, sw) = self._cmd.lchan.update_binary(opts.data, opts.offset)
+ (data, _sw) = self._cmd.lchan.update_binary(opts.data, opts.offset)
if data:
self._cmd.poutput(data)
@@ -630,18 +621,18 @@
def do_update_binary_decoded(self, opts):
"""Encode + Update (Write) data of a transparent EF"""
if opts.json_path:
- (data_json, sw) = self._cmd.lchan.read_binary_dec()
+ (data_json, _sw) = self._cmd.lchan.read_binary_dec()
js_path_modify(data_json, opts.json_path,
json.loads(opts.data))
else:
data_json = json.loads(opts.data)
- (data, sw) = self._cmd.lchan.update_binary_dec(data_json)
+ (data, _sw) = self._cmd.lchan.update_binary_dec(data_json)
if data:
self._cmd.poutput_json(data)
- def do_edit_binary_decoded(self, opts):
+ def do_edit_binary_decoded(self, _opts):
"""Edit the JSON representation of the EF contents in an editor."""
- (orig_json, sw) = self._cmd.lchan.read_binary_dec()
+ (orig_json, _sw) = self._cmd.lchan.read_binary_dec()
with tempfile.TemporaryDirectory(prefix='pysim_') as dirname:
filename = '%s/file' % dirname
# write existing data as JSON to file
@@ -654,7 +645,7 @@
if edited_json == orig_json:
self._cmd.poutput("Data not modified, skipping write")
else:
- (data, sw) = self._cmd.lchan.update_binary_dec(edited_json)
+ (data, _sw) = self._cmd.lchan.update_binary_dec(edited_json)
if data:
self._cmd.poutput_json(data)
@@ -695,7 +686,7 @@
return method(b2h(raw_bin_data))
if self._construct:
return parse_construct(self._construct, raw_bin_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_tlv(raw_bin_data)
return t.to_dict()
@@ -722,7 +713,7 @@
return method(raw_bin_data)
if self._construct:
return parse_construct(self._construct, raw_bin_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_tlv(raw_bin_data)
return t.to_dict()
@@ -748,7 +739,7 @@
return h2b(method(abstract_data))
if self._construct:
return build_construct(self._construct, abstract_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
return t.to_tlv()
@@ -776,7 +767,7 @@
return b2h(raw_bin_data)
if self._construct:
return b2h(build_construct(self._construct, abstract_data))
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
return b2h(t.to_tlv())
@@ -793,10 +784,6 @@
@with_default_category('Linear Fixed EF Commands')
class ShellCommands(CommandSet):
"""Shell commands specific for Linear Fixed EFs."""
-
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
-
dec_hex_parser = argparse.ArgumentParser()
dec_hex_parser.add_argument('--oneline', action='store_true',
help='No JSON pretty-printing, dump as a single line')
@@ -819,8 +806,8 @@
"""Read one or multiple records from a record-oriented EF"""
for r in range(opts.count):
recnr = opts.record_nr + r
- (data, sw) = self._cmd.lchan.read_record(recnr)
- if (len(data) > 0):
+ (data, _sw) = self._cmd.lchan.read_record(recnr)
+ if len(data) > 0:
recstr = str(data)
else:
recstr = "(empty)"
@@ -835,18 +822,18 @@
@cmd2.with_argparser(read_rec_dec_parser)
def do_read_record_decoded(self, opts):
"""Read + decode a record from a record-oriented EF"""
- (data, sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
+ (data, _sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
self._cmd.poutput_json(data, opts.oneline)
read_recs_parser = argparse.ArgumentParser()
@cmd2.with_argparser(read_recs_parser)
- def do_read_records(self, opts):
+ def do_read_records(self, _opts):
"""Read all records from a record-oriented EF"""
num_of_rec = self._cmd.lchan.selected_file_num_of_rec()
for recnr in range(1, 1 + num_of_rec):
- (data, sw) = self._cmd.lchan.read_record(recnr)
- if (len(data) > 0):
+ (data, _sw) = self._cmd.lchan.read_record(recnr)
+ if len(data) > 0:
recstr = str(data)
else:
recstr = "(empty)"
@@ -863,7 +850,7 @@
# collect all results in list so they are rendered as JSON list when printing
data_list = []
for recnr in range(1, 1 + num_of_rec):
- (data, sw) = self._cmd.lchan.read_record_dec(recnr)
+ (data, _sw) = self._cmd.lchan.read_record_dec(recnr)
data_list.append(data)
self._cmd.poutput_json(data_list, opts.oneline)
@@ -875,7 +862,7 @@
@cmd2.with_argparser(upd_rec_parser)
def do_update_record(self, opts):
"""Update (write) data to a record-oriented EF"""
- (data, sw) = self._cmd.lchan.update_record(opts.record_nr, opts.data)
+ (data, _sw) = self._cmd.lchan.update_record(opts.record_nr, opts.data)
if data:
self._cmd.poutput(data)
@@ -890,12 +877,12 @@
def do_update_record_decoded(self, opts):
"""Encode + Update (write) data to a record-oriented EF"""
if opts.json_path:
- (data_json, sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
+ (data_json, _sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
js_path_modify(data_json, opts.json_path,
json.loads(opts.data))
else:
data_json = json.loads(opts.data)
- (data, sw) = self._cmd.lchan.update_record_dec(
+ (data, _sw) = self._cmd.lchan.update_record_dec(
opts.record_nr, data_json)
if data:
self._cmd.poutput(data)
@@ -907,7 +894,7 @@
@cmd2.with_argparser(edit_rec_dec_parser)
def do_edit_record_decoded(self, opts):
"""Edit the JSON representation of one record in an editor."""
- (orig_json, sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
+ (orig_json, _sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
with tempfile.TemporaryDirectory(prefix='pysim_') as dirname:
filename = '%s/file' % dirname
# write existing data as JSON to file
@@ -920,7 +907,7 @@
if edited_json == orig_json:
self._cmd.poutput("Data not modified, skipping write")
else:
- (data, sw) = self._cmd.lchan.update_record_dec(
+ (data, _sw) = self._cmd.lchan.update_record_dec(
opts.record_nr, edited_json)
if data:
self._cmd.poutput_json(data)
@@ -966,7 +953,7 @@
return method(raw_bin_data, record_nr=record_nr)
if self._construct:
return parse_construct(self._construct, raw_bin_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_tlv(raw_bin_data)
return t.to_dict()
@@ -994,7 +981,7 @@
return method(raw_hex_data, record_nr=record_nr)
if self._construct:
return parse_construct(self._construct, raw_bin_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_tlv(raw_bin_data)
return t.to_dict()
@@ -1022,7 +1009,7 @@
return b2h(raw_bin_data)
if self._construct:
return b2h(build_construct(self._construct, abstract_data))
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
return b2h(t.to_tlv())
@@ -1050,7 +1037,7 @@
return h2b(method(abstract_data, record_nr=record_nr))
if self._construct:
return build_construct(self._construct, abstract_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
return t.to_tlv()
@@ -1113,7 +1100,7 @@
return method(raw_bin_data)
if self._construct:
return parse_construct(self._construct, raw_bin_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_tlv(raw_bin_data)
return t.to_dict()
@@ -1140,7 +1127,7 @@
return method(raw_hex_data)
if self._construct:
return parse_construct(self._construct, raw_bin_data)
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_tlv(raw_bin_data)
return t.to_dict()
@@ -1166,7 +1153,7 @@
return b2h(method(abstract_data))
if self._construct:
return b2h(filter_dict(build_construct(self._construct, abstract_data)))
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
return b2h(t.to_tlv())
@@ -1193,7 +1180,7 @@
return h2b(method(abstract_data))
if self._construct:
return filter_dict(build_construct(self._construct, abstract_data))
- elif self._tlv:
+ if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
return t.to_tlv()
@@ -1223,9 +1210,6 @@
class ShellCommands(CommandSet):
"""Shell commands specific for BER-TLV EFs."""
- def __init__(self):
- super().__init__()
-
retrieve_data_parser = argparse.ArgumentParser()
retrieve_data_parser.add_argument(
'tag', type=auto_int, help='BER-TLV Tag of value to retrieve')
@@ -1233,10 +1217,10 @@
@cmd2.with_argparser(retrieve_data_parser)
def do_retrieve_data(self, opts):
"""Retrieve (Read) data from a BER-TLV EF"""
- (data, sw) = self._cmd.lchan.retrieve_data(opts.tag)
+ (data, _sw) = self._cmd.lchan.retrieve_data(opts.tag)
self._cmd.poutput(data)
- def do_retrieve_tags(self, opts):
+ def do_retrieve_tags(self, _opts):
"""List tags available in a given BER-TLV EF"""
tags = self._cmd.lchan.retrieve_tags()
self._cmd.poutput(tags)
@@ -1249,7 +1233,7 @@
@cmd2.with_argparser(set_data_parser)
def do_set_data(self, opts):
"""Set (Write) data for a given tag in a BER-TLV EF"""
- (data, sw) = self._cmd.lchan.set_data(opts.tag, opts.data)
+ (data, _sw) = self._cmd.lchan.set_data(opts.tag, opts.data)
if data:
self._cmd.poutput(data)
@@ -1260,7 +1244,7 @@
@cmd2.with_argparser(del_data_parser)
def do_delete_data(self, opts):
"""Delete data for a given tag in a BER-TLV EF"""
- (data, sw) = self._cmd.lchan.set_data(opts.tag, None)
+ (data, _sw) = self._cmd.lchan.set_data(opts.tag, None)
if data:
self._cmd.poutput(data)
@@ -1312,7 +1296,7 @@
"""
self.name = name
self.adf = adf
- self.sw = sw or dict()
+ self.sw = sw or {}
# back-reference from ADF to Applicaiton
if self.adf:
self.aid = aid or self.adf.aid
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35847?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I94e1f5791e9fc34a60d0254978a35fd6ab2ff8d7
Gerrit-Change-Number: 35847
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35809?usp=email )
Change subject: pylint: card_key_provider.py, card_handler.py, iso7816_4.py, jsonpath.py
......................................................................
pylint: card_key_provider.py, card_handler.py, iso7816_4.py, jsonpath.py
pySim/card_key_provider.py:57:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
pySim/card_key_provider.py:61:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)
pySim/card_handler.py:100:0: C0325: Unnecessary parens after '=' keyword (superfluous-parens)
pySim/card_handler.py:100:24: C0121: Comparison 'self.cmds.get('verbose') == True' should be 'self.cmds.get('verbose') is True' if checking for the singleton value True, or 'bool(self.cmds.get('verbose'))' if testing for truthiness (singleton-comparison)
pySim/card_handler.py:29:0: C0411: standard import "import subprocess" should be placed before "from pySim.transport import LinkBase" (wrong-import-order)
pySim/card_handler.py:30:0: C0411: standard import "import sys" should be placed before "from pySim.transport import LinkBase" (wrong-import-order)
pySim/card_handler.py:31:0: C0411: third party import "import yaml" should be placed before "from pySim.transport import LinkBase" (wrong-import-order)
pySim/iso7816_4.py:20:0: W0401: Wildcard import construct (wildcard-import)
pySim/jsonpath.py:1:0: C0114: Missing module docstring (missing-module-docstring)
pySim/jsonpath.py:6:0: W0105: String statement has no effect (pointless-string-statement)
pySim/jsonpath.py:2:0: W0611: Unused import json (unused-import)
pySim/jsonpath.py:3:0: W0611: Unused import pprint (unused-import)
Change-Id: I780595d69000f727ad0fbaff4b89918b91b3122e
---
M pySim/card_handler.py
M pySim/card_key_provider.py
M pySim/iso7816_4.py
M pySim/jsonpath.py
4 files changed, 32 insertions(+), 11 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/09/35809/1
diff --git a/pySim/card_handler.py b/pySim/card_handler.py
index 57e0d32..e7884ad 100644
--- a/pySim/card_handler.py
+++ b/pySim/card_handler.py
@@ -24,12 +24,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from pySim.transport import LinkBase
-
import subprocess
import sys
import yaml
+from pySim.transport import LinkBase
class CardHandlerBase:
"""Abstract base class representing a mechanism for card insertion/removal."""
@@ -97,7 +96,7 @@
print("Card handler Config-file: " + str(config_file))
with open(config_file) as cfg:
self.cmds = yaml.load(cfg, Loader=yaml.FullLoader)
- self.verbose = (self.cmds.get('verbose') == True)
+ self.verbose = self.cmds.get('verbose') is True
def __print_outout(self, out):
print("")
diff --git a/pySim/card_key_provider.py b/pySim/card_key_provider.py
index 00e32aa..33a2a3d 100644
--- a/pySim/card_key_provider.py
+++ b/pySim/card_key_provider.py
@@ -54,11 +54,11 @@
dictionary of {field, value} strings for each requested field from 'fields'
"""
for f in fields:
- if (f not in self.VALID_FIELD_NAMES):
+ if f not in self.VALID_FIELD_NAMES:
raise ValueError("Requested field name '%s' is not a valid field name, valid field names are: %s" %
(f, str(self.VALID_FIELD_NAMES)))
- if (key not in self.VALID_FIELD_NAMES):
+ if key not in self.VALID_FIELD_NAMES:
raise ValueError("Key field name '%s' is not a valid field name, valid field names are: %s" %
(key, str(self.VALID_FIELD_NAMES)))
diff --git a/pySim/iso7816_4.py b/pySim/iso7816_4.py
index 1da5809..9d1229e 100644
--- a/pySim/iso7816_4.py
+++ b/pySim/iso7816_4.py
@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-from construct import *
+from construct import GreedyBytes
from pySim.construct import *
from pySim.utils import *
from pySim.filesystem import *
diff --git a/pySim/jsonpath.py b/pySim/jsonpath.py
index 4dd838c..5778de9 100644
--- a/pySim/jsonpath.py
+++ b/pySim/jsonpath.py
@@ -1,8 +1,3 @@
-# coding=utf-8
-import json
-import pprint
-import jsonpath_ng
-
"""JSONpath utility functions as needed within pysim.
As pySim-sell has the ability to represent SIM files as JSON strings,
@@ -10,6 +5,8 @@
of a file or record in its JSON representation.
"""
+import jsonpath_ng
+
# (C) 2021 by Harald Welte <laforge(a)osmocom.org>
#
# This program is free software: you can redistribute it and/or modify
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35809?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I780595d69000f727ad0fbaff4b89918b91b3122e
Gerrit-Change-Number: 35809
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35813?usp=email )
Change subject: pylint: ota.py
......................................................................
pylint: ota.py
pySim/ota.py:21:0: W0401: Wildcard import construct (wildcard-import)
pySim/ota.py:129:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
pySim/ota.py:150:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:192:8: W0612: Unused variable 'padded_data' (unused-variable)
pySim/ota.py:202:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:207:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:210:4: C0103: Method name "fromKeyset" doesn't conform to snake_case naming style (invalid-name)
pySim/ota.py:239:8: W0107: Unnecessary pass statement (unnecessary-pass)
pySim/ota.py:242:4: C0103: Method name "fromKeyset" doesn't conform to snake_case naming style (invalid-name)
pySim/ota.py:328:4: W0221: Number of parameters was 4 in 'OtaDialect.encode_cmd' and is now 5 in overriding 'OtaDialectSms.encode_cmd' method (arguments-differ)
pySim/ota.py:392:4: W0221: Number of parameters was 3 in 'OtaDialect.decode_resp' and is now 4 in overriding 'OtaDialectSms.decode_resp' method (arguments-differ)
Change-Id: Icb8d690e541dbaf1406085a8446a0c67641fefff
---
M pySim/ota.py
1 file changed, 37 insertions(+), 18 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/13/35813/1
diff --git a/pySim/ota.py b/pySim/ota.py
index 5955a08..14bad56 100644
--- a/pySim/ota.py
+++ b/pySim/ota.py
@@ -15,14 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from pySim.construct import *
-from pySim.utils import b2h
-from pySim.sms import UserDataHeader
-from construct import *
import zlib
import abc
import struct
from typing import Optional
+from construct import Enum, Int8ub, Int16ub, Struct, Bytes, GreedyBytes, BitsInteger, BitStruct
+from construct import Flag, Padding, Switch, this
+
+from pySim.construct import *
+from pySim.utils import b2h
+from pySim.sms import UserDataHeader
# ETS TS 102 225 gives the general command structure and the dialects for CAT_TP, TCP/IP and HTTPS
# 3GPP TS 31.115 gives the dialects for SMS-PP, SMS-CB, USSD and HTTP
@@ -112,12 +114,12 @@
@property
def auth(self):
"""Return an instance of the matching OtaAlgoAuth."""
- return OtaAlgoAuth.fromKeyset(self)
+ return OtaAlgoAuth.from_keyset(self)
@property
def crypt(self):
"""Return an instance of the matching OtaAlgoCrypt."""
- return OtaAlgoCrypt.fromKeyset(self)
+ return OtaAlgoCrypt.from_keyset(self)
class OtaCheckError(Exception):
pass
@@ -128,26 +130,24 @@
def _compute_sig_len(self, spi:SPI):
if spi['rc_cc_ds'] == 'no_rc_cc_ds':
return 0
- elif spi['rc_cc_ds'] == 'rc': # CRC-32
+ if spi['rc_cc_ds'] == 'rc': # CRC-32
return 4
- elif spi['rc_cc_ds'] == 'cc': # Cryptographic Checksum (CC)
+ if spi['rc_cc_ds'] == 'cc': # Cryptographic Checksum (CC)
# TODO: this is not entirely correct, as in AES case it could be 4 or 8
return 8
- else:
- raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds'])
+ raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds'])
@abc.abstractmethod
- def encode_cmd(self, otak: OtaKeyset, tar: bytes, apdu: bytes) -> bytes:
+ def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, apdu: bytes) -> bytes:
pass
@abc.abstractmethod
- def decode_resp(self, otak: OtaKeyset, apdu: bytes) -> (object, Optional["CompactRemoteResp"]):
+ def decode_resp(self, otak: OtaKeyset, spi: dict, apdu: bytes) -> (object, Optional["CompactRemoteResp"]):
"""Decode a response into a response packet and, if indicted (by a
response status of `"por_ok"`) a decoded response.
The response packet's common characteristics are not fully determined,
and (so far) completely proprietary per dialect."""
- pass
from Cryptodome.Cipher import DES, DES3, AES
@@ -190,7 +190,7 @@
def encrypt(self, data:bytes) -> bytes:
"""Encrypt given input bytes using the key material given in constructor."""
padded_data = self.pad_to_blocksize(data)
- return self._encrypt(data)
+ return self._encrypt(padded_data)
def decrypt(self, data:bytes) -> bytes:
"""Decrypt given input bytes using the key material given in constructor."""
@@ -199,15 +199,13 @@
@abc.abstractmethod
def _encrypt(self, data:bytes) -> bytes:
"""Actual implementation, to be implemented by derived class."""
- pass
@abc.abstractmethod
def _decrypt(self, data:bytes) -> bytes:
"""Actual implementation, to be implemented by derived class."""
- pass
@classmethod
- def fromKeyset(cls, otak: OtaKeyset) -> 'OtaAlgoCrypt':
+ def from_keyset(cls, otak: OtaKeyset) -> 'OtaAlgoCrypt':
"""Resolve the class for the encryption algorithm of otak and instantiate it."""
for subc in cls.__subclasses__():
if subc.enum_name == otak.algo_crypt:
@@ -239,7 +237,7 @@
pass
@classmethod
- def fromKeyset(cls, otak: OtaKeyset) -> 'OtaAlgoAuth':
+ def from_keyset(cls, otak: OtaKeyset) -> 'OtaAlgoAuth':
"""Resolve the class for the authentication algorithm of otak and instantiate it."""
for subc in cls.__subclasses__():
if subc.enum_name == otak.algo_auth:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35813?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Icb8d690e541dbaf1406085a8446a0c67641fefff
Gerrit-Change-Number: 35813
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange