diff options
author | Johannes Krampf <johannes.krampf@googlemail.com> | 2014-01-19 16:03:49 +0100 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2014-01-20 12:42:44 -0500 |
commit | 19f789bdfd58eba2ed8fe604bbabf8df0fcc0771 (patch) | |
tree | 51c49104aec5b420382f82f71e3b4a8edf0be8f1 /scripts/readserial.py | |
parent | 0a82fc743c5ec1553f745bec6fc8bc8780088fd8 (diff) | |
download | seabios-19f789bdfd58eba2ed8fe604bbabf8df0fcc0771.tar.gz |
build: Be careful with unicode and byte strings for python3 compatibility.
Signed-off-by: Johannes Krampf <johannes.krampf@googlemail.com>
Diffstat (limited to 'scripts/readserial.py')
-rwxr-xr-x | scripts/readserial.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/scripts/readserial.py b/scripts/readserial.py index 5b40fdc0..4f29648d 100755 --- a/scripts/readserial.py +++ b/scripts/readserial.py @@ -13,6 +13,8 @@ import time import select import optparse +from python23compat import as_bytes + # Reset time counter after this much idle time. RESTARTINTERVAL = 60 # Number of bits in a transmitted byte - 8N1 is 1 start bit + 8 data @@ -25,7 +27,7 @@ def calibrateserialwrite(outfile, byteadjust): data = data * 80 while 1: st = time.time() - outfile.write(data) + outfile.write(as_bytes(data)) outfile.flush() et = time.time() sys.stdout.write( @@ -85,11 +87,11 @@ def readserial(infile, logfile, byteadjust): msg = "\n\n======= %s (adjust=%.1fus)\n" % ( time.asctime(time.localtime(datatime)), byteadjust * 1000000) sys.stdout.write(msg) - logfile.write(msg) + logfile.write(as_bytes(msg)) lasttime = datatime # Translate unprintable chars; add timestamps - out = "" + out = as_bytes("") for c in d: if isnewline: delta = datatime - starttime - (charcount * byteadjust) @@ -113,7 +115,10 @@ def readserial(infile, logfile, byteadjust): continue out += c - sys.stdout.write(out) + if (sys.version_info > (3, 0)): + sys.stdout.buffer.write(out) + else: + sys.stdout.write(out) sys.stdout.flush() logfile.write(out) logfile.flush() |