Signed-off-by: Kevin O'Connor kevin@koconnor.net --- scripts/readserial.py | 28 +++++++++++----------------- 1 file 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()
It's simpler to use b"" designations around binary strings than to use the as_bytes() function.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- scripts/buildrom.py | 6 ++---- scripts/checkrom.py | 4 +--- scripts/python23compat.py | 14 -------------- 3 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 scripts/python23compat.py
diff --git a/scripts/buildrom.py b/scripts/buildrom.py index 0499049..48bfc17 100755 --- a/scripts/buildrom.py +++ b/scripts/buildrom.py @@ -7,8 +7,6 @@
import sys, struct
-from python23compat import as_bytes - def alignpos(pos, alignbytes): mask = alignbytes - 1 return (pos + mask) & ~mask @@ -31,7 +29,7 @@ def main(): count = len(data)
# Pad to a 512 byte boundary - data += as_bytes("\0") * (alignpos(count, 512) - count) + data += b"\0" * (alignpos(count, 512) - count) count = len(data)
# Check if a pci header is present @@ -42,7 +40,7 @@ def main():
# Fill in size field; clear checksum field blocks = struct.pack('<B', int(count/512)) - data = data[:2] + blocks + data[3:6] + as_bytes("\0") + data[7:] + data = data[:2] + blocks + data[3:6] + b"\0" + data[7:]
# Checksum rom data = data[:6] + checksum(data) + data[7:] diff --git a/scripts/checkrom.py b/scripts/checkrom.py index aced5e2..a5b15a4 100755 --- a/scripts/checkrom.py +++ b/scripts/checkrom.py @@ -8,8 +8,6 @@ import sys, struct import layoutrom, buildrom
-from python23compat import as_bytes - def subst(data, offset, new): return data[:offset] + new + data[offset + len(new):]
@@ -88,7 +86,7 @@ def main():
# Write final file f = open(outfile, 'wb') - f.write((as_bytes("\0") * (finalsize - datasize)) + rawdata) + f.write((b"\0" * (finalsize - datasize)) + rawdata) f.close()
if __name__ == '__main__': diff --git a/scripts/python23compat.py b/scripts/python23compat.py deleted file mode 100644 index 572b7f1..0000000 --- a/scripts/python23compat.py +++ /dev/null @@ -1,14 +0,0 @@ -# Helper code for compatibility of the code with both Python 2 and Python 3 -# -# Copyright (C) 2014 Johannes Krampf johannes.krampf@googlemail.com -# -# This file may be distributed under the terms of the GNU GPLv3 license. - -import sys - -if (sys.version_info > (3, 0)): - def as_bytes(str): - return bytes(str, "ASCII") -else: - def as_bytes(str): - return str
On Sun, Dec 19, 2021 at 09:45:59AM -0500, Kevin O'Connor wrote:
Signed-off-by: Kevin O'Connor kevin@koconnor.net
scripts/readserial.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
FYI, I committed this series (along with the two gcc warning patches sent separately).
-Kevin