From 4ce1701de2d42119a24035fcc92984a0501ef7af Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 6 Jan 2022 20:24:20 +0000 Subject: [PATCH] string literal fixes: deprecated escapes, et al. --- mmgen/altcoins/eth/rlp/codec.py | 2 +- mmgen/obj.py | 2 +- test/include/common.py | 2 +- test/include/pexpect.py | 2 +- test/test_py_d/ts_ethdev.py | 22 +++++++++++----------- test/test_py_d/ts_main.py | 4 ++-- test/test_py_d/ts_shared.py | 2 +- test/test_py_d/ts_xmrwallet.py | 4 ++-- test/tooltest2.py | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/mmgen/altcoins/eth/rlp/codec.py b/mmgen/altcoins/eth/rlp/codec.py index 7cdb9988..05253fef 100644 --- a/mmgen/altcoins/eth/rlp/codec.py +++ b/mmgen/altcoins/eth/rlp/codec.py @@ -210,7 +210,7 @@ def decode(rlp, sedes=None, strict=True, recursive_cache=False, **kwargs): :param sedes: an object implementing a function ``deserialize(code)`` which will be applied after decoding, or ``None`` if no deserialization should be performed - :param \*\*kwargs: additional keyword arguments that will be passed to the deserializer + :param **kwargs: additional keyword arguments that will be passed to the deserializer :param strict: if false inputs that are longer than necessary don't cause an exception :returns: the decoded and maybe deserialized Python object :raises: :exc:`rlp.DecodingError` if the input string does not end after the root item and diff --git a/mmgen/obj.py b/mmgen/obj.py index 1cea9f0e..31e48fcf 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -974,7 +974,7 @@ class IPPort(str,Hilite,InitErrors,MMGenObject): if type(s) == cls: return s try: - m = re.fullmatch('{q}\.{q}\.{q}\.{q}:(\d{{1,10}})'.format(q=r'([0-9]{1,3})'),s) + m = re.fullmatch(r'{q}\.{q}\.{q}\.{q}:(\d{{1,10}})'.format(q=r'([0-9]{1,3})'),s) assert m is not None, f'{s!r}: invalid IP:HOST specifier' for e in m.groups(): if len(e) != 1 and e[0] == '0': diff --git a/test/include/common.py b/test/include/common.py index 6c3c0117..27f52735 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -29,7 +29,7 @@ from mmgen.devtools import * def strip_ansi_escapes(s): import re - return re.sub('\x1b\[[;0-9]+?m','',s) + return re.sub('\x1b' + r'\[[;0-9]+?m','',s) ascii_uc = ''.join(map(chr,list(range(65,91)))) # 26 chars ascii_lc = ''.join(map(chr,list(range(97,123)))) # 26 chars diff --git a/test/include/pexpect.py b/test/include/pexpect.py index c3480fc9..b942bed8 100755 --- a/test/include/pexpect.py +++ b/test/include/pexpect.py @@ -70,7 +70,7 @@ class MMGenPexpect(object): self.expect('Check key-to-address validity? (y/N): ',('n','y')[check]) def view_tx(self,view): - self.expect('View.* transaction.*\? .*: ',view,regex=True) + self.expect(r'View.* transaction.*\? .*: ',view,regex=True) if view not in 'n\n': self.expect('to continue: ','\n') diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index e0ab48ae..f444ac35 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -90,26 +90,26 @@ bals = { ('98831F3A:E:2','23.45495'), ('98831F3A:E:11','1.234'), ('98831F3A:E:21','2.345'), - (burn_addr + '\s+Non-MMGen',amt1)], + (burn_addr + r'\s+Non-MMGen',amt1)], '8': [ ('98831F3A:E:1','0'), ('98831F3A:E:2','23.45495'), ('98831F3A:E:11',vbal1,'a1'), ('98831F3A:E:12','99.99895'), ('98831F3A:E:21','2.345'), - (burn_addr + '\s+Non-MMGen',amt1)], + (burn_addr + r'\s+Non-MMGen',amt1)], '9': [ ('98831F3A:E:1','0'), ('98831F3A:E:2','23.45495'), ('98831F3A:E:11',vbal1,'a1'), ('98831F3A:E:12',vbal2), ('98831F3A:E:21','2.345'), - (burn_addr + '\s+Non-MMGen',amt1)], + (burn_addr + r'\s+Non-MMGen',amt1)], '10': [ ('98831F3A:E:1','0'), ('98831F3A:E:2','23.0218'), ('98831F3A:E:3','0.4321'), ('98831F3A:E:11',vbal1,'a1'), ('98831F3A:E:12',vbal2), ('98831F3A:E:21','2.345'), - (burn_addr + '\s+Non-MMGen',amt1)] + (burn_addr + r'\s+Non-MMGen',amt1)] } token_bals = { @@ -120,18 +120,18 @@ token_bals = { ('98831F3A:E:12','1.23456','0')], '4': [ ('98831F3A:E:11','110.654317776666555545',vbal1,'a1'), ('98831F3A:E:12','1.23456','0'), - (burn_addr + '\s+Non-MMGen',amt2,amt1)], + (burn_addr + r'\s+Non-MMGen',amt2,amt1)], '5': [ ('98831F3A:E:11','110.654317776666555545',vbal1,'a1'), ('98831F3A:E:12','1.23456','99.99895'), - (burn_addr + '\s+Non-MMGen',amt2,amt1)], + (burn_addr + r'\s+Non-MMGen',amt2,amt1)], '6': [ ('98831F3A:E:11','110.654317776666555545',vbal1,'a1'), ('98831F3A:E:12','0',vbal2), ('98831F3A:E:13','1.23456','0'), - (burn_addr + '\s+Non-MMGen',amt2,amt1)], + (burn_addr + r'\s+Non-MMGen',amt2,amt1)], '7': [ ('98831F3A:E:11','67.444317776666555545',vbal9,'a2'), ('98831F3A:E:12','43.21',vbal2), ('98831F3A:E:13','1.23456','0'), - (burn_addr + '\s+Non-MMGen',amt2,amt1)] + (burn_addr + r'\s+Non-MMGen',amt2,amt1)] } token_bals_getbalance = { '1': (vbal4,'999999.12345689012345678'), @@ -696,7 +696,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): addr,_amt1,_amt2,adj = b if len(b) == 4 else b + (False,) if adj and self.proto.coin == 'ETC': _amt2 = str(Decimal(_amt2) + Decimal(adj[1]) * self.bal_corr) - pat = rf'{addr}\b.*\D{_amt1}\D.*\b{_amt2}\D' + pat = fr'{addr}\b.*\D{_amt1}\D.*\b{_amt2}\D' assert re.search(pat,text), pat ss = 'Total MM1:' assert re.search(ss,text),ss @@ -723,7 +723,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): def chk_label(self,lbl_pat,addr='98831F3A:E:3'): t = self.spawn('mmgen-tool', self.eth_args + ['listaddresses','all_labels=1']) - t.expect(rf'{addr}\b.*\S{{30}}\b.*{lbl_pat}\b',regex=True) + t.expect(fr'{addr}\b.*\S{{30}}\b.*{lbl_pat}\b',regex=True) return t def add_label1(self): return self.add_label(lbl=tw_label_zh) @@ -1084,7 +1084,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): t.expect(' main menu): ',n+'\n') t.expect('Is this what you want? (y/N): ','y') t.expect('[R]efresh balance:\b','q') - t.expect(f'Total unspent:.*\D{total}\D.*{total_coin}',regex=True) + t.expect(rf'Total unspent:.*\D{total}\D.*{total_coin}',regex=True) t.read() return t diff --git a/test/test_py_d/ts_main.py b/test/test_py_d/ts_main.py index fed7576b..51b3e748 100755 --- a/test/test_py_d/ts_main.py +++ b/test/test_py_d/ts_main.py @@ -497,7 +497,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): ([],['--rbf'])[self.proto.cap('rbf')] + ['-f',self.tx_fee,'-B'] + add_args + cmd_args + txdo_args) - if t.expect([('Get','Unsigned transac')[cmdline_inputs],'Unable to connect to \S+'],regex=True) == 1: + if t.expect([('Get','Unsigned transac')[cmdline_inputs],r'Unable to connect to \S+'],regex=True) == 1: raise TestSuiteException('\n'+t.p.after) if cmdline_inputs: @@ -665,7 +665,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): t.expect_getend('Incog Wallet ID: ') wcls = Wallet.fmt_code_to_type(in_fmt) t.hash_preset(wcls.desc,'1') - t.passphrase(f'{wcls.desc} \w{{8}}',self.wpasswd) + t.passphrase(rf'{wcls.desc} \w{{8}}',self.wpasswd) vmsg('Comparing generated checksum with checksum from address file') chk = t.expect_getend(r'Checksum for address data .*?: ',regex=True) verify_checksum_or_exit(self._get_addrfile_checksum(),chk) diff --git a/test/test_py_d/ts_shared.py b/test/test_py_d/ts_shared.py index 46929d51..c8e08ee6 100755 --- a/test/test_py_d/ts_shared.py +++ b/test/test_py_d/ts_shared.py @@ -150,7 +150,7 @@ class TestSuiteShared(object): def txsign_end(self,t,tnum=None,has_label=False): t.expect('Signing transaction') t.do_comment(False,has_label=has_label) - t.expect('Save signed transaction.*?\? \(Y/n\): ','y',regex=True) + t.expect(r'Save signed transaction.*?\? \(Y/n\): ','y',regex=True) t.written_to_file('Signed transaction' + (' #' + tnum if tnum else ''), oo=True) return t diff --git a/test/test_py_d/ts_xmrwallet.py b/test/test_py_d/ts_xmrwallet.py index 228251f7..fb0a5bf3 100755 --- a/test/test_py_d/ts_xmrwallet.py +++ b/test/test_py_d/ts_xmrwallet.py @@ -377,11 +377,11 @@ class TestSuiteXMRWallet(TestSuiteBase): if op == 'sweep': t.expect( - 'Create new {} .* \(y/N\): '.format(('address','account')[',' in arg2]), + r'Create new {} .* \(y/N\): '.format(('address','account')[',' in arg2]), ('y','n')[reuse_acct], regex=True ) if reuse_acct: - t.expect( 'to last existing account .* \(y/N\): ','y', regex=True ) + t.expect( r'to last existing account .* \(y/N\): ','y', regex=True ) if return_amt: amt = XMRAmt(strip_ansi_escapes(t.expect_getend('Amt: ')).replace('XMR','').strip()) diff --git a/test/tooltest2.py b/test/tooltest2.py index f674f237..bb0b9de8 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -56,7 +56,7 @@ def md5_hash(s): def md5_hash_strip(s): import re - s = re.sub('\x1b\[[;0-9]+?m','',s) # strip ANSI color sequences + s = re.sub('\x1b' + r'\[[;0-9]+?m','',s) # strip ANSI color sequences s = s.replace(NL,'\n') # fix DOS newlines return md5_hash(s.strip())