summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2022-11-26 22:33:25 (GMT)
committerGitHub <noreply@github.com>2022-11-26 22:33:25 (GMT)
commit024ac542d738f56b36bdeb3517a10e93da5acab9 (patch)
tree7e54e0fcc68871e059ccff2adaf39b8a1808dcad /Lib/http
parent25bc115df9d0e82309852609a83b5ab7f804cdc1 (diff)
downloadcpython-024ac542d738f56b36bdeb3517a10e93da5acab9.zip
cpython-024ac542d738f56b36bdeb3517a10e93da5acab9.tar.gz
cpython-024ac542d738f56b36bdeb3517a10e93da5acab9.tar.bz2
bpo-45975: Simplify some while-loops with walrus operator (GH-29347)
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py16
-rw-r--r--Lib/http/cookiejar.py9
2 files changed, 5 insertions, 20 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 0a3e950..15c5cf6 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -578,11 +578,7 @@ class HTTPResponse(io.BufferedIOBase):
assert self.chunked != _UNKNOWN
value = []
try:
- while True:
- chunk_left = self._get_chunk_left()
- if chunk_left is None:
- break
-
+ while (chunk_left := self._get_chunk_left()) is not None:
if amt is not None and amt <= chunk_left:
value.append(self._safe_read(amt))
self.chunk_left = chunk_left - amt
@@ -998,10 +994,7 @@ class HTTPConnection:
encode = self._is_textIO(data)
if encode and self.debuglevel > 0:
print("encoding file using iso-8859-1")
- while 1:
- datablock = data.read(self.blocksize)
- if not datablock:
- break
+ while datablock := data.read(self.blocksize):
if encode:
datablock = datablock.encode("iso-8859-1")
sys.audit("http.client.send", self, datablock)
@@ -1031,10 +1024,7 @@ class HTTPConnection:
encode = self._is_textIO(readable)
if encode and self.debuglevel > 0:
print("encoding file using iso-8859-1")
- while True:
- datablock = readable.read(self.blocksize)
- if not datablock:
- break
+ while datablock := readable.read(self.blocksize):
if encode:
datablock = datablock.encode("iso-8859-1")
yield datablock
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index 65c45e2..b0161a8 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -1915,9 +1915,7 @@ class LWPCookieJar(FileCookieJar):
"comment", "commenturl")
try:
- while 1:
- line = f.readline()
- if line == "": break
+ while (line := f.readline()) != "":
if not line.startswith(header):
continue
line = line[len(header):].strip()
@@ -2017,12 +2015,9 @@ class MozillaCookieJar(FileCookieJar):
filename)
try:
- while 1:
- line = f.readline()
+ while (line := f.readline()) != "":
rest = {}
- if line == "": break
-
# httponly is a cookie flag as defined in rfc6265
# when encoded in a netscape cookie file,
# the line is prepended with "#HttpOnly_"