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.
This commit is contained in:
Moritz Lell 2019-10-30 19:21:23 +01:00
commit e239820afd
4 changed files with 7 additions and 7 deletions

View file

@ -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):

View file

@ -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

View file

@ -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: