]> arthur.barton.de Git - bup.git/commitdiff
main: switch print_clean_line to bytes
authorRob Browning <rlb@defaultvalue.org>
Tue, 10 Sep 2019 06:24:27 +0000 (01:24 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 29 Sep 2019 20:25:18 +0000 (15:25 -0500)
This function filters arbitrary content, and only needs to assume that
it's ASCII-compatible (i.e. it only cares about \n and \r).
Explicitly use bytes to accommodate Python 3.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
main.py

diff --git a/main.py b/main.py
index 7f632beaa997f0a7dd6bbff8066f32f4b80dff96..f955321d97afd80845d05be5d9d73c0c1caff023 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -154,7 +154,7 @@ def force_tty():
         os.environ['BUP_FORCE_TTY'] = str(amt)
 
 
-sep_rx = re.compile(r'([\r\n])')
+sep_rx = re.compile(br'([\r\n])')
 
 def print_clean_line(dest, content, width, sep=None):
     """Write some or all of content, followed by sep, to the dest fd after
@@ -162,19 +162,19 @@ def print_clean_line(dest, content, width, sep=None):
     terminal width or truncating it to the terminal width if sep is a
     carriage return."""
     global sep_rx
-    assert sep in ('\r', '\n', None)
+    assert sep in (b'\r', b'\n', None)
     if not content:
         if sep:
             os.write(dest, sep)
         return
     for x in content:
         assert not sep_rx.match(x)
-    content = ''.join(content)
-    if sep == '\r' and len(content) > width:
+    content = b''.join(content)
+    if sep == b'\r' and len(content) > width:
         content = content[width:]
     os.write(dest, content)
     if len(content) < width:
-        os.write(dest, ' ' * (width - len(content)))
+        os.write(dest, b' ' * (width - len(content)))
     if sep:
         os.write(dest, sep)