ruff SIM102 (use single if instead of nested if)
This commit is contained in:
parent
5ccf9e061e
commit
69a4a8bd32
15 changed files with 52 additions and 69 deletions
|
|
@ -222,9 +222,8 @@ class AddrList(MMGenObject): # Address info for a single seed ID
|
|||
if self.al_id is None:
|
||||
return
|
||||
|
||||
if type(self) is ViewKeyAddrList:
|
||||
if not 'viewkey' in self.al_id.mmtype.extra_attrs:
|
||||
die(1, f'viewkeys not supported for address type {self.al_id.mmtype.desc!r}')
|
||||
if type(self) is ViewKeyAddrList and not 'viewkey' in self.al_id.mmtype.extra_attrs:
|
||||
die(1, f'viewkeys not supported for address type {self.al_id.mmtype.desc!r}')
|
||||
|
||||
self.id_str = AddrListIDStr(self)
|
||||
|
||||
|
|
|
|||
|
|
@ -73,11 +73,10 @@ class Autosign:
|
|||
|
||||
def __init__(self, cfg, *, cmd=None):
|
||||
|
||||
if cfg.mnemonic_fmt:
|
||||
if cfg.mnemonic_fmt not in self.mn_fmts:
|
||||
die(1, '{!r}: invalid mnemonic format (must be one of: {})'.format(
|
||||
cfg.mnemonic_fmt,
|
||||
fmt_list(self.mn_fmts, fmt='no_spc')))
|
||||
if cfg.mnemonic_fmt and cfg.mnemonic_fmt not in self.mn_fmts:
|
||||
die(1, '{!r}: invalid mnemonic format (must be one of: {})'.format(
|
||||
cfg.mnemonic_fmt,
|
||||
fmt_list(self.mn_fmts, fmt='no_spc')))
|
||||
|
||||
match gc.platform:
|
||||
case 'linux':
|
||||
|
|
|
|||
|
|
@ -198,9 +198,8 @@ class Signable:
|
|||
self.die_wrong_num_txs('unsent_raw', desc='unsent')
|
||||
if len(self.unsent) > 1:
|
||||
self.die_wrong_num_txs('unsent')
|
||||
if self.unsent:
|
||||
if self.unsent[0].stem != self.unsent_raw[0].stem:
|
||||
die(1, f'{self.unsent[0]}, {self.unsent_raw[0]}: file mismatch')
|
||||
if self.unsent and self.unsent[0].stem != self.unsent_raw[0].stem:
|
||||
die(1, f'{self.unsent[0]}, {self.unsent_raw[0]}: file mismatch')
|
||||
return self.unsent_raw + self.unsent
|
||||
|
||||
def shred_abortable(self):
|
||||
|
|
|
|||
|
|
@ -117,12 +117,11 @@ class Lockable(AttrCtrl):
|
|||
val = getattr(self, name)
|
||||
if name not in (self._set_ok + self._reset_ok):
|
||||
raise AttributeError(f'attribute {name!r} of {type(self).__name__} object is read-only')
|
||||
elif name not in self._reset_ok:
|
||||
if not (
|
||||
elif name not in self._reset_ok and not (
|
||||
(val != 0 and not val) or
|
||||
(self._use_class_attr and name not in self.__dict__)):
|
||||
raise AttributeError(
|
||||
f'attribute {name!r} of {type(self).__name__} object is already set,'
|
||||
+ ' and resetting is forbidden')
|
||||
raise AttributeError(
|
||||
f'attribute {name!r} of {type(self).__name__} object is already set,'
|
||||
+ ' and resetting is forbidden')
|
||||
|
||||
return AttrCtrl.__setattr__(self, name, value)
|
||||
|
|
|
|||
|
|
@ -226,12 +226,11 @@ class CfgFileSampleUsr(cfg_file_sample):
|
|||
self.copy_system_data(self.fn)
|
||||
|
||||
def parse_metadata(self):
|
||||
if self.data:
|
||||
if m := re.match(r'# Version (\d+) ([a-f0-9]{40})$', self.data[-1]):
|
||||
self.ver = m[1]
|
||||
self.chksum = m[2]
|
||||
self.data = self.data[:-1] # remove metadata line
|
||||
return True
|
||||
if self.data and (m := re.match(r'# Version (\d+) ([a-f0-9]{40})$', self.data[-1])):
|
||||
self.ver = m[1]
|
||||
self.chksum = m[2]
|
||||
self.data = self.data[:-1] # remove metadata line
|
||||
return True
|
||||
|
||||
def diff(self, a_tup, b_tup): # a=user, b=system
|
||||
a = [i.name for i in a_tup]#[3:] # Debug
|
||||
|
|
|
|||
|
|
@ -116,10 +116,9 @@ class Crypto:
|
|||
def decrypt_seed(self, enc_seed, key, *, seed_id, key_id):
|
||||
self.util.vmsg_r('Checking key...')
|
||||
chk1 = make_chksum_8(key)
|
||||
if key_id:
|
||||
if not self.util.compare_chksums(key_id, 'key ID', chk1, 'computed'):
|
||||
msg('Incorrect passphrase or hash preset')
|
||||
return False
|
||||
if key_id and not self.util.compare_chksums(key_id, 'key ID', chk1, 'computed'):
|
||||
msg('Incorrect passphrase or hash preset')
|
||||
return False
|
||||
|
||||
dec_seed = self.decrypt_data(enc_seed, key, desc='seed')
|
||||
chk2 = make_chksum_8(dec_seed)
|
||||
|
|
|
|||
|
|
@ -40,11 +40,10 @@ def check_or_create_dir(path):
|
|||
try:
|
||||
os.listdir(path)
|
||||
except:
|
||||
if os.getenv('MMGEN_TEST_SUITE'):
|
||||
if os.path.exists(path): # path is a link or regular file
|
||||
from subprocess import run
|
||||
run(['rm', '-rf', str(path)])
|
||||
set_vt100()
|
||||
if os.getenv('MMGEN_TEST_SUITE') and os.path.exists(path): # path is a link or regular file
|
||||
from subprocess import run
|
||||
run(['rm', '-rf', str(path)])
|
||||
set_vt100()
|
||||
try:
|
||||
os.makedirs(path, 0o700)
|
||||
except:
|
||||
|
|
@ -83,9 +82,8 @@ def _check_file_type_and_access(fname, ftype, *, blkdev_ok=False):
|
|||
(stat.S_ISREG, 'regular file'),
|
||||
(stat.S_ISLNK, 'symbolic link')
|
||||
]
|
||||
if blkdev_ok:
|
||||
if not gc.platform in ('win32',):
|
||||
ok_types.append((stat.S_ISBLK, 'block device'))
|
||||
if blkdev_ok and gc.platform != 'win32':
|
||||
ok_types.append((stat.S_ISBLK, 'block device'))
|
||||
|
||||
try:
|
||||
mode = os.stat(fname).st_mode
|
||||
|
|
|
|||
|
|
@ -135,9 +135,8 @@ if cmd in ('enable_swap', 'disable_swap', 'list_led', 'test_led'):
|
|||
if cmd not in Autosign.cmds + Autosign.util_cmds:
|
||||
die(1, f'‘{cmd}’: unrecognized command')
|
||||
|
||||
if cfg.xmrwallets:
|
||||
if cmd not in ('setup', 'xmr_setup'):
|
||||
die(1, '--xmrwallets is valid only for the ‘setup’ and ‘xmr_setup’ operations')
|
||||
if cfg.xmrwallets and cmd not in ('setup', 'xmr_setup'):
|
||||
die(1, '--xmrwallets is valid only for the ‘setup’ and ‘xmr_setup’ operations')
|
||||
|
||||
if cmd != 'setup':
|
||||
for opt in ('seed_len', 'mnemonic_fmt', 'keys_from_file'):
|
||||
|
|
|
|||
|
|
@ -159,10 +159,9 @@ async def process_tx(tx):
|
|||
|
||||
txcfg = Config({'_clone': cfg, 'proto': tx.proto, 'coin': tx.proto.coin})
|
||||
|
||||
if not post_send_op:
|
||||
if cfg.tx_proxy:
|
||||
from .tx.tx_proxy import check_client
|
||||
check_client(txcfg)
|
||||
if (not post_send_op) and cfg.tx_proxy:
|
||||
from .tx.tx_proxy import check_client
|
||||
check_client(txcfg)
|
||||
|
||||
from .rpc import rpc_init
|
||||
tx.rpc = await rpc_init(txcfg)
|
||||
|
|
@ -177,9 +176,8 @@ async def process_tx(tx):
|
|||
|
||||
if not cfg.yes:
|
||||
tx.info.view_with_prompt('View transaction details?')
|
||||
if tx.add_comment(): # edits an existing comment, returns true if changed
|
||||
if not cfg.autosign:
|
||||
tx.file.write(ask_write_default_yes=True)
|
||||
if tx.add_comment() and not cfg.autosign: # edits existing comment, returns true if changed
|
||||
tx.file.write(ask_write_default_yes=True)
|
||||
|
||||
return await tx.send(txcfg, asi, batch=batch)
|
||||
|
||||
|
|
|
|||
|
|
@ -316,10 +316,9 @@ class BitcoinRPCClient(RPCClient, metaclass=AsyncInit):
|
|||
self.auth = auth_data(user, passwd)
|
||||
return
|
||||
|
||||
if self.has_auth_cookie:
|
||||
if cookie := self.get_daemon_auth_cookie():
|
||||
self.auth = auth_data(*cookie.split(':'))
|
||||
return
|
||||
if self.has_auth_cookie and (cookie := self.get_daemon_auth_cookie()):
|
||||
self.auth = auth_data(*cookie.split(':'))
|
||||
return
|
||||
|
||||
die(1, '\n\n' + fmt(no_credentials_errmsg, strip_char='\t', indent=' ').format(
|
||||
proto_name = self.proto.name,
|
||||
|
|
|
|||
|
|
@ -31,13 +31,12 @@ class SwapAsset:
|
|||
fs = '%s{:10} {:23} {:9} {}' % indent
|
||||
yield fs.format('ASSET', 'DESCRIPTION', 'STATUS', 'CONTRACT ADDRESS')
|
||||
for k, v in self.assets_data.items():
|
||||
if not k in self.blacklisted:
|
||||
if k in self.send or k in self.recv:
|
||||
yield fs.format(
|
||||
k,
|
||||
v.desc,
|
||||
'tested' if v.tested else 'untested',
|
||||
self.evm_contracts.get(k,'-'))
|
||||
if not k in self.blacklisted and (k in self.send or k in self.recv):
|
||||
yield fs.format(
|
||||
k,
|
||||
v.desc,
|
||||
'tested' if v.tested else 'untested',
|
||||
self.evm_contracts.get(k,'-'))
|
||||
|
||||
def gen_bad():
|
||||
if self.blacklisted:
|
||||
|
|
|
|||
|
|
@ -143,10 +143,9 @@ class Base(MMGenObject):
|
|||
return init_info(self.cfg, self)
|
||||
|
||||
def check_correct_chain(self):
|
||||
if hasattr(self, 'rpc'):
|
||||
if self.chain != self.rpc.chain:
|
||||
die('TransactionChainMismatch',
|
||||
f'Transaction is for {self.chain}, but coin daemon chain is {self.rpc.chain}!')
|
||||
if hasattr(self, 'rpc') and self.chain != self.rpc.chain:
|
||||
die('TransactionChainMismatch',
|
||||
f'Transaction is for {self.chain}, but coin daemon chain is {self.rpc.chain}!')
|
||||
|
||||
def sum_inputs(self):
|
||||
return sum(e.amt for e in self.inputs)
|
||||
|
|
|
|||
|
|
@ -24,9 +24,8 @@ class OpCreate(OpWallet):
|
|||
opts = ('restore_height',)
|
||||
|
||||
def check_uopts(self):
|
||||
if self.cfg.restore_height != 'current':
|
||||
if int(self.cfg.restore_height or 0) < 0:
|
||||
die(1, f'{self.cfg.restore_height}: invalid value for --restore-height (less than zero)')
|
||||
if self.cfg.restore_height != 'current' and int(self.cfg.restore_height or 0) < 0:
|
||||
die(1, f'{self.cfg.restore_height}: invalid value for --restore-height (less than zero)')
|
||||
if self.cfg.compat:
|
||||
self.cfg.wallet_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -98,10 +98,9 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
if hasattr(self, 'txdev'):
|
||||
del self.txdev
|
||||
|
||||
if not self.cfg.no_daemon_stop:
|
||||
if gc.platform == 'darwin':
|
||||
for label in (self.asi.dev_label, self.asi.macos_ramdisk.label):
|
||||
self._macOS_eject_disk(label)
|
||||
if (not self.cfg.no_daemon_stop) and gc.platform == 'darwin':
|
||||
for label in (self.asi.dev_label, self.asi.macos_ramdisk.label):
|
||||
self._macOS_eject_disk(label)
|
||||
|
||||
def _create_autosign_instances(self, create_dirs):
|
||||
d = {'offline': {'name':'asi'}}
|
||||
|
|
|
|||
|
|
@ -174,9 +174,8 @@ def clean(cfgs, tmpdir_ids=None, extra_dirs=[]):
|
|||
|
||||
def clean_extra_dirs():
|
||||
for d in extra_dirs:
|
||||
if os.path.exists(d):
|
||||
if cleandir(d):
|
||||
yield os.path.relpath(d)
|
||||
if os.path.exists(d) and cleandir(d):
|
||||
yield os.path.relpath(d)
|
||||
|
||||
for clean_func, list_fmt in (
|
||||
(clean_tmpdirs, 'no_quotes'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue