summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2016-12-14 12:21:35 -0800
committerDylan Baker <dylan@pnwbakers.com>2016-12-14 15:43:39 -0800
commit8be904b96144e71458851d6e156dd4bae4398aa3 (patch)
tree55d3f6f59f5992f86558d03c5944b746b94e8d3b /alot/helper.py
parent15a724dfff40ec3b35af2526584e81ff82b4c40b (diff)
use open as a context manager instead of oneline open().read()
While open().read() is nice for its terseness it has the problem that it causes an fd to leak until the gc collects it. For short lived scripts this isn't a big deal, but for a program like alot that run for long periods of time it's better to be correct and ensure that the fd is closed.
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/alot/helper.py b/alot/helper.py
index f968306d..ba68bd45 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -465,7 +465,8 @@ def libmagic_version_at_least(version):
# TODO: make this work on blobs, not paths
def mimewrap(path, filename=None, ctype=None):
- content = open(path, 'rb').read()
+ with open(path, 'rb') as f:
+ content = f.read()
if not ctype:
ctype = guess_mimetype(content)
# libmagic < 5.12 incorrectly detects excel/powerpoint files as