mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 10:42:13 +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:
@@ -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:
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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))
|
||||
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user