Kaydet (Commit) 14c7bc2a authored tarafından Benjamin Peterson's avatar Benjamin Peterson

close file explicitly

üst ceea163e
...@@ -467,7 +467,6 @@ def translation(domain, localedir=None, languages=None, ...@@ -467,7 +467,6 @@ def translation(domain, localedir=None, languages=None,
if fallback: if fallback:
return NullTranslations() return NullTranslations()
raise IOError(ENOENT, 'No translation file found for domain', domain) 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 # Avoid opening, reading, and parsing the .mo file after it's been done
# once. # once.
result = None result = None
...@@ -475,7 +474,8 @@ def translation(domain, localedir=None, languages=None, ...@@ -475,7 +474,8 @@ def translation(domain, localedir=None, languages=None,
key = os.path.abspath(mofile) key = os.path.abspath(mofile)
t = _translations.get(key) t = _translations.get(key)
if t is None: 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 # Copy the translation object to allow setting fallbacks and
# output charset. All other instance data is shared with the # output charset. All other instance data is shared with the
# cached object. # cached object.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment