use startswith() instead of string indexing where feasible
This commit is contained in:
parent
9482ecc705
commit
cde987efd3
7 changed files with 7 additions and 7 deletions
|
|
@ -376,7 +376,7 @@ class Config(Lockable):
|
|||
|
||||
if os.getenv('MMGEN_DEBUG_ALL'):
|
||||
for name in _env_opts:
|
||||
if name[:11] == 'MMGEN_DEBUG':
|
||||
if name.startswith('MMGEN_DEBUG'):
|
||||
os.environ[name] = '1'
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ def get_stack_trace(message=None, nl='\n', sep='\n ', trim=3):
|
|||
|
||||
import os, re, traceback
|
||||
|
||||
tb = [t for t in traceback.extract_stack() if t.filename[:1] != '<']
|
||||
tb = [t for t in traceback.extract_stack() if not t.filename.startswith('<')]
|
||||
fs = '{}:{}: in {}:\n {}'
|
||||
out = [
|
||||
fs.format(
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ def write_data_to_file(
|
|||
of = None # Windows
|
||||
|
||||
if of:
|
||||
if of[:5] == 'pipe:':
|
||||
if of.startswith('pipe:'):
|
||||
if no_tty:
|
||||
die(2, f'Writing {desc} to pipe is not allowed')
|
||||
if ask_tty and not cfg.quiet:
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class Token(Contract):
|
|||
async def get_decimals(self):
|
||||
ret = await self.do_call('decimals()')
|
||||
try:
|
||||
assert ret[:2] == '0x'
|
||||
assert ret.startswith('0x')
|
||||
return int(ret, 16)
|
||||
except:
|
||||
msg(f'RPC call to decimals() failed (returned {ret!r})')
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ class TokenBase(Base):
|
|||
if self.is_swap:
|
||||
d = rlp.decode(bytes.fromhex(self.serialized2))
|
||||
data = d[5].hex()
|
||||
assert data[:8] == '44bc937b', (
|
||||
assert data.startswith('44bc937b'), (
|
||||
f'{data[:8]}: invalid MethodID in router TX serialized data')
|
||||
assert data[32:72] == self.token_vault_addr, (
|
||||
f'{data[32:72]}: invalid vault address in router TX serialized data')
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class tool_cmd(tool_cmd_base):
|
|||
def redeem_script2addr(self, redeem_script_hex: 'sstr'): # new
|
||||
"convert a Segwit P2SH-P2WPKH redeem script to an address"
|
||||
assert self.mmtype.name == 'segwit', 'This command is meaningful only for --type=segwit'
|
||||
assert redeem_script_hex[:4] == '0014', f'{redeem_script_hex!r}: invalid redeem script'
|
||||
assert redeem_script_hex.startswith('0014'), f'{redeem_script_hex!r}: invalid redeem script'
|
||||
assert len(redeem_script_hex) == 44, f'{len(redeem_script_hex)//2} bytes: invalid redeem script length'
|
||||
from ..proto.btc.common import hash160
|
||||
return self.proto.pubhash2addr(hash160(bytes.fromhex(redeem_script_hex)), 'p2sh')
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ class CmdTestWalletConv(CmdTestBase, CmdTestShared):
|
|||
t.expect('Enter brainwallet: ', ref_wallet_brainpass+'\n')
|
||||
if icls.enc and icls.type != 'brain':
|
||||
t.passphrase(icls.desc, self.wpasswd)
|
||||
if self.test_name[:19] == 'ref_hincog_conv_old':
|
||||
if self.test_name.startswith('ref_hincog_conv_old'):
|
||||
t.expect('Is the Seed ID correct? (Y/n): ', '\n')
|
||||
else:
|
||||
t.expect(['Passphrase is OK', ' are correct'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue