[PATCH 4 of 9] sshpeer: use `iter(callable, sentinel)` instead of while True

Augie Fackler raf at durin42.com
Sat Aug 6 11:02:34 EDT 2016


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1470420022 14400
#      Fri Aug 05 14:00:22 2016 -0400
# Node ID 5fbdb186660f4c93905498e4a1a5f71d7a0cd7ec
# Parent  c2fd50f63ebfefc68335cf8b5eed78c58cb15ee2
sshpeer: use `iter(callable, sentinel)` instead of while True

This is functionally equivalent, but is a little more concise.

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -292,10 +292,7 @@ class sshpeer(wireproto.wirepeer):
         r = self._call(cmd, **args)
         if r:
             return '', r
-        while True:
-            d = fp.read(4096)
-            if not d:
-                break
+        for d in iter(lambda: fp.read(4096), ''):
             self._send(d)
         self._send("", flush=True)
         r = self._recv()
@@ -308,10 +305,7 @@ class sshpeer(wireproto.wirepeer):
         if r:
             # XXX needs to be made better
             raise error.Abort(_('unexpected remote reply: %s') % r)
-        while True:
-            d = fp.read(4096)
-            if not d:
-                break
+        for d in iter(lambda: fp.read(4096), ''):
             self._send(d)
         self._send("", flush=True)
         return self.pipei
@@ -353,10 +347,7 @@ class sshpeer(wireproto.wirepeer):
         d = self._call("addchangegroup")
         if d:
             self._abort(error.RepoError(_("push refused: %s") % d))
-        while True:
-            d = cg.read(4096)
-            if not d:
-                break
+        for d in iter(lambda: cg.read(4096), ''):
             self.pipeo.write(d)
             self.readerr()
 


More information about the Mercurial-devel mailing list