pyln: Decode process output once before storing it

This commit is contained in:
Christian Decker 2020-10-06 11:57:51 +02:00 committed by Rusty Russell
parent 81569de709
commit 9021bb26d1
3 changed files with 14 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import sqlite3
import string
import struct
import subprocess
import sys
import threading
import time
import warnings
@ -202,15 +203,22 @@ class TailableProc(object):
for line in iter(self.proc.stdout.readline, ''):
if len(line) == 0:
break
if self.log_filter(line.decode('ASCII')):
line = line.decode('ASCII').rstrip()
if self.log_filter(line):
continue
if self.verbose:
logging.debug("%s: %s", self.prefix, line.decode().rstrip())
sys.stdout.write("{}: {}\n".format(self.prefix, line))
with self.logs_cond:
self.logs.append(str(line.rstrip()))
self.logs.append(line)
self.logs_cond.notifyAll()
self.running = False
self.proc.stdout.close()
if self.proc.stderr:
for line in iter(self.proc.stderr.readline, ''):
if len(line) == 0:

View File

@ -2125,7 +2125,7 @@ def test_dataloss_protection(node_factory, bitcoind):
# be zero)
"[0-9a-f]{64}"
# my_current_per_commitment_point
"0[23][0-9a-f]{64}'$")
"0[23][0-9a-f]{64}")
# After an htlc, we should get different results (two more commits)
l1.pay(l2, 200000000)
@ -2148,7 +2148,7 @@ def test_dataloss_protection(node_factory, bitcoind):
# your_last_per_commitment_secret
"[0-9a-f]{64}"
# my_current_per_commitment_point
"0[23][0-9a-f]{64}'$")
"0[23][0-9a-f]{64}")
# Now, move l2 back in time.
l2.stop()

View File

@ -354,7 +354,7 @@ def test_gossip_weirdalias(node_factory, bitcoind):
{'alias': normal_name}
]
l1, l2 = node_factory.get_nodes(2, opts=opts)
weird_name_json = json.encoder.JSONEncoder().encode(weird_name)[1:-1].replace('\\', '\\\\')
weird_name_json = json.encoder.JSONEncoder().encode(weird_name)[1:-1]
aliasline = l1.daemon.is_in_log('Server started with public key .* alias')
assert weird_name_json in str(aliasline)
assert l2.daemon.is_in_log('Server started with public key .* alias {}'