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

login
register
mail settings
Submitter Augie Fackler
Date Aug. 6, 2016, 3:02 p.m.
Message ID <5fbdb186660f4c939054.1470495754@imladris.local>
Download mbox | patch
Permalink /patch/16158/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 6, 2016, 3:02 p.m.
# HG changeset patch
# User Augie Fackler <augie@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.

Patch

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()