laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/35846?usp=email )
Change subject: pylint: commands.py
......................................................................
pylint: commands.py
pySim/commands.py:443:0: C0325: Unnecessary parens after 'if' keyword
(superfluous-parens)
pySim/commands.py:446:0: C0325: Unnecessary parens after 'elif' keyword
(superfluous-parens)
pySim/commands.py:669:0: C0325: Unnecessary parens after 'elif' keyword
(superfluous-parens)
pySim/commands.py:27:0: W0622: Redefining built-in 'BlockingIOError'
(redefined-builtin)
pySim/commands.py:27:0: W0401: Wildcard import construct (wildcard-import)
pySim/commands.py:30:0: W0404: Reimport 'Hexstr' (imported line 29) (reimported)
pySim/commands.py:42:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:48:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:98:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:114:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:131:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:223:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:234:8: R1705: Unnecessary "else" after "return",
remove the "else" and de-indent the code inside it (no-else-return)
pySim/commands.py:252:11: C0123: Use isinstance() rather than type() for a typecheck.
(unidiomatic-typecheck)
pySim/commands.py:271:11: C0123: Use isinstance() rather than type() for a typecheck.
(unidiomatic-typecheck)
pySim/commands.py:274:18: W0612: Unused variable 'sw' (unused-variable)
pySim/commands.py:326:16: W0707: Consider explicitly re-raising using 'raise
ValueError('%s, failed to read (offset %d)' % (str_sanitize(str(e)), offset)) from
e' (raise-missing-from)
pySim/commands.py:386:16: W0707: Consider explicitly re-raising using 'raise
ValueError('%s, failed to write chunk (chunk_offset %d, chunk_len %d)' %
(str_sanitize(str(e)), chunk_offset, chunk_len)) from e' (raise-missing-from)
pySim/commands.py:443:12: R1720: Unnecessary "elif" after "raise",
remove the leading "el" from "elif" (no-else-raise)
pySim/commands.py:521:14: R1714: Consider merging these comparisons with 'in' by
using 'sw in ('62f1', '62f2')'. Use a set instead if elements are
hashable. (consider-using-in)
pySim/commands.py:532:11: R1701: Consider merging these isinstance calls to
isinstance(data, (bytearray, bytes)) (consider-merging-isinstance)
pySim/commands.py:666:8: R1720: Unnecessary "elif" after "raise",
remove the leading "el" from "elif" (no-else-raise)
pySim/commands.py:762:12: R1705: Unnecessary "elif" after "return",
remove the leading "el" from "elif" (no-else-return)
pySim/commands.py:776:12: R1705: Unnecessary "elif" after "return",
remove the leading "el" from "elif" (no-else-return)
Change-Id: Idfcd6f799d5de9ecacd2c3d1e0d1f7d932f2b8db
---
M pySim/commands.py
1 file changed, 55 insertions(+), 23 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/46/35846/1
diff --git a/pySim/commands.py b/pySim/commands.py
index 81edf82..8393d22 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -24,9 +24,9 @@
from typing import List, Optional, Tuple
import typing # construct also has a Union, so we do typing.Union below
-from construct import *
+from construct import Construct, Struct, Const, Select
from pySim.construct import LV, filter_dict
-from pySim.utils import rpad, lpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i,
i2h, str_sanitize, expand_hex, SwMatchstr
+from pySim.utils import rpad, lpad, b2h, h2b, sw_match, bertlv_encode_len, h2i, i2h,
str_sanitize, expand_hex, SwMatchstr
from pySim.utils import Hexstr, SwHexstr, ResTuple
from pySim.exceptions import SwMatchError
from pySim.transport import LinkBase
@@ -249,7 +249,7 @@
"""
rv = []
- if type(dir_list) is not list:
+ if not isinstance(dir_list, list):
dir_list = [dir_list]
for i in dir_list:
data, sw = self.send_apdu(self.cla_byte + "a4" + self.sel_ctrl +
"02" + i)
@@ -268,10 +268,10 @@
list of return values (FCP in hex encoding) for each element of the path
"""
rv = []
- if type(dir_list) is not list:
+ if not isinstance(dir_list, list):
dir_list = [dir_list]
for i in dir_list:
- data, sw = self.select_file(i)
+ data, _sw = self.select_file(i)
rv.append(data)
return rv
@@ -324,7 +324,7 @@
data, sw = self.send_apdu_checksw(pdu)
except Exception as e:
raise ValueError('%s, failed to read (offset %d)' %
- (str_sanitize(str(e)), offset))
+ (str_sanitize(str(e)), offset)) from e
total_data += data
chunk_offset += chunk_len
return total_data, sw
@@ -384,7 +384,7 @@
chunk_data, chunk_sw = self.send_apdu_checksw(pdu)
except Exception as e:
raise ValueError('%s, failed to write chunk (chunk_offset %d,
chunk_len %d)' %
- (str_sanitize(str(e)), chunk_offset, chunk_len))
+ (str_sanitize(str(e)), chunk_offset, chunk_len)) from e
total_data += data
chunk_offset += chunk_len
if verify:
@@ -440,10 +440,10 @@
else:
# make sure the input data is padded to the record length using 0xFF.
# In cases where the input data exceed we throw an exception.
- if (len(data) // 2 > rec_length):
+ if len(data) // 2 > rec_length:
raise ValueError('Data length exceeds record length (expected max %d,
got %d)' % (
rec_length, len(data) // 2))
- elif (len(data) // 2 < rec_length):
+ elif len(data) // 2 < rec_length:
if leftpad:
data = lpad(data, rec_length * 2)
else:
@@ -518,7 +518,7 @@
# retrieve first block
data, sw = self._retrieve_data(tag, first=True)
total_data += data
- while sw == '62f1' or sw == '62f2':
+ while sw in ['62f1', '62f2']:
data, sw = self._retrieve_data(tag, first=False)
total_data += data
return total_data, sw
@@ -529,7 +529,7 @@
p1 = 0x80
else:
p1 = 0x00
- if isinstance(data, bytes) or isinstance(data, bytearray):
+ if isinstance(data, (bytes, bytearray)):
data = b2h(data)
pdu = self.cla4lchan('80') + 'db00%02x%02x%s' % (p1,
len(data)//2, data)
return self.send_apdu_checksw(pdu)
@@ -666,7 +666,7 @@
if sw_match(sw, '63cx'):
raise RuntimeError('Failed to %s chv_no 0x%02X with code 0x%s, %i tries
left.' %
(op_name, chv_no, b2h(pin_code).upper(), int(sw[3])))
- elif (sw != '9000'):
+ if sw != '9000':
raise SwMatchError(sw, '9000')
def verify_chv(self, chv_no: int, code: Hexstr) -> ResTuple:
@@ -761,30 +761,28 @@
def encode_duration(secs: int) -> Hexstr:
if secs >= 10*24*60*60:
return '04%02x' % (secs // (10*24*60*60))
- elif secs >= 24*60*60:
+ if secs >= 24*60*60:
return '03%02x' % (secs // (24*60*60))
- elif secs >= 60*60:
+ if secs >= 60*60:
return '02%02x' % (secs // (60*60))
- elif secs >= 60:
+ if secs >= 60:
return '01%02x' % (secs // 60)
- else:
- return '00%02x' % secs
+ return '00%02x' % secs
def decode_duration(enc: Hexstr) -> int:
time_unit = enc[:2]
length = h2i(enc[2:4])[0]
if time_unit == '04':
return length * 10*24*60*60
- elif time_unit == '03':
+ if time_unit == '03':
return length * 24*60*60
- elif time_unit == '02':
+ if time_unit == '02':
return length * 60*60
- elif time_unit == '01':
+ if time_unit == '01':
return length * 60
- elif time_unit == '00':
+ if time_unit == '00':
return length
- else:
- raise ValueError('Time unit must be 0x00..0x04')
+ raise ValueError('Time unit must be 0x00..0x04')
min_dur_enc = encode_duration(min_len_secs)
max_dur_enc = encode_duration(max_len_secs)
data, sw = self.send_apdu_checksw('8076000004' + min_dur_enc +
max_dur_enc)
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/35846?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: Idfcd6f799d5de9ecacd2c3d1e0d1f7d932f2b8db
Gerrit-Change-Number: 35846
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange