mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-10 06:39:15 +02:00
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:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user