summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-12-19 09:44:13 -0500
committerKevin O'Connor <kevin@koconnor.net>2021-12-19 09:44:30 -0500
commit9ad4399b0e13c84cd6680a8ea6896d7133519995 (patch)
treee162ae50d3f1a4ae496d3d17cf713853fd2d619c /scripts
parent98dd53b99442ae15d78125b4453b1adc926e9ff3 (diff)
downloadqemu-seabios-9ad4399b0e13c84cd6680a8ea6896d7133519995.tar.gz
readserial: Improve Python3 compatibility
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/readserial.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/scripts/readserial.py b/scripts/readserial.py
index a7383e8..e3f56e5 100755
--- a/scripts/readserial.py
+++ b/scripts/readserial.py
@@ -10,8 +10,6 @@
import sys, os, time, select, 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
@@ -20,11 +18,11 @@ BITSPERBYTE = 10
def calibrateserialwrite(outfile, byteadjust):
# Build 4000 bytes of dummy data.
- data = "0123456789" * 4 + "012345678" + "\n"
+ data = b"0123456789" * 4 + b"012345678" + b"\n"
data = data * 80
while 1:
st = time.time()
- outfile.write(as_bytes(data))
+ outfile.write(data)
outfile.flush()
et = time.time()
sys.stdout.write(
@@ -84,38 +82,34 @@ 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(as_bytes(msg))
+ logfile.write(msg.encode())
lasttime = datatime
# Translate unprintable chars; add timestamps
- out = as_bytes("")
- for c in d:
+ out = bytearray()
+ for oc in bytearray(d):
if isnewline:
delta = datatime - starttime - (charcount * byteadjust)
- out += "%06.3f: " % delta
+ out += b"%06.3f: " % delta
isnewline = 0
- oc = ord(c)
charcount += 1
datatime += byteadjust
if oc == 0x0d:
continue
if oc == 0x00:
- out += "<00>\n"
+ out += b"<00>\n"
isnewline = 1
continue
if oc == 0x0a:
- out += "\n"
+ out += b"\n"
isnewline = 1
continue
if oc < 0x20 or oc >= 0x7f and oc != 0x09:
- out += "<%02x>" % oc
+ out += b"<%02x>" % oc
continue
- out += c
+ out.append(oc)
- if (sys.version_info > (3, 0)):
- sys.stdout.buffer.write(out)
- else:
- sys.stdout.write(out)
+ sys.stdout.write(out.decode())
sys.stdout.flush()
logfile.write(out)
logfile.flush()