mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-21 12:18:13 +02:00
Explicitly specify encoding when opening text files in Python code
This commit is contained in:
@@ -36,7 +36,7 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
wait_until(lambda: os.path.isfile(self.block_filename) and os.stat(self.block_filename).st_size >= (block_count * 65), timeout=10)
|
||||
|
||||
# file content should equal the generated blocks hashes
|
||||
with open(self.block_filename, 'r') as f:
|
||||
with open(self.block_filename, 'r', encoding="utf-8") as f:
|
||||
assert_equal(sorted(blocks), sorted(l.strip() for l in f.read().splitlines()))
|
||||
|
||||
self.log.info("test -walletnotify")
|
||||
@@ -45,7 +45,7 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
|
||||
# file content should equal the generated transaction hashes
|
||||
txids_rpc = list(map(lambda t: t['txid'], self.nodes[1].listtransactions("*", block_count)))
|
||||
with open(self.tx_filename, 'r') as f:
|
||||
with open(self.tx_filename, 'r', encoding="ascii") as f:
|
||||
assert_equal(sorted(txids_rpc), sorted(l.strip() for l in f.read().splitlines()))
|
||||
os.remove(self.tx_filename)
|
||||
|
||||
@@ -58,7 +58,7 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
|
||||
# file content should equal the generated transaction hashes
|
||||
txids_rpc = list(map(lambda t: t['txid'], self.nodes[1].listtransactions("*", block_count)))
|
||||
with open(self.tx_filename, 'r') as f:
|
||||
with open(self.tx_filename, 'r', encoding="ascii") as f:
|
||||
assert_equal(sorted(txids_rpc), sorted(l.strip() for l in f.read().splitlines()))
|
||||
|
||||
# Mine another 41 up-version blocks. -alertnotify should trigger on the 51st.
|
||||
|
||||
@@ -81,11 +81,11 @@ class GetblockstatsTest(BitcoinTestFramework):
|
||||
'mocktime': int(mocktime),
|
||||
'stats': self.expected_stats,
|
||||
}
|
||||
with open(filename, 'w') as f:
|
||||
with open(filename, 'w', encoding="utf8") as f:
|
||||
json.dump(to_dump, f, sort_keys=True, indent=2)
|
||||
|
||||
def load_test_data(self, filename):
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename, 'r', encoding="utf8") as f:
|
||||
d = json.load(f)
|
||||
blocks = d['blocks']
|
||||
mocktime = d['mocktime']
|
||||
|
||||
@@ -327,7 +327,7 @@ def get_auth_cookie(datadir):
|
||||
assert password is None # Ensure that there is only one rpcpassword line
|
||||
password = line.split("=")[1].strip("\n")
|
||||
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
|
||||
with open(os.path.join(datadir, "regtest", ".cookie"), 'r') as f:
|
||||
with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f:
|
||||
userpass = f.read()
|
||||
split_userpass = userpass.split(':')
|
||||
user = split_userpass[0]
|
||||
|
||||
@@ -213,7 +213,7 @@ def main():
|
||||
# Read config generated by configure.
|
||||
config = configparser.ConfigParser()
|
||||
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
|
||||
config.read_file(open(configfile))
|
||||
config.read_file(open(configfile, encoding="utf8"))
|
||||
|
||||
passon_args.append("--configfile=%s" % configfile)
|
||||
|
||||
@@ -590,7 +590,7 @@ class RPCCoverage():
|
||||
if not os.path.isfile(coverage_ref_filename):
|
||||
raise RuntimeError("No coverage reference found")
|
||||
|
||||
with open(coverage_ref_filename, 'r') as coverage_ref_file:
|
||||
with open(coverage_ref_filename, 'r', encoding="utf8") as coverage_ref_file:
|
||||
all_cmds.update([line.strip() for line in coverage_ref_file.readlines()])
|
||||
|
||||
for root, dirs, files in os.walk(self.dir):
|
||||
@@ -599,7 +599,7 @@ class RPCCoverage():
|
||||
coverage_filenames.add(os.path.join(root, filename))
|
||||
|
||||
for filename in coverage_filenames:
|
||||
with open(filename, 'r') as coverage_file:
|
||||
with open(filename, 'r', encoding="utf8") as coverage_file:
|
||||
covered_cmds.update([line.strip() for line in coverage_file.readlines()])
|
||||
|
||||
return all_cmds - covered_cmds
|
||||
|
||||
@@ -88,7 +88,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
self.nodes[0].assert_start_raises_init_error(['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist')
|
||||
# should not initialize if the specified walletdir is not a directory
|
||||
not_a_dir = wallet_dir('notadir')
|
||||
open(not_a_dir, 'a').close()
|
||||
open(not_a_dir, 'a', encoding="utf8").close()
|
||||
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
|
||||
|
||||
self.log.info("Do not allow -zapwallettxes with multiwallet")
|
||||
|
||||
Reference in New Issue
Block a user