summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2013-02-12 01:04:27 (GMT)
committerGiampaolo Rodola' <g.rodola@gmail.com>2013-02-12 01:04:27 (GMT)
commit2f50aaf2ff427fb713e82699a6dcbeeb038b10c2 (patch)
tree0e2c24897b8918f19d8504915ccebd466c0bbd92 /Lib/xml
parentfd6e6cfa29b2289e711dc7f57f36897c78899ee7 (diff)
downloadcpython-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.zip
cpython-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.tar.gz
cpython-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.tar.bz2
modernize some modules' code by using with statement around open()
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/dom/expatbuilder.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/Lib/xml/dom/expatbuilder.py b/Lib/xml/dom/expatbuilder.py
index f074ab9..81e2df7 100644
--- a/Lib/xml/dom/expatbuilder.py
+++ b/Lib/xml/dom/expatbuilder.py
@@ -905,11 +905,8 @@ def parse(file, namespaces=True):
builder = ExpatBuilder()
if isinstance(file, str):
- fp = open(file, 'rb')
- try:
+ with open(file, 'rb') as fp:
result = builder.parseFile(fp)
- finally:
- fp.close()
else:
result = builder.parseFile(file)
return result
@@ -939,11 +936,8 @@ def parseFragment(file, context, namespaces=True):
builder = FragmentBuilder(context)
if isinstance(file, str):
- fp = open(file, 'rb')
- try:
+ with open(file, 'rb') as fp:
result = builder.parseFile(fp)
- finally:
- fp.close()
else:
result = builder.parseFile(file)
return result