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

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


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1470420039 14400
#      Fri Aug 05 14:00:39 2016 -0400
# Node ID cfdfe5d1d84a5cbcd59575f0344fbc52863bf801
# Parent  07c773056e724ba6e1e753635909e968026cffb3
url: use `iter(callable, sentinel)` instead of while True

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

diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -208,18 +208,14 @@ def _generic_proxytunnel(self):
         version, status, reason = res._read_status()
         if status != httplib.CONTINUE:
             break
-        while True:
-            skip = res.fp.readline().strip()
-            if not skip:
-                break
+        # skip lines that are all whitespace
+        list(iter(lambda: res.fp.readline().strip(), ''))
     res.status = status
     res.reason = reason.strip()
 
     if res.status == 200:
-        while True:
-            line = res.fp.readline()
-            if line == '\r\n':
-                break
+        # skip lines until we find a blank line
+        list(iter(res.fp.readline, '\r\n'))
         return True
 
     if version == 'HTTP/1.0':


More information about the Mercurial-devel mailing list