Patchwork [2,of,6] procutil: define LineBufferedWrapper on all Python versions

login
register
mail settings
Submitter Manuel Jacob
Date July 5, 2020, 2:51 a.m.
Message ID <527b213d2d2416ce86bc.1593917498@tmp.fritz.box>
Download mbox | patch
Permalink /patch/46619/
State Accepted
Headers show

Comments

Manuel Jacob - July 5, 2020, 2:51 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1593657438 -7200
#      Thu Jul 02 04:37:18 2020 +0200
# Node ID 527b213d2d2416ce86bc17aac34851142dc37f77
# Parent  cbec874a8b0f9441469cbd5e79db6dcd83b4c4d4
# EXP-Topic stdio
procutil: define LineBufferedWrapper on all Python versions

There’s nothing Python 3-only about LineBufferedWrapper. In the future, we may
want to use it on Windows, to work around missing line-buffering support.
Yuya Nishihara - July 6, 2020, 11:19 a.m.
On Sun, 05 Jul 2020 04:51:38 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1593657438 -7200
> #      Thu Jul 02 04:37:18 2020 +0200
> # Node ID 527b213d2d2416ce86bc17aac34851142dc37f77
> # Parent  cbec874a8b0f9441469cbd5e79db6dcd83b4c4d4
> # EXP-Topic stdio
> procutil: define LineBufferedWrapper on all Python versions

Queued the first two, thanks.

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -49,23 +49,22 @@ 
         return False
 
 
-if pycompat.ispy3:
+class LineBufferedWrapper(object):
+    def __init__(self, orig):
+        self.orig = orig
 
-    class LineBufferedWrapper(object):
-        def __init__(self, orig):
-            self.orig = orig
-
-        def __getattr__(self, attr):
-            return getattr(self.orig, attr)
+    def __getattr__(self, attr):
+        return getattr(self.orig, attr)
 
-        def write(self, s):
-            orig = self.orig
-            res = orig.write(s)
-            if s.endswith(b'\n'):
-                orig.flush()
-            return res
+    def write(self, s):
+        orig = self.orig
+        res = orig.write(s)
+        if s.endswith(b'\n'):
+            orig.flush()
+        return res
 
-    io.BufferedIOBase.register(LineBufferedWrapper)
+
+io.BufferedIOBase.register(LineBufferedWrapper)
 
 
 # glibc determines buffering on first write to stdout - if we replace a TTY