contrib: Remove confusing and redundant encoding from IO
The encoding arg is confusing, because it is not applied consistently for all IO. Also, it is useless, as the majority of files are ASCII encoded, which are fine to encode and decode with any mode. Moreover, UTF-8 is already required for most scripts to work properly, so setting the encoding twice is redundant. So remove the encoding from most IO. It would be fine to remove from all IO, however I kept it for two files: * contrib/asmap/asmap-tool.py: This specifically looks for utf-8 encoding errors, so it makes sense to sepecify the utf-8 encoding explicitly. * test/functional/test_framework/test_node.py: Reading the debug log in text mode specifically counts the utf-8 characters (not bytes), so it makes sense to specify the utf-8 encoding explicitly.
This commit is contained in:
54 files changed
+127
-128
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user