python: Explicitly set encoding to utf8 when opening text files
This commit is contained in:
parent
1944eb1c86
commit
337e528d33
|
@ -17,7 +17,7 @@ class HardForkDetectionTest(BitcoinTestFramework):
|
||||||
def setup_network(self):
|
def setup_network(self):
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
|
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
|
||||||
with open(self.alert_filename, 'w'):
|
with open(self.alert_filename, 'w', encoding='utf8'):
|
||||||
pass # Just open then close to create zero-length file
|
pass # Just open then close to create zero-length file
|
||||||
self.nodes.append(start_node(0, self.options.tmpdir,
|
self.nodes.append(start_node(0, self.options.tmpdir,
|
||||||
["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]))
|
["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]))
|
||||||
|
@ -48,7 +48,7 @@ class HardForkDetectionTest(BitcoinTestFramework):
|
||||||
self.assert_safemode_on("We do not appear to fully agree with our peers!")
|
self.assert_safemode_on("We do not appear to fully agree with our peers!")
|
||||||
|
|
||||||
# Check that an -alertnotify was triggered.
|
# Check that an -alertnotify was triggered.
|
||||||
with open(self.alert_filename, 'r') as f:
|
with open(self.alert_filename, 'r', encoding='utf8') as f:
|
||||||
alert_text = f.read()
|
alert_text = f.read()
|
||||||
|
|
||||||
if len(alert_text) == 0:
|
if len(alert_text) == 0:
|
||||||
|
|
|
@ -98,7 +98,7 @@ class SaplingRewindTest(BitcoinTestFramework):
|
||||||
except:
|
except:
|
||||||
logpath = self.options.tmpdir + "/node2/regtest/debug.log"
|
logpath = self.options.tmpdir + "/node2/regtest/debug.log"
|
||||||
found = False
|
found = False
|
||||||
with open(logpath, 'r') as f:
|
with open(logpath, 'r', encoding='utf8') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
# Search for the rollback message in the debug log, and ensure that it has the
|
# Search for the rollback message in the debug log, and ensure that it has the
|
||||||
# correct expected rollback length.
|
# correct expected rollback length.
|
||||||
|
|
|
@ -600,7 +600,7 @@ def check_node_log(self, node_number, line_to_check, stop_node = True):
|
||||||
self.nodes[node_number].stop()
|
self.nodes[node_number].stop()
|
||||||
bitcoind_processes[node_number].wait()
|
bitcoind_processes[node_number].wait()
|
||||||
logpath = self.options.tmpdir + "/node" + str(node_number) + "/regtest/debug.log"
|
logpath = self.options.tmpdir + "/node" + str(node_number) + "/regtest/debug.log"
|
||||||
with open(logpath, "r") as myfile:
|
with open(logpath, "r", encoding="utf8") as myfile:
|
||||||
logdata = myfile.readlines()
|
logdata = myfile.readlines()
|
||||||
for (n, logline) in enumerate(logdata):
|
for (n, logline) in enumerate(logdata):
|
||||||
if line_to_check in logline:
|
if line_to_check in logline:
|
||||||
|
|
|
@ -57,7 +57,7 @@ class WalletImportExportTest (BitcoinTestFramework):
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
def parse_wallet_file(dump_path):
|
def parse_wallet_file(dump_path):
|
||||||
file_lines = open(dump_path, "r").readlines()
|
file_lines = open(dump_path, "r", encoding="utf8").readlines()
|
||||||
# We expect information about the HDSeed and fingerpring in the header
|
# We expect information about the HDSeed and fingerpring in the header
|
||||||
assert_true("HDSeed" in file_lines[4], "Expected HDSeed")
|
assert_true("HDSeed" in file_lines[4], "Expected HDSeed")
|
||||||
assert_true("fingerprint" in file_lines[4], "Expected fingerprint")
|
assert_true("fingerprint" in file_lines[4], "Expected fingerprint")
|
||||||
|
|
|
@ -747,7 +747,7 @@ class ZcashNode(object):
|
||||||
cli_args.append('-testnet=1')
|
cli_args.append('-testnet=1')
|
||||||
cli_args.append('getblockcount')
|
cli_args.append('getblockcount')
|
||||||
|
|
||||||
devnull = open('/dev/null', 'w+')
|
devnull = open('/dev/null', 'w+', encoding='utf8')
|
||||||
if os.getenv('PYTHON_DEBUG', ''):
|
if os.getenv('PYTHON_DEBUG', ''):
|
||||||
print('start_node: zcashd started, calling zcash-cli -rpcwait getblockcount')
|
print('start_node: zcashd started, calling zcash-cli -rpcwait getblockcount')
|
||||||
subprocess.check_call(cli_args, stdout=devnull)
|
subprocess.check_call(cli_args, stdout=devnull)
|
||||||
|
|
|
@ -303,7 +303,7 @@ class DependsVersionGetter:
|
||||||
|
|
||||||
def current_version(self):
|
def current_version(self):
|
||||||
mk_file_path = os.path.join(SOURCE_ROOT, "depends", "packages", safe_depends(self.name) + ".mk")
|
mk_file_path = os.path.join(SOURCE_ROOT, "depends", "packages", safe_depends(self.name) + ".mk")
|
||||||
mk_file = open(mk_file_path, 'r').read()
|
mk_file = open(mk_file_path, 'r', encoding='utf8').read()
|
||||||
|
|
||||||
regexp_whitelist = [
|
regexp_whitelist = [
|
||||||
"package\)_version=(\d+)\.(\d+)\.(\d+)$",
|
"package\)_version=(\d+)\.(\d+)\.(\d+)$",
|
||||||
|
@ -329,7 +329,7 @@ class DependsVersionGetter:
|
||||||
class LevelDbVersionGetter:
|
class LevelDbVersionGetter:
|
||||||
def current_version(self):
|
def current_version(self):
|
||||||
header_path = os.path.join(SOURCE_ROOT, "src", "leveldb", "include", "leveldb", "db.h")
|
header_path = os.path.join(SOURCE_ROOT, "src", "leveldb", "include", "leveldb", "db.h")
|
||||||
header_contents = open(header_path, 'r').read()
|
header_contents = open(header_path, 'r', encoding='utf8').read()
|
||||||
|
|
||||||
match = re.search("kMajorVersion\s*=\s*(\d+);\s*.*kMinorVersion\s*=\s*(\d+);\s*$", header_contents, re.MULTILINE)
|
match = re.search("kMajorVersion\s*=\s*(\d+);\s*.*kMinorVersion\s*=\s*(\d+);\s*$", header_contents, re.MULTILINE)
|
||||||
if match:
|
if match:
|
||||||
|
@ -340,7 +340,7 @@ class LevelDbVersionGetter:
|
||||||
class UnivalueVersionGetter:
|
class UnivalueVersionGetter:
|
||||||
def current_version(self):
|
def current_version(self):
|
||||||
configure_path = os.path.join(SOURCE_ROOT, "src", "univalue", "configure.ac")
|
configure_path = os.path.join(SOURCE_ROOT, "src", "univalue", "configure.ac")
|
||||||
configure_contents = open(configure_path, 'r').read()
|
configure_contents = open(configure_path, 'r', encoding='utf8').read()
|
||||||
|
|
||||||
match = re.search("AC_INIT.*univalue.*\[(\d+)\.(\d+)\.(\d+)\]", configure_contents)
|
match = re.search("AC_INIT.*univalue.*\[(\d+)\.(\d+)\.(\d+)\]", configure_contents)
|
||||||
if match:
|
if match:
|
||||||
|
@ -357,7 +357,7 @@ class PostponedUpdates():
|
||||||
"postponed-updates.txt"
|
"postponed-updates.txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
file = open(postponedlist_path, 'r')
|
file = open(postponedlist_path, 'r', encoding='utf8')
|
||||||
for line in file.readlines():
|
for line in file.readlines():
|
||||||
stripped = re.sub('#.*$', '', line).strip()
|
stripped = re.sub('#.*$', '', line).strip()
|
||||||
if stripped != "":
|
if stripped != "":
|
||||||
|
|
|
@ -595,14 +595,14 @@ class PathPatcher (object):
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
logging.debug('Patching %r', self._path)
|
logging.debug('Patching %r', self._path)
|
||||||
self._inf = open(self._path, 'r')
|
self._inf = open(self._path, 'r', encoding='utf8')
|
||||||
self._outf = StringIO()
|
self._outf = StringIO()
|
||||||
return (self._inf, self._outf)
|
return (self._inf, self._outf)
|
||||||
|
|
||||||
def __exit__(self, et, ev, tb):
|
def __exit__(self, et, ev, tb):
|
||||||
if (et, ev, tb) == (None, None, None):
|
if (et, ev, tb) == (None, None, None):
|
||||||
self._inf.close()
|
self._inf.close()
|
||||||
with open(self._path, 'w') as f:
|
with open(self._path, 'w', encoding='utf8') as f:
|
||||||
f.write(self._outf.getvalue())
|
f.write(self._outf.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue