contrib: Remove confusing and redundant encoding from IO
What changed, and why it matters
This commit removes explicit 'UTF-8' encoding declarations from dozens of helper and test scripts in the Bitcoin Core repository. In Python 3, removing the encoding argument makes file operations fall back to the system's default locale encoding. On most modern systems that default is UTF-8, so the change is intended to be a no-op cleanup. However, on systems where the locale is not UTF-8, some scripts could fail or behave differently when reading files that contain non-ASCII characters. The commit deliberately keeps explicit UTF-8 handling in the two places where it actually matters.
No immediate security action is required. Treat this as a code-quality change. If the project supports running these scripts on non-UTF-8 locales, consider verifying that the two retained explicit encodings are sufficient and that no script reads user-controlled data that could contain non-ASCII bytes. CI environments should ensure `PYTHONUTF8=1` or a UTF-8 locale to avoid portability issues.
Security signals we found
Behavior depends on system locale encoding after removing explicit UTF-8
Potential for inconsistent handling of non-ASCII input on non-UTF-8 systems
No input validation or sanitization changes
No changes to cryptographic, consensus, or P2P code
Change is limited to development, CI, and test tooling
Evidence from the diff
The patch deletes the encoding='utf-8' (or utf8) parameter from open(), subprocess.check_output(..., text=True), and logging.FileHandler() calls across 54 files under contrib/, ci/, and test/. Python 3 then uses locale.getpreferredencoding(False). The author argues this is safe because most files are ASCII and the project already requires UTF-8. Two files retain explicit encoding: contrib/asmap/asmap-tool.py (it intentionally tests for UTF-8 decode errors) and test/functional/test_framework/test_node.py (it counts UTF-8 characters in the debug log). No C++ node code is touched, so consensus, networking, and wallet logic are unaffected.
Changed components
ci/test/02_run_container.pycontrib/devtools/circular-dependencies.pycontrib/devtools/clang-format-diff.pycontrib/devtools/copyright_header.pycontrib/filter-lcov.pycontrib/linearize/linearize-data.pycontrib/linearize/linearize-hashes.pycontrib/message-capture/message-capture-parser.pycontrib/seeds/generate-seeds.pycontrib/seeds/makeseeds.pycontrib/verify-binaries/verify.pycontrib/verify-commits/verify-commits.pytest/functional/combine_logs.pytest/functional/feature_asmap.pytest/functional/feature_config_args.pytest/functional/feature_includeconf.pytest/functional/feature_loadblock.pytest/functional/feature_notifications.pytest/functional/feature_startupnotify.pytest/functional/feature_taproot.pytest/functional/feature_versionbits_warning.pytest/functional/mining_mainnet.pytest/functional/mocks/invalid_signer.pytest/functional/mocks/signer.pytest/functional/rpc_createmultisig.pytest/functional/rpc_decodescript.pytest/functional/rpc_getblockstats.pytest/functional/rpc_help.pytest/functional/rpc_psbt.pytest/functional/rpc_signer.pytest/functional/rpc_users.pytest/functional/rpc_whitelist.pytest/functional/test_framework/coverage.pytest/functional/test_framework/crypto/ellswift.pytest/functional/test_framework/key.pytest/functional/test_framework/netutil.pytest/functional/test_framework/test_framework.pytest/functional/test_framework/test_node.pytest/functional/test_framework/util.pytest/functional/test_runner.pytest/functional/tool_utils.pytest/functional/tool_wallet.pytest/functional/wallet_backup.pytest/functional/wallet_backwards_compatibility.pytest/functional/wallet_encryption.pytest/functional/wallet_multiwallet.pytest/functional/wallet_signer.pytest/fuzz/test_runner.pytest/lint/lint-files.pytest/lint/lint-include-guards.pytest/lint/lint-includes.pytest/lint/lint-locale-dependence.pytest/lint/lint-shell-locale.pytest/lint/lint-tests.pyInspect captured patch +127 / −128
diff --git a/ci/test/02_run_container.py b/ci/test/02_run_container.py
index 4d0bed2a..311fe923 100755
--- a/ci/test/02_run_container.py
+++ b/ci/test/02_run_container.py
@@ -26,7 +26,6 @@ def main():
["bash", "-c", "grep export ./ci/test/00_setup_env*.sh"],
stdout=subprocess.PIPE,
text=True,
- encoding="utf8",
).stdout.splitlines()
settings = set(l.split("=")[0].split("export ")[1] for l in settings)
# Add "hidden" settings, which are never exported, manually. Otherwise,
@@ -42,7 +41,7 @@ def main():
u=os.environ["USER"],
c=os.environ["CONTAINER_NAME"],
)
- with open(env_file, "w", encoding="utf8") as file:
+ with open(env_file, "w") as file:
for k, v in os.environ.items():
if k in settings:
file.write(f"{k}={v}\n")
diff --git a/contrib/devtools/circular-dependencies.py b/contrib/devtools/circular-dependencies.py
index b742a8ce..09362c9f 100755
--- a/contrib/devtools/circular-dependencies.py
+++ b/contrib/devtools/circular-dependencies.py
@@ -49,7 +49,7 @@ for arg in sys.argv[1:]:
# TODO: implement support for multiple include directories
for arg in sorted(files.keys()):
module = files[arg]
- with open(arg, 'r', encoding="utf8") as f:
+ with open(arg, 'r') as f:
for line in f:
match = RE.match(line)
if match:
diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py
index 30e804db..f3515631 100755
--- a/contrib/devtools/clang-format-diff.py
+++ b/contrib/devtools/clang-format-diff.py
@@ -169,7 +169,7 @@ def main():
sys.exit(p.returncode)
if not args.i:
- with open(filename, encoding="utf8") as f:
+ with open(filename) as f:
code = f.readlines()
formatted_code = StringIO(stdout).readlines()
diff = difflib.unified_diff(
diff --git a/contrib/devtools/copyright_header.py b/contrib/devtools/copyright_header.py
index 12d72764..39b67ec4 100755
--- a/contrib/devtools/copyright_header.py
+++ b/contrib/devtools/copyright_header.py
@@ -140,7 +140,7 @@ def file_has_without_c_style_copyright_for_holder(contents, holder_name):
################################################################################
def read_file(filename):
- return open(filename, 'r', encoding="utf8").read()
+ return open(filename, 'r').read()
def gather_file_info(filename):
info = {}
@@ -316,12 +316,12 @@ def get_most_recent_git_change_year(filename):
################################################################################
def read_file_lines(filename):
- with open(filename, 'r', encoding="utf8") as f:
+ with open(filename, 'r') as f:
file_lines = f.readlines()
return file_lines
def write_file_lines(filename, file_lines):
- with open(filename, 'w', encoding="utf8") as f:
+ with open(filename, 'w') as f:
f.write(''.join(file_lines))
################################################################################
diff --git a/contrib/filter-lcov.py b/contrib/filter-lcov.py
index db780ad5..373dfe3e 100755
--- a/contrib/filter-lcov.py
+++ b/contrib/filter-lcov.py
@@ -16,8 +16,8 @@ pattern = args.pattern
outfile = args.outfile
in_remove = False
-with open(tracefile, 'r', encoding="utf8") as f:
- with open(outfile, 'w', encoding="utf8") as wf:
+with open(tracefile, 'r') as f:
+ with open(outfile, 'w') as wf:
for line in f:
for p in pattern:
if line.startswith("SF:") and p in line:
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index 74d98307..1613f5ca 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -34,7 +34,7 @@ def get_blk_dt(blk_hdr):
# When getting the list of block hashes, undo any byte reversals.
def get_block_hashes(settings):
blkindex = []
- with open(settings['hashlist'], "r", encoding="utf8") as f:
+ with open(settings['hashlist'], "r") as f:
for line in f:
line = line.rstrip()
if settings['rev_hash_bytes'] == 'true':
@@ -267,7 +267,7 @@ if __name__ == '__main__':
print("Usage: linearize-data.py CONFIG-FILE")
sys.exit(1)
- with open(sys.argv[1], encoding="utf8") as f:
+ with open(sys.argv[1]) as f:
for line in f:
# skip comment lines
m = re.search(r'^\s*#', line)
diff --git a/contrib/linearize/linearize-hashes.py b/contrib/linearize/linearize-hashes.py
index 695bafad..ddd9a7ba 100755
--- a/contrib/linearize/linearize-hashes.py
+++ b/contrib/linearize/linearize-hashes.py
@@ -87,7 +87,7 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
def get_rpc_cookie():
# Open the cookie file
- with open(os.path.join(os.path.expanduser(settings['datadir']), '.cookie'), 'r', encoding="ascii") as f:
+ with open(os.path.join(os.path.expanduser(settings['datadir']), '.cookie'), 'r') as f:
combined = f.readline()
combined_split = combined.split(":")
settings['rpcuser'] = combined_split[0]
@@ -98,7 +98,7 @@ if __name__ == '__main__':
print("Usage: linearize-hashes.py CONFIG-FILE")
sys.exit(1)
- with open(sys.argv[1], encoding="utf8") as f:
+ with open(sys.argv[1]) as f:
for line in f:
# skip comment lines
m = re.search(r'^\s*#', line)
diff --git a/contrib/message-capture/message-capture-parser.py b/contrib/message-capture/message-capture-parser.py
index 0f409717..19ab8d02 100755
--- a/contrib/message-capture/message-capture-parser.py
+++ b/contrib/message-capture/message-capture-parser.py
@@ -205,7 +205,7 @@ def main():
jsonrep = json.dumps(messages)
if output:
- with open(str(output), 'w+', encoding="utf8") as f_out:
+ with open(str(output), 'w+') as f_out:
f_out.write(jsonrep)
else:
print(jsonrep)
diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py
index a3ce0122..41261091 100755
--- a/contrib/seeds/generate-seeds.py
+++ b/contrib/seeds/generate-seeds.py
@@ -168,16 +168,16 @@ def main():
g.write(' *\n')
g.write(' * Each line contains a BIP155 serialized (networkID, addr, port) tuple.\n')
g.write(' */\n')
- with open(os.path.join(indir,'nodes_main.txt'), 'r', encoding="utf8") as f:
+ with open(os.path.join(indir,'nodes_main.txt'), 'r') as f:
process_nodes(g, f, 'chainparams_seed_main')
g.write('\n')
- with open(os.path.join(indir,'nodes_signet.txt'), 'r', encoding="utf8") as f:
+ with open(os.path.join(indir,'nodes_signet.txt'), 'r') as f:
process_nodes(g, f, 'chainparams_seed_signet')
g.write('\n')
- with open(os.path.join(indir,'nodes_test.txt'), 'r', encoding="utf8") as f:
+ with open(os.path.join(indir,'nodes_test.txt'), 'r') as f:
process_nodes(g, f, 'chainparams_seed_test')
g.write('\n')
- with open(os.path.join(indir,'nodes_testnet4.txt'), 'r', encoding="utf8") as f:
+ with open(os.path.join(indir,'nodes_testnet4.txt'), 'r') as f:
process_nodes(g, f, 'chainparams_seed_testnet4')
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')
diff --git a/contrib/seeds/makeseeds.py b/contrib/seeds/makeseeds.py
index 0e5826ef..1cb96039 100755
--- a/contrib/seeds/makeseeds.py
+++ b/contrib/seeds/makeseeds.py
@@ -211,7 +211,7 @@ def main():
print('Done.', file=sys.stderr)
print('Loading and parsing DNS seeds…', end='', file=sys.stderr, flush=True)
- with open(args.seeds, 'r', encoding='utf8') as f:
+ with open(args.seeds, 'r') as f:
lines = f.readlines()
ips = [parseline(line) for line in lines]
random.shuffle(ips)
diff --git a/contrib/verify-binaries/verify.py b/contrib/verify-binaries/verify.py
index 6c07b36c..6f5a933f 100755
--- a/contrib/verify-binaries/verify.py
+++ b/contrib/verify-binaries/verify.py
@@ -246,8 +246,8 @@ def files_are_equal(filename1, filename2):
eq = contents1 == contents2
if not eq:
- with open(filename1, 'r', encoding='utf-8') as f1, \
- open(filename2, 'r', encoding='utf-8') as f2:
+ with open(filename1, 'r') as f1, \
+ open(filename2, 'r') as f2:
f1lines = f1.readlines()
f2lines = f2.readlines()
@@ -426,7 +426,7 @@ def verify_shasums_signature(
def parse_sums_file(sums_file_path: str, filename_filter: list[str]) -> list[list[str]]:
# extract hashes/filenames of binaries to verify from hash file;
# each line has the following format: "<hash> <binary_filename>"
- with open(sums_file_path, 'r', encoding='utf8') as hash_file:
+ with open(sums_file_path, 'r') as hash_file:
return [line.split()[:2] for line in hash_file if len(filename_filter) == 0 or any(f in line for f in filename_filter)]
diff --git a/contrib/verify-commits/verify-commits.py b/contrib/verify-commits/verify-commits.py
index a1fe78a6..808f26ed 100755
--- a/contrib/verify-commits/verify-commits.py
+++ b/contrib/verify-commits/verify-commits.py
@@ -82,17 +82,17 @@ def main():
# get directory of this program and read data files
dirname = os.path.dirname(os.path.abspath(__file__))
print("Using verify-commits data from " + dirname)
- with open(dirname + "/trusted-git-root", "r", encoding="utf8") as f:
+ with open(dirname + "/trusted-git-root", "r") as f:
verified_root = f.read().splitlines()[0]
- with open(dirname + "/trusted-sha512-root-commit", "r", encoding="utf8") as f:
+ with open(dirname + "/trusted-sha512-root-commit", "r") as f:
verified_sha512_root = f.read().splitlines()[0]
- with open(dirname + "/allow-revsig-commits", "r", encoding="utf8") as f:
+ with open(dirname + "/allow-revsig-commits", "r") as f:
revsig_allowed = f.read().splitlines()
- with open(dirname + "/allow-unclean-merge-commits", "r", encoding="utf8") as f:
+ with open(dirname + "/allow-unclean-merge-commits", "r") as f:
unclean_merge_allowed = f.read().splitlines()
- with open(dirname + "/allow-incorrect-sha512-commits", "r", encoding="utf8") as f:
+ with open(dirname + "/allow-incorrect-sha512-commits", "r") as f:
incorrect_sha512_allowed = f.read().splitlines()
- with open(dirname + "/trusted-keys", "r", encoding="utf8") as f:
+ with open(dirname + "/trusted-keys", "r") as f:
trusted_keys = f.read().splitlines()
# Set commit and variables
diff --git a/test/functional/combine_logs.py b/test/functional/combine_logs.py
index 998cb208..c4e46732 100755
--- a/test/functional/combine_logs.py
+++ b/test/functional/combine_logs.py
@@ -148,7 +148,7 @@ def get_log_events(source, logfile):
Log events may be split over multiple lines. We use the timestamp
regex match as the marker for a new log event."""
try:
- with open(logfile, 'r', encoding='utf-8') as infile:
+ with open(logfile, 'r') as infile:
event = ''
timestamp = ''
for line in infile:
diff --git a/test/functional/feature_asmap.py b/test/functional/feature_asmap.py
index eef599f1..139725bb 100755
--- a/test/functional/feature_asmap.py
+++ b/test/functional/feature_asmap.py
@@ -97,7 +97,7 @@ class AsmapTest(BitcoinTestFramework):
self.log.info('Test bitcoind -asmap with empty map file')
self.stop_node(0)
empty_asmap = os.path.join(self.datadir, "ip_asn.map")
- with open(empty_asmap, "w", encoding="utf-8") as f:
+ with open(empty_asmap, "w") as f:
f.write("")
msg = f"Error: Could not parse asmap file \"{empty_asmap}\""
self.node.assert_start_raises_init_error(extra_args=[f'-asmap={empty_asmap}'], expected_msg=msg)
diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py
index 441c21f0..14a5115a 100755
--- a/test/functional/feature_config_args.py
+++ b/test/functional/feature_config_args.py
@@ -55,7 +55,7 @@ class ConfArgsTest(BitcoinTestFramework):
os.rename(conf_path.with_suffix('.confbkp'), conf_path)
self.log.debug('Verifying includeconf directive pointing to directory is caught')
- with open(conf_path, 'a', encoding='utf-8') as conf:
+ with open(conf_path, 'a') as conf:
conf.write(f'includeconf={self.nodes[0].datadir_path}\n')
self.nodes[0].assert_start_raises_init_error(
extra_args=['-regtest'],
@@ -68,12 +68,12 @@ class ConfArgsTest(BitcoinTestFramework):
self.log.info('Disabling configuration via -noconf')
conf_path = self.nodes[0].datadir_path / 'bitcoin.conf'
- with open(conf_path, encoding='utf-8') as conf:
+ with open(conf_path) as conf:
settings = [f'-{line.rstrip()}' for line in conf if len(line) > 1 and line[0] != '[']
os.rename(conf_path, conf_path.with_suffix('.confbkp'))
self.log.debug('Verifying garbage in config can be detected')
- with open(conf_path, 'a', encoding='utf-8') as conf:
+ with open(conf_path, 'a') as conf:
conf.write('garbage\n')
self.nodes[0].assert_start_raises_init_error(
extra_args=['-regtest'],
@@ -107,9 +107,9 @@ class ConfArgsTest(BitcoinTestFramework):
expected_msg=conf_in_config_file_err,
)
inc_conf_file_path = self.nodes[0].datadir_path / 'include.conf'
- with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a', encoding='utf-8') as conf:
+ with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a') as conf:
conf.write(f'includeconf={inc_conf_file_path}\n')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('conf=some.conf\n')
self.nodes[0].assert_start_raises_init_error(
expected_msg=conf_in_config_file_err,
@@ -119,65 +119,65 @@ class ConfArgsTest(BitcoinTestFramework):
expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli=1',
extra_args=['-dash_cli=1'],
)
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('dash_conf=1\n')
with self.nodes[0].assert_debug_log(expected_msgs=['Ignoring unknown configuration value dash_conf']):
self.start_node(0)
self.stop_node(0)
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('reindex=1\n')
with self.nodes[0].assert_debug_log(expected_msgs=['Warning: reindex=1 is set in the configuration file, which will significantly slow down startup. Consider removing or commenting out this option for better performance, unless there is currently a condition which makes rebuilding the indexes necessary']):
self.start_node(0)
self.stop_node(0)
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('-dash=1\n')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 1: -dash=1, options in configuration file must be specified without leading -')
if self.is_wallet_compiled():
- with open(inc_conf_file_path, 'w', encoding='utf8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write("wallet=foo\n")
self.nodes[0].assert_start_raises_init_error(expected_msg=f'Error: Config setting for -wallet only applied on {self.chain} network when in [{self.chain}] section.')
main_conf_file_path = self.nodes[0].datadir_path / "bitcoin_main.conf"
util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('acceptnonstdtxn=1\n')
self.nodes[0].assert_start_raises_init_error(extra_args=[f"-conf={main_conf_file_path}", "-allowignoredconf"], expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('nono\n')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('server=1\nrpcuser=someuser\nmain.rpcpassword=some#pass')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('server=1\nrpcuser=someuser\n[main]\nrpcpassword=some#pass')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 4, using # in rpcpassword can be ambiguous and should be avoided')
inc_conf_file2_path = self.nodes[0].datadir_path / 'include2.conf'
- with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a', encoding='utf-8') as conf:
+ with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a') as conf:
conf.write(f'includeconf={inc_conf_file2_path}\n')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('testnot.datadir=1\n')
- with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file2_path, 'w') as conf:
conf.write('[testnet]\n')
self.restart_node(0)
self.nodes[0].stop_node(expected_stderr=f'Warning: {inc_conf_file_path}:1 Section [testnot] is not recognized.{os.linesep}{inc_conf_file2_path}:1 Section [testnet] is not recognized.')
- with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file_path, 'w') as conf:
conf.write('') # clear
- with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
+ with open(inc_conf_file2_path, 'w') as conf:
conf.write('') # clear
def test_config_file_log(self):
@@ -522,9 +522,9 @@ class ConfArgsTest(BitcoinTestFramework):
conf_file = default_data_dir / "bitcoin.conf"
# datadir needs to be set before [chain] section
- with open(conf_file, encoding='utf8') as f:
+ with open(conf_file) as f:
conf_file_contents = f.read()
- with open(conf_file, 'w', encoding='utf8') as f:
+ with open(conf_file, 'w') as f:
f.write(f"datadir={new_data_dir}\n")
f.write(conf_file_contents)
diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py
index ee484e7e..a416b229 100755
--- a/test/functional/feature_includeconf.py
+++ b/test/functional/feature_includeconf.py
@@ -24,12 +24,12 @@ class IncludeConfTest(BitcoinTestFramework):
def run_test(self):
# Create additional config files
# - tmpdir/node0/relative.conf
- with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:
f.write("uacomment=relative\n")
# - tmpdir/node0/relative2.conf
- with open(self.nodes[0].datadir_path / "relative2.conf", "w", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "relative2.conf", "w") as f:
f.write("uacomment=relative2\n")
- with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
f.write("uacomment=main\nincludeconf=relative.conf\n")
self.restart_node(0)
@@ -50,7 +50,7 @@ class IncludeConfTest(BitcoinTestFramework):
)
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
- with open(self.nodes[0].datadir_path / "relative.conf", "a", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "relative.conf", "a") as f:
f.write("includeconf=relative2.conf\n")
self.start_node(0)
@@ -61,7 +61,7 @@ class IncludeConfTest(BitcoinTestFramework):
self.log.info("-includeconf cannot contain invalid arg")
# Commented out as long as we ignore invalid arguments in configuration files
- #with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
+ #with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:
# f.write("foo=bar\n")
#self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Invalid configuration value foo")
@@ -70,11 +70,11 @@ class IncludeConfTest(BitcoinTestFramework):
self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf")
self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")
- with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:
# Restore initial file contents
f.write("uacomment=relative\n")
- with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
f.write("includeconf=relative2.conf\n")
self.start_node(0)
diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py
index 0e6ec14c..2bf700d1 100755
--- a/test/functional/feature_loadblock.py
+++ b/test/functional/feature_loadblock.py
@@ -41,10 +41,10 @@ class LoadblockTest(BitcoinTestFramework):
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
mode='w',
delete=False,
- encoding="utf-8")
+ )
self.log.info("Create linearization config file")
- with open(cfg_file, "a", encoding="utf-8") as cfg:
+ with open(cfg_file, "a") as cfg:
cfg.write(f"datadir={data_dir}\n")
cfg.write(f"rpcuser={node_url.username}\n")
cfg.write(f"rpcpassword={node_url.password}\n")
diff --git a/test/functional/feature_notifications.py b/test/functional/feature_notifications.py
index 519d80b9..12bc6b18 100755
--- a/test/functional/feature_notifications.py
+++ b/test/functional/feature_notifications.py
@@ -200,7 +200,7 @@ class NotificationsTest(BitcoinTestFramework):
self.wait_until(lambda: os.path.isfile(self.shutdownnotify_file), timeout=10)
def large_work_invalid_chain_warning_in_alert_file(self):
- with open(self.alertnotify_file, 'r', encoding='utf8') as f:
+ with open(self.alertnotify_file, 'r') as f:
alert_text = f.read()
return LARGE_WORK_INVALID_CHAIN_WARNING in alert_text
@@ -213,7 +213,7 @@ class NotificationsTest(BitcoinTestFramework):
fname = os.path.join(self.walletnotify_dir, notify_outputname(self.wallet, tx_id))
# Wait for the cached writes to hit storage
self.wait_until(lambda: os.path.getsize(fname) > 0, timeout=10)
- with open(fname, 'rt', encoding='utf-8') as f:
+ with open(fname, 'rt') as f:
text = f.read()
# Universal newline ensures '\n' on 'nt'
assert_equal(text[-1], '\n')
diff --git a/test/functional/feature_startupnotify.py b/test/functional/feature_startupnotify.py
index 1e071037..d9c2f864 100755
--- a/test/functional/feature_startupnotify.py
+++ b/test/functional/feature_startupnotify.py
@@ -27,7 +27,7 @@ class StartupNotifyTest(BitcoinTestFramework):
self.log.info("Test -startupnotify is executed once")
def get_count():
- with open(tmpdir_file, "r", encoding="utf8") as f:
+ with open(tmpdir_file, "r") as f:
file_content = f.read()
return file_content.count(FILE_NAME)
diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py
index 24cb26a3..d3c1ac03 100755
--- a/test/functional/feature_taproot.py
+++ b/test/functional/feature_taproot.py
@@ -1396,7 +1396,7 @@ def dump_json_test(tx, input_utxos, idx, success, failure):
sha1 = hashlib.sha1(dump.encode("utf-8")).hexdigest()
dirname = os.environ.get("TEST_DUMP_DIR", ".") + ("/%s" % sha1[0])
os.makedirs(dirname, exist_ok=True)
- with open(dirname + ("/%s" % sha1), 'w', encoding="utf8") as f:
+ with open(dirname + ("/%s" % sha1), 'w') as f:
f.write(dump)
# Data type to keep track of UTXOs, where they were created, and how to spend them.
diff --git a/test/functional/feature_versionbits_warning.py b/test/functional/feature_versionbits_warning.py
index 96ec7c57..bc4b6791 100755
--- a/test/functional/feature_versionbits_warning.py
+++ b/test/functional/feature_versionbits_warning.py
@@ -32,7 +32,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
def setup_network(self):
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
# Open and close to create zero-length file
- with open(self.alert_filename, 'w', encoding='utf8'):
+ with open(self.alert_filename, 'w'):
pass
self.extra_args = [[f"-alertnotify=echo %s >> \"{self.alert_filename}\""]]
self.setup_nodes()
@@ -55,7 +55,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
def versionbits_in_alert_file(self):
"""Test that the versionbits warning has been written to the alert file."""
- with open(self.alert_filename, 'r', encoding='utf8') as f:
+ with open(self.alert_filename, 'r') as f:
alert_text = f.read()
return VB_PATTERN.search(alert_text) is not None
diff --git a/test/functional/mining_mainnet.py b/test/functional/mining_mainnet.py
index 67219100..122ea481 100755
--- a/test/functional/mining_mainnet.py
+++ b/test/functional/mining_mainnet.py
@@ -83,7 +83,7 @@ class MiningMainnetTest(BitcoinTestFramework):
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), self.options.datafile)
prev_hash = node.getbestblockhash()
blocks = None
- with open(path, encoding='utf-8') as f:
+ with open(path) as f:
blocks = json.load(f)
n_blocks = len(blocks['timestamps'])
assert_equal(n_blocks, 2016)
diff --git a/test/functional/mocks/invalid_signer.py b/test/functional/mocks/invalid_signer.py
index 7bfa9051..b9a5c2a1 100755
--- a/test/functional/mocks/invalid_signer.py
+++ b/test/functional/mocks/invalid_signer.py
@@ -11,7 +11,7 @@ import json
def perform_pre_checks():
mock_result_path = os.path.join(os.getcwd(), "mock_result")
if os.path.isfile(mock_result_path):
- with open(mock_result_path, "r", encoding="utf8") as f:
+ with open(mock_result_path, "r") as f:
mock_result = f.read()
if mock_result[0]:
sys.stdout.write(mock_result[2:])
diff --git a/test/functional/mocks/signer.py b/test/functional/mocks/signer.py
index 23d163aa..da5d9d9f 100755
--- a/test/functional/mocks/signer.py
+++ b/test/functional/mocks/signer.py
@@ -11,7 +11,7 @@ import json
def perform_pre_checks():
mock_result_path = os.path.join(os.getcwd(), "mock_result")
if os.path.isfile(mock_result_path):
- with open(mock_result_path, "r", encoding="utf8") as f:
+ with open(mock_result_path, "r") as f:
mock_result = f.read()
if mock_result[0]:
sys.stdout.write(mock_result[2:])
@@ -60,7 +60,7 @@ def signtx(args):
if args.fingerprint != "00000001":
return sys.stdout.write(json.dumps({"error": "Unexpected fingerprint", "fingerprint": args.fingerprint}))
- with open(os.path.join(os.getcwd(), "mock_psbt"), "r", encoding="utf8") as f:
+ with open(os.path.join(os.getcwd(), "mock_psbt"), "r") as f:
mock_psbt = f.read()
if args.fingerprint == "00000001" :
diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py
index 1675aa0c..5ae6c39e 100755
--- a/test/functional/rpc_createmultisig.py
+++ b/test/functional/rpc_createmultisig.py
@@ -184,7 +184,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
def test_sortedmulti_descriptors_bip67(self):
self.log.info('Testing sortedmulti descriptors with BIP 67 test vectors')
- with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f:
+ with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json')) as f:
vectors = json.load(f)
for t in vectors:
diff --git a/test/functional/rpc_decodescript.py b/test/functional/rpc_decodescript.py
index 4f127fa8..40a53ce2 100755
--- a/test/functional/rpc_decodescript.py
+++ b/test/functional/rpc_decodescript.py
@@ -266,7 +266,7 @@ class DecodeScriptTest(BitcoinTestFramework):
assert_equal('OP_RETURN 3011020701010101010101020601010101010101', rpc_result['vin'][0]['scriptSig']['asm'])
def decodescript_datadriven_tests(self):
- with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_decodescript.json'), encoding='utf-8') as f:
+ with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_decodescript.json')) as f:
dd_tests = json.load(f)
for script, result in dd_tests:
diff --git a/test/functional/rpc_getblockstats.py b/test/functional/rpc_getblockstats.py
index 7def4f8f..fee23d20 100755
--- a/test/functional/rpc_getblockstats.py
+++ b/test/functional/rpc_getblockstats.py
@@ -78,11 +78,11 @@ class GetblockstatsTest(BitcoinTestFramework):
'mocktime': int(mocktime),
'stats': self.expected_stats,
}
- with open(filename, 'w', encoding="utf8") as f:
+ with open(filename, 'w') as f:
json.dump(to_dump, f, sort_keys=True, indent=2)
def load_test_data(self, filename):
- with open(filename, 'r', encoding="utf8") as f:
+ with open(filename, 'r') as f:
d = json.load(f)
blocks = d['blocks']
mocktime = d['mocktime']
diff --git a/test/functional/rpc_help.py b/test/functional/rpc_help.py
index 74d34ddc..92ee5d15 100755
--- a/test/functional/rpc_help.py
+++ b/test/functional/rpc_help.py
@@ -22,7 +22,7 @@ def process_mapping(fname):
cmds = []
string_params = []
in_rpcs = False
- with open(fname, "r", encoding="utf8") as f:
+ with open(fname, "r") as f:
for line in f:
line = line.rstrip()
if not in_rpcs:
@@ -153,7 +153,7 @@ class HelpRpcTest(BitcoinTestFramework):
os.mkdir(dump_dir)
calls = [line.split(' ', 1)[0] for line in self.nodes[0].help().splitlines() if line and not line.startswith('==')]
for call in calls:
- with open(os.path.join(dump_dir, call), 'w', encoding='utf-8') as f:
+ with open(os.path.join(dump_dir, call), 'w') as f:
# Make sure the node can generate the help at runtime without crashing
f.write(self.nodes[0].help(call))
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
index 3943abce..1cd2a1da 100755
--- a/test/functional/rpc_psbt.py
+++ b/test/functional/rpc_psbt.py
@@ -799,7 +799,7 @@ class PSBTTest(BitcoinTestFramework):
assert_equal(unknown_psbt, unknown_out)
# Open the data file
- with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_psbt.json'), encoding='utf-8') as f:
+ with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_psbt.json')) as f:
d = json.load(f)
invalids = d['invalid']
invalid_with_msgs = d["invalid_with_msg"]
diff --git a/test/functional/rpc_signer.py b/test/functional/rpc_signer.py
index 715520b1..0cfc2324 100755
--- a/test/functional/rpc_signer.py
+++ b/test/functional/rpc_signer.py
@@ -37,7 +37,7 @@ class RPCSignerTest(BitcoinTestFramework):
self.skip_if_no_external_signer()
def set_mock_result(self, node, res):
- with open(os.path.join(node.cwd, "mock_result"), "w", encoding="utf8") as f:
+ with open(os.path.join(node.cwd, "mock_result"), "w") as f:
f.write(res)
def clear_mock_result(self, node):
diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py
index 9e475bbe..a12adc80 100755
--- a/test/functional/rpc_users.py
+++ b/test/functional/rpc_users.py
@@ -61,11 +61,11 @@ class HTTPBasicsTest(BitcoinTestFramework):
rpcauth3 = lines[1]
self.password = lines[3]
- with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
f.write(rpcauth + "\n")
f.write(rpcauth2 + "\n")
f.write(rpcauth3 + "\n")
- with open(self.nodes[1].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
+ with open(self.nodes[1].datadir_path / "bitcoin.conf", "a") as f:
f.write("rpcuser={}\n".format(self.rpcuser))
f.write("rpcpassword={}\n".format(self.rpcpassword))
self.restart_node(0)
diff --git a/test/functional/rpc_whitelist.py b/test/functional/rpc_whitelist.py
index b103289f..5acae0cb 100755
--- a/test/functional/rpc_whitelist.py
+++ b/test/functional/rpc_whitelist.py
@@ -61,7 +61,7 @@ class RPCWhitelistTest(BitcoinTestFramework):
]
# These commands shouldn't be allowed for any user to test failures
self.never_allowed = ["getnetworkinfo"]
- with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
f.write("\nrpcwhitelistdefault=0\n")
for user in self.users:
f.write("rpcauth=" + user[0] + ":" + user[1] + "\n")
@@ -96,7 +96,7 @@ class RPCWhitelistTest(BitcoinTestFramework):
# Replace file configurations
self.nodes[0].replace_in_config([("rpcwhitelistdefault=0", "rpcwhitelistdefault=1")])
- with open(self.nodes[0].datadir_path / "bitcoin.conf", 'a', encoding='utf8') as f:
+ with open(self.nodes[0].datadir_path / "bitcoin.conf", 'a') as f:
f.write("rpcwhitelist=__cookie__:getblockcount,getblockchaininfo,getmempoolinfo,stop\n")
self.restart_node(0)
diff --git a/test/functional/test_framework/coverage.py b/test/functional/test_framework/coverage.py
index 912a945d..29e918d4 100644
--- a/test/functional/test_framework/coverage.py
+++ b/test/functional/test_framework/coverage.py
@@ -55,7 +55,7 @@ class AuthServiceProxyWrapper():
rpc_method = self.auth_service_proxy_instance._service_name
if self.coverage_logfile:
- with open(self.coverage_logfile, 'a+', encoding='utf8') as f:
+ with open(self.coverage_logfile, 'a+') as f:
f.write("%s\n" % rpc_method)
def __truediv__(self, relative_uri):
@@ -107,7 +107,7 @@ def write_all_rpc_commands(dirname: str, node: AuthServiceProxy) -> bool:
if line and not line.startswith('='):
commands.add("%s\n" % line.split()[0])
- with open(filename, 'w', encoding='utf8') as f:
+ with open(filename, 'w') as f:
f.writelines(list(commands))
return True
diff --git a/test/functional/test_framework/crypto/ellswift.py b/test/functional/test_framework/crypto/ellswift.py
index 429b7b9f..4880ef5b 100644
--- a/test/functional/test_framework/crypto/ellswift.py
+++ b/test/functional/test_framework/crypto/ellswift.py
@@ -134,7 +134,7 @@ class TestFrameworkEllSwift(unittest.TestCase):
def test_elligator_encode_testvectors(self):
"""Implement the BIP324 test vectors for ellswift encoding (read from xswiftec_inv_test_vectors.csv)."""
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'xswiftec_inv_test_vectors.csv')
- with open(vectors_file, newline='', encoding='utf8') as csvfile:
+ with open(vectors_file, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
u = FE.from_bytes(bytes.fromhex(row['u']))
@@ -150,7 +150,7 @@ class TestFrameworkEllSwift(unittest.TestCase):
def test_elligator_decode_testvectors(self):
"""Implement the BIP324 test vectors for ellswift decoding (read from ellswift_decode_test_vectors.csv)."""
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ellswift_decode_test_vectors.csv')
- with open(vectors_file, newline='', encoding='utf8') as csvfile:
+ with open(vectors_file, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
encoding = bytes.fromhex(row['ellswift'])
diff --git a/test/functional/test_framework/key.py b/test/functional/test_framework/key.py
index 558dcbf2..6caafe8b 100644
--- a/test/functional/test_framework/key.py
+++ b/test/functional/test_framework/key.py
@@ -316,7 +316,7 @@ class TestFrameworkKey(unittest.TestCase):
"""Implement the BIP340 test vectors (read from bip340_test_vectors.csv)."""
num_tests = 0
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'bip340_test_vectors.csv')
- with open(vectors_file, newline='', encoding='utf8') as csvfile:
+ with open(vectors_file, newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader)
for row in reader:
diff --git a/test/functional/test_framework/netutil.py b/test/functional/test_framework/netutil.py
index f79a8c36..6cb34eb8 100644
--- a/test/functional/test_framework/netutil.py
+++ b/test/functional/test_framework/netutil.py
@@ -69,7 +69,7 @@ def netstat(typ='tcp'):
To get pid of all network process running on system, you must run this script
as superuser
'''
- with open('/proc/net/'+typ,'r',encoding='utf8') as f:
+ with open('/proc/net/'+typ,'r') as f:
content = f.readlines()
content.pop(0)
result = []
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 50312021..a74ab5ae 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -751,7 +751,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
self.log = logging.getLogger('TestFramework')
self.log.setLevel(logging.DEBUG)
# Create file handler to log all messages
- fh = logging.FileHandler(self.options.tmpdir + '/test_framework.log', encoding='utf-8')
+ fh = logging.FileHandler(self.options.tmpdir + '/test_framework.log')
fh.setLevel(logging.DEBUG)
# Create console handler to log messages to stderr. By default this logs only error messages, but can be configured with --loglevel.
ch = logging.StreamHandler(sys.stdout)
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 4186cec5..060a932d 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -506,13 +506,13 @@ class TestNode():
The substitutions are passed as a list of search-replace-tuples, e.g.
[("old", "new"), ("foo", "bar"), ...]
"""
- with open(self.bitcoinconf, 'r', encoding='utf8') as conf:
+ with open(self.bitcoinconf, 'r') as conf:
conf_data = conf.read()
for replacement in replacements:
assert_equal(len(replacement), 2)
old, new = replacement[0], replacement[1]
conf_data = conf_data.replace(old, new)
- with open(self.bitcoinconf, 'w', encoding='utf8') as conf:
+ with open(self.bitcoinconf, 'w') as conf:
conf.write(conf_data)
@property
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index bbad6ea7..f08b36d5 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -528,7 +528,7 @@ def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect=
else:
chain_name_conf_arg = chain
chain_name_conf_section = chain
- with open(config_path, 'w', encoding='utf8') as f:
+ with open(config_path, 'w') as f:
if chain_name_conf_arg:
f.write("{}=1\n".format(chain_name_conf_arg))
if chain_name_conf_section:
@@ -594,7 +594,7 @@ def get_temp_default_datadir(temp_dir: pathlib.Path) -> tuple[dict, pathlib.Path
def append_config(datadir, options):
- with open(os.path.join(datadir, "bitcoin.conf"), 'a', encoding='utf8') as f:
+ with open(os.path.join(datadir, "bitcoin.conf"), 'a') as f:
for option in options:
f.write(option + "\n")
@@ -603,7 +603,7 @@ def get_auth_cookie(datadir, chain):
user = None
password = None
if os.path.isfile(os.path.join(datadir, "bitcoin.conf")):
- with open(os.path.join(datadir, "bitcoin.conf"), 'r', encoding='utf8') as f:
+ with open(os.path.join(datadir, "bitcoin.conf"), 'r') as f:
for line in f:
if line.startswith("rpcuser="):
assert user is None # Ensure that there is only one rpcuser line
@@ -612,7 +612,7 @@ def get_auth_cookie(datadir, chain):
assert password is None # Ensure that there is only one rpcpassword line
password = line.split("=")[1].strip("\n")
try:
- with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f:
+ with open(os.path.join(datadir, chain, ".cookie"), 'r') as f:
userpass = f.read()
split_userpass = userpass.split(':')
user = split_userpass[0]
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 8c26ab95..d63dbade 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -428,7 +428,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, encoding="utf8"))
+ config.read_file(open(configfile))
passon_args.append("--configfile=%s" % configfile)
@@ -699,7 +699,7 @@ def print_results(test_results, max_len_name, runtime):
def write_results(test_results, filepath, total_runtime):
- with open(filepath, mode="w", encoding="utf8") as results_file:
+ with open(filepath, mode="w") as results_file:
results_writer = csv.writer(results_file)
results_writer.writerow(['test', 'status', 'duration(seconds)'])
all_passed = True
@@ -911,7 +911,7 @@ class RPCCoverage():
if not os.path.isfile(coverage_ref_filename):
raise RuntimeError("No coverage reference found")
- with open(coverage_ref_filename, 'r', encoding="utf8") as coverage_ref_file:
+ with open(coverage_ref_filename, 'r') as coverage_ref_file:
all_cmds.update([line.strip() for line in coverage_ref_file.readlines()])
for root, _, files in os.walk(self.dir):
@@ -920,7 +920,7 @@ class RPCCoverage():
coverage_filenames.add(os.path.join(root, filename))
for filename in coverage_filenames:
- with open(filename, 'r', encoding="utf8") as coverage_file:
+ with open(filename, 'r') as coverage_file:
covered_cmds.update([line.strip() for line in coverage_file.readlines()])
return all_cmds - covered_cmds
diff --git a/test/functional/tool_utils.py b/test/functional/tool_utils.py
index 6dfe27c3..525285de 100755
--- a/test/functional/tool_utils.py
+++ b/test/functional/tool_utils.py
@@ -28,7 +28,7 @@ class ToolUtils(BitcoinTestFramework):
def run_test(self):
self.testcase_dir = Path(self.config["environment"]["SRCDIR"]) / "test" / "functional" / "data" / "util"
self.bins = self.get_binaries()
- with open(self.testcase_dir / "bitcoin-util-test.json", encoding="utf8") as f:
+ with open(self.testcase_dir / "bitcoin-util-test.json") as f:
input_data = json.loads(f.read())
for i, test_obj in enumerate(input_data):
@@ -50,7 +50,7 @@ class ToolUtils(BitcoinTestFramework):
# Read the input data (if there is any)
inputData = None
if "input" in testObj:
- with open(self.testcase_dir / testObj["input"], encoding="utf8") as f:
+ with open(self.testcase_dir / testObj["input"]) as f:
inputData = f.read()
# Read the expected output data (if there is any)
@@ -60,7 +60,7 @@ class ToolUtils(BitcoinTestFramework):
if "output_cmp" in testObj:
outputFn = testObj['output_cmp']
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
- with open(self.testcase_dir / outputFn, encoding="utf8") as f:
+ with open(self.testcase_dir / outputFn) as f:
outputData = f.read()
if not outputData:
raise Exception(f"Output data missing for {outputFn}")
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index bbf84d7a..d5bc4ad6 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -83,7 +83,7 @@ class ToolWalletTest(BitcoinTestFramework):
def read_dump(self, filename):
dump = OrderedDict()
- with open(filename, "r", encoding="utf8") as f:
+ with open(filename, "r") as f:
for row in f:
row = row.strip()
key, value = row.split(',')
@@ -98,7 +98,7 @@ class ToolWalletTest(BitcoinTestFramework):
def write_dump(self, dump, filename, magic=None, skip_checksum=False):
if magic is None:
magic = "BITCOIN_CORE_WALLET_DUMP"
- with open(filename, "w", encoding="utf8") as f:
+ with open(filename, "w") as f:
row = ",".join([magic, dump[magic]]) + "\n"
f.write(row)
for k, v in dump.items():
diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py
index 6f3637a0..4d08ace4 100755
--- a/test/functional/wallet_backup.py
+++ b/test/functional/wallet_backup.py
@@ -112,7 +112,7 @@ class WalletBackupTest(BitcoinTestFramework):
def restore_invalid_wallet(self):
node = self.nodes[3]
invalid_wallet_file = self.nodes[0].datadir_path / 'invalid_wallet_file.bak'
- open(invalid_wallet_file, 'a', encoding="utf8").write('invald wallet')
+ open(invalid_wallet_file, 'a').write('invald wallet')
wallet_name = "res0"
not_created_wallet_file = node.wallets_path / wallet_name
error_message = "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(not_created_wallet_file)
diff --git a/test/functional/wallet_backwards_compatibility.py b/test/functional/wallet_backwards_compatibility.py
index 1f335398..a67b4676 100755
--- a/test/functional/wallet_backwards_compatibility.py
+++ b/test/functional/wallet_backwards_compatibility.py
@@ -100,7 +100,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
bad_deriv_wallet.dumpwallet(dump_path)
addr = None
seed = None
- with open(dump_path, encoding="utf8") as f:
+ with open(dump_path) as f:
for line in f:
if f"hdkeypath=m/0'/0'/{LAST_KEYPOOL_INDEX}'" in line:
addr = line.split(" ")[4].split("=")[1]
@@ -123,7 +123,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
os.unlink(dump_path)
bad_deriv_wallet.dumpwallet(dump_path)
bad_path_addr = None
- with open(dump_path, encoding="utf8") as f:
+ with open(dump_path) as f:
for line in f:
if f"hdkeypath={bad_deriv_path}" in line:
bad_path_addr = line.split(" ")[4].split("=")[1]
diff --git a/test/functional/wallet_encryption.py b/test/functional/wallet_encryption.py
index b54852b7..f8182e10 100755
--- a/test/functional/wallet_encryption.py
+++ b/test/functional/wallet_encryption.py
@@ -134,13 +134,13 @@ class WalletEncryptionTest(BitcoinTestFramework):
do_wallet_tool("-wallet=noprivs", f"-dumpfile={dumpfile_path}", "dump")
# Modify the dump
- with open(dumpfile_path, "r", encoding="utf-8") as f:
+ with open(dumpfile_path, "r") as f:
dump_content = f.readlines()
# Drop the checksum line
dump_content = dump_content[:-1]
# Insert a valid mkey line. This corresponds to a passphrase of "pass".
dump_content.append("046d6b657901000000,300dc926f3b3887aad3d5d5f5a0fc1b1a4a1722f9284bd5c6ff93b64a83902765953939c58fe144013c8b819f42cf698b208e9911e5f0c544fa300000000cc52050000\n")
- with open(dumpfile_path, "w", encoding="utf-8") as f:
+ with open(dumpfile_path, "w") as f:
contents = "".join(dump_content)
f.write(contents)
checksum = hash256(contents.encode())
@@ -158,7 +158,7 @@ class WalletEncryptionTest(BitcoinTestFramework):
# Make a new dump and check that there are no mkeys
dumpfile_path = self.nodes[0].datadir_path / "noprivs_enc.dump"
do_wallet_tool("-wallet=noprivs_enc", f"-dumpfile={dumpfile_path}", "dump")
- with open(dumpfile_path, "r", encoding="utf-8") as f:
+ with open(dumpfile_path, "r") as f:
# Check there's nothing with an 'mkey' prefix
assert_equal(all([not line.startswith("046d6b6579") for line in f]), True)
diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py
index 64f57cec..f15c1506 100755
--- a/test/functional/wallet_multiwallet.py
+++ b/test/functional/wallet_multiwallet.py
@@ -180,7 +180,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', encoding="utf8").close()
+ open(not_a_dir, 'a').close()
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
# if wallets/ doesn't exist, datadir should be the default wallet dir
diff --git a/test/functional/wallet_signer.py b/test/functional/wallet_signer.py
index c239bb61..52780e6f 100755
--- a/test/functional/wallet_signer.py
+++ b/test/functional/wallet_signer.py
@@ -48,7 +48,7 @@ class WalletSignerTest(BitcoinTestFramework):
self.skip_if_no_wallet()
def set_mock_result(self, node, res):
- with open(os.path.join(node.cwd, "mock_result"), "w", encoding="utf8") as f:
+ with open(os.path.join(node.cwd, "mock_result"), "w") as f:
f.write(res)
def clear_mock_result(self, node):
@@ -170,7 +170,7 @@ class WalletSignerTest(BitcoinTestFramework):
assert hww.testmempoolaccept([mock_tx])[0]["allowed"]
- with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w", encoding="utf8") as f:
+ with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w") as f:
f.write(mock_psbt_signed["psbt"])
self.log.info('Test send using hww1')
@@ -195,7 +195,7 @@ class WalletSignerTest(BitcoinTestFramework):
mock_psbt_bumped = mock_wallet.psbtbumpfee(orig_tx_id)["psbt"]
mock_psbt_bumped_signed = mock_wallet.walletprocesspsbt(psbt=mock_psbt_bumped, sign=True, sighashtype="ALL", bip32derivs=True)
- with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w", encoding="utf8") as f:
+ with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w") as f:
f.write(mock_psbt_bumped_signed["psbt"])
self.log.info('Test bumpfee using hww1')
diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py
index 5b2c847b..d31d95ed 100755
--- a/test/fuzz/test_runner.py
+++ b/test/fuzz/test_runner.py
@@ -99,7 +99,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, encoding="utf8"))
+ config.read_file(open(configfile))
if not config["components"].getboolean("ENABLE_FUZZ_BINARY"):
logging.error("Must have fuzz executable built")
diff --git a/test/lint/lint-files.py b/test/lint/lint-files.py
index c5af959e..cddaed98 100755
--- a/test/lint/lint-files.py
+++ b/test/lint/lint-files.py
@@ -185,7 +185,7 @@ def check_shebang_file_permissions(files_meta) -> int:
# *.py files which don't contain an `if __name__ == '__main__'` are not expected to be executed directly
if file_meta.extension == "py":
- with open(filename, "r", encoding="utf8") as f:
+ with open(filename, "r") as f:
file_data = f.read()
if not re.search("""if __name__ == ['"]__main__['"]:""", file_data):
continue
diff --git a/test/lint/lint-include-guards.py b/test/lint/lint-include-guards.py
index e16bb94a..e0d4eb95 100755
--- a/test/lint/lint-include-guards.py
+++ b/test/lint/lint-include-guards.py
@@ -71,7 +71,7 @@ def main():
regex_pattern = f'^#(ifndef|define|endif //) {header_id}'
- with open(header_file, 'r', encoding='utf-8') as f:
+ with open(header_file, 'r') as f:
header_file_contents = f.readlines()
count = 0
diff --git a/test/lint/lint-includes.py b/test/lint/lint-includes.py
index b0c91b90..0f108904 100755
--- a/test/lint/lint-includes.py
+++ b/test/lint/lint-includes.py
@@ -40,13 +40,13 @@ EXPECTED_BOOST_INCLUDES = [
def get_toplevel():
- return check_output(["git", "rev-parse", "--show-toplevel"], text=True, encoding="utf8").rstrip("\n")
+ return check_output(["git", "rev-parse", "--show-toplevel"], text=True).rstrip("\n")
def list_files_by_suffix(suffixes):
exclude_args = [":(exclude)" + dir for dir in EXCLUDED_DIRS]
- files_list = check_output(["git", "ls-files", "src"] + exclude_args, text=True, encoding="utf8").splitlines()
+ files_list = check_output(["git", "ls-files", "src"] + exclude_args, text=True).splitlines()
return [file for file in files_list if file.endswith(suffixes)]
@@ -68,7 +68,7 @@ def find_included_cpps():
included_cpps = list()
try:
- included_cpps = check_output(["git", "grep", "-E", r"^#include [<\"][^>\"]+\.cpp[>\"]", "--", "*.cpp", "*.h"], text=True, encoding="utf8").splitlines()
+ included_cpps = check_output(["git", "grep", "-E", r"^#include [<\"][^>\"]+\.cpp[>\"]", "--", "*.cpp", "*.h"], text=True).splitlines()
except CalledProcessError as e:
if e.returncode > 1:
raise e
@@ -82,7 +82,7 @@ def find_extra_boosts():
exclusion_set = set()
try:
- included_boosts = check_output(["git", "grep", "-E", r"^#include <boost/", "--", "*.cpp", "*.h"], text=True, encoding="utf8").splitlines()
+ included_boosts = check_output(["git", "grep", "-E", r"^#include <boost/", "--", "*.cpp", "*.h"], text=True).splitlines()
except CalledProcessError as e:
if e.returncode > 1:
raise e
@@ -105,7 +105,7 @@ def find_quote_syntax_inclusions():
quote_syntax_inclusions = list()
try:
- quote_syntax_inclusions = check_output(["git", "grep", r"^#include \"", "--", "*.cpp", "*.h"] + exclude_args, text=True, encoding="utf8").splitlines()
+ quote_syntax_inclusions = check_output(["git", "grep", r"^#include \"", "--", "*.cpp", "*.h"] + exclude_args, text=True).splitlines()
except CalledProcessError as e:
if e.returncode > 1:
raise e
@@ -120,7 +120,7 @@ def main():
# Check for duplicate includes
for filename in list_files_by_suffix((".cpp", ".h")):
- with open(filename, "r", encoding="utf8") as file:
+ with open(filename, "r") as file:
include_list = [line.rstrip("\n") for line in file if re.match(r"^#include", line)]
duplicates = find_duplicate_includes(include_list)
@@ -148,13 +148,13 @@ def main():
if extra_boosts:
for boost in extra_boosts:
print(f"A new Boost dependency in the form of \"{boost}\" appears to have been introduced:")
- print(check_output(["git", "grep", boost, "--", "*.cpp", "*.h"], text=True, encoding="utf8"))
+ print(check_output(["git", "grep", boost, "--", "*.cpp", "*.h"], text=True))
exit_code = 1
# Check if Boost dependencies are no longer used
for expected_boost in EXPECTED_BOOST_INCLUDES:
try:
- check_output(["git", "grep", "-q", r"^#include <%s>" % expected_boost, "--", "*.cpp", "*.h"], text=True, encoding="utf8")
+ check_output(["git", "grep", "-q", r"^#include <%s>" % expected_boost, "--", "*.cpp", "*.h"], text=True)
except CalledProcessError as e:
if e.returncode > 1:
raise e
diff --git a/test/lint/lint-locale-dependence.py b/test/lint/lint-locale-dependence.py
index e728123e..c6a64587 100755
--- a/test/lint/lint-locale-dependence.py
+++ b/test/lint/lint-locale-dependence.py
@@ -219,7 +219,7 @@ def find_locale_dependent_function_uses():
git_grep_output = list()
try:
- git_grep_output = check_output(git_grep_command, text=True, encoding="utf8").splitlines()
+ git_grep_output = check_output(git_grep_command, text=True).splitlines()
except CalledProcessError as e:
if e.returncode > 1:
raise e
diff --git a/test/lint/lint-shell-locale.py b/test/lint/lint-shell-locale.py
index 59515e78..3602289d 100755
--- a/test/lint/lint-shell-locale.py
+++ b/test/lint/lint-shell-locale.py
@@ -41,7 +41,7 @@ def main():
if re.search('src/(secp256k1|minisketch)/', file_path):
continue
- with open(file_path, 'r', encoding='utf-8') as file_obj:
+ with open(file_path, 'r') as file_obj:
contents = file_obj.read()
non_comment_pattern = re.compile(r'^\s*((?!#).+)$', re.MULTILINE)
diff --git a/test/lint/lint-tests.py b/test/lint/lint-tests.py
index 100339d2..f4072d69 100755
--- a/test/lint/lint-tests.py
+++ b/test/lint/lint-tests.py
@@ -23,7 +23,7 @@ def grep_boost_fixture_test_suite():
"src/test/**.cpp",
"src/wallet/test/**.cpp",
]
- return subprocess.check_output(command, text=True, encoding="utf8")
+ return subprocess.check_output(command, text=True)
def check_matching_test_names(test_suite_list):
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.