summaryrefslogtreecommitdiffstats
path: root/Lib/gettext.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-10 01:38:02 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-10 01:38:02 (GMT)
commit14c7bc2ad22f4fffdcf2b3d58b1358846a53079f (patch)
tree97b2089490370d8c77f926661b0c98631ffeff99 /Lib/gettext.py
parentceea163e7ce7a4d0952000801ba4856931b47103 (diff)
downloadcpython-14c7bc2ad22f4fffdcf2b3d58b1358846a53079f.zip
cpython-14c7bc2ad22f4fffdcf2b3d58b1358846a53079f.tar.gz
cpython-14c7bc2ad22f4fffdcf2b3d58b1358846a53079f.tar.bz2
close file explicitly
Diffstat (limited to 'Lib/gettext.py')
-rw-r--r--Lib/gettext.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py
index 90ebc51..8b8b510 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -467,7 +467,6 @@ def translation(domain, localedir=None, languages=None,
if fallback:
return NullTranslations()
raise IOError(ENOENT, 'No translation file found for domain', domain)
- # TBD: do we need to worry about the file pointer getting collected?
# Avoid opening, reading, and parsing the .mo file after it's been done
# once.
result = None
@@ -475,7 +474,8 @@ def translation(domain, localedir=None, languages=None,
key = os.path.abspath(mofile)
t = _translations.get(key)
if t is None:
- t = _translations.setdefault(key, class_(open(mofile, 'rb')))
+ with open(mofile, 'rb') as fp:
+ t = _translations.setdefault(key, class_(fp))
# Copy the translation object to allow setting fallbacks and
# output charset. All other instance data is shared with the
# cached object.