summaryrefslogtreecommitdiff
path: root/alot/commands
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/commands
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/commands')
-rw-r--r--alot/commands/globals.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index 7d5c1d3e..437b3644 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -733,7 +733,8 @@ class ComposeCommand(Command):
priority='error')
return
try:
- self.envelope.parse_template(open(path).read())
+ with open(path) as f:
+ self.envelope.parse_template(f.read())
except Exception as e:
ui.notify(str(e), priority='error')
return
@@ -792,7 +793,8 @@ class ComposeCommand(Command):
self.envelope.attach(sig, filename=name)
logging.debug('attached')
else:
- sigcontent = open(sig).read()
+ with open(sig) as f:
+ sigcontent = f.read()
enc = helper.guess_encoding(sigcontent)
mimetype = helper.guess_mimetype(sigcontent)
if mimetype.startswith('text'):