From e239820afd1959f8c0d01ee9dac5f59bd18d0fd2 Mon Sep 17 00:00:00 2001 From: Moritz Lell Date: Wed, 30 Oct 2019 19:21:23 +0100 Subject: [PATCH] Distinguish byte (python2 str type) and unicode strings (python 3 str type) Python 3 strings are python 2 unicode strings. Therefore consistently mark strings that are sent via pipes or written/read to file as byte strings. --- docs/md2man.py | 2 +- redo/builder.py | 6 +++--- redo/cmd_log.py | 2 +- redo/jobserver.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/md2man.py b/docs/md2man.py index e7f1526..f89a459 100644 --- a/docs/md2man.py +++ b/docs/md2man.py @@ -246,7 +246,7 @@ if len(sys.argv) != 3: infile = sys.argv[1] htmlfile = sys.argv[2] -lines += open(infile).read().decode('utf8').split('\n') +lines += open(infile, 'rb').read().decode('utf8').split('\n') # parse pandoc-style document headers (not part of markdown) g = re.match(r'^%\s+(.*?)\((.*?)\)\s+(.*)$', lines[0]) diff --git a/redo/builder.py b/redo/builder.py index c6504fe..1ae4a44 100644 --- a/redo/builder.py +++ b/redo/builder.py @@ -62,7 +62,7 @@ def start_stdin_log_reader(status, details, pretty, color, # subprocess died without sending us anything: that's bad. err('failed to start redo-log subprocess; cannot continue.\n') os._exit(99) - assert b == 'REDO-OK\n' + assert b == b'REDO-OK\n' # now we know the subproc is running and will report our errors # to stderr, so it's okay to lose our own stderr. os.close(ar) @@ -218,7 +218,7 @@ class _BuildJob(object): ffd, fname = tempfile.mkstemp(prefix='redo.', suffix='.tmp') helpers.close_on_exec(ffd, True) os.unlink(fname) - self.outfile = os.fdopen(ffd, 'w+') + self.outfile = os.fdopen(ffd, 'w+b') # this will run in the dofile's directory, so use only basenames here arg1 = basename + ext # target name (including extension) arg2 = basename # target name (without extension) @@ -404,7 +404,7 @@ class _BuildJob(object): # script wrote to stdout. Copy its contents to the tmpfile. helpers.unlink(self.tmpname) try: - newf = open(self.tmpname, 'w') + newf = open(self.tmpname, 'wb') except IOError as e: dnt = os.path.dirname(os.path.abspath(t)) if not os.path.exists(dnt): diff --git a/redo/cmd_log.py b/redo/cmd_log.py index 466efd3..fdcc7b8 100644 --- a/redo/cmd_log.py +++ b/redo/cmd_log.py @@ -264,7 +264,7 @@ def main(): # their old stderr. ack_fd = int(opt.ack_fd) assert ack_fd > 2 - if os.write(ack_fd, 'REDO-OK\n') != 8: + if os.write(ack_fd, b'REDO-OK\n') != 8: raise Exception('write to ack_fd returned wrong length') os.close(ack_fd) queue += targets diff --git a/redo/jobserver.py b/redo/jobserver.py index acd3f4f..9102345 100644 --- a/redo/jobserver.py +++ b/redo/jobserver.py @@ -128,7 +128,7 @@ def _release(n): assert _cheats >= 0 if n_to_share: _debug('PUT tokenfds %d\n' % n_to_share) - os.write(_tokenfds[1], 't' * n_to_share) + os.write(_tokenfds[1], b't' * n_to_share) def _release_except_mine(): @@ -189,7 +189,7 @@ def _try_read(fd, n): def _try_read_all(fd, n): - bb = '' + bb = b'' while 1: b = _try_read(fd, n) if not b: