use context managers to open files for reading

This commit is contained in:
Eli Schwartz 2019-09-11 23:35:00 -04:00
parent e4ea6f9e15
commit 7358e09e88
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -20,7 +20,8 @@ def available_translations():
stats = P('localization/stats.calibre_msgpack', allow_user_override=False)
if os.path.exists(stats):
from calibre.utils.serialize import msgpack_loads
stats = msgpack_loads(open(stats, 'rb').read())
with open(stats, 'rb') as f:
stats = msgpack_loads(f.read())
else:
stats = {}
_available_translations = [x for x in stats if stats[x] > 0.1]