summaryrefslogtreecommitdiffstats
path: root/Lib/xml
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/xml
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/xml')
-rw-r--r--Lib/xml/dom/expatbuilder.py5
-rw-r--r--Lib/xml/etree/ElementTree.py5
-rw-r--r--Lib/xml/sax/xmlreader.py4
3 files changed, 3 insertions, 11 deletions
diff --git a/Lib/xml/dom/expatbuilder.py b/Lib/xml/dom/expatbuilder.py
index 199c22d..7dd667b 100644
--- a/Lib/xml/dom/expatbuilder.py
+++ b/Lib/xml/dom/expatbuilder.py
@@ -200,10 +200,7 @@ class ExpatBuilder:
parser = self.getParser()
first_buffer = True
try:
- while 1:
- buffer = file.read(16*1024)
- if not buffer:
- break
+ while buffer := file.read(16*1024):
parser.Parse(buffer, False)
if first_buffer and self.document.documentElement:
self._setup_subset(buffer)
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index ebbe2b7..df5d519 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -566,10 +566,7 @@ class ElementTree:
# it with chunks.
self._root = parser._parse_whole(source)
return self._root
- while True:
- data = source.read(65536)
- if not data:
- break
+ while data := source.read(65536):
parser.feed(data)
self._root = parser.close()
return self._root
diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py
index 716f228..e906121 100644
--- a/Lib/xml/sax/xmlreader.py
+++ b/Lib/xml/sax/xmlreader.py
@@ -120,10 +120,8 @@ class IncrementalParser(XMLReader):
file = source.getCharacterStream()
if file is None:
file = source.getByteStream()
- buffer = file.read(self._bufsize)
- while buffer:
+ while buffer := file.read(self._bufsize):
self.feed(buffer)
- buffer = file.read(self._bufsize)
self.close()
def feed(self, data):