Mercurial > public > sg101
comparison core/functions.py @ 976:f5aa74dcdd7a
Ensure temporary files get deleted during hotlinking.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 05 Oct 2015 20:07:44 -0500 |
parents | 51a2051588f5 |
children | e932f2ecd4a7 |
comparison
equal
deleted
inserted
replaced
975:8c3d52b7cbd1 | 976:f5aa74dcdd7a |
---|---|
1 """This file houses various core utility functions""" | 1 """This file houses various core utility functions""" |
2 from contextlib import contextmanager | |
2 import datetime | 3 import datetime |
3 import logging | 4 import logging |
4 import os | 5 import os |
5 import re | 6 import re |
6 import tempfile | 7 import tempfile |
27 return self | 28 return self |
28 | 29 |
29 def __exit__(self, exc_type, exc_value, traceback): | 30 def __exit__(self, exc_type, exc_value, traceback): |
30 self.file.close() | 31 self.file.close() |
31 os.remove(self.filename) | 32 os.remove(self.filename) |
33 | |
34 | |
35 @contextmanager | |
36 def remove_file(path): | |
37 """Context manager for removing a file when the context is exited.""" | |
38 try: | |
39 yield path | |
40 finally: | |
41 os.remove(path) | |
32 | 42 |
33 | 43 |
34 def send_mail(subject, message, from_email, recipient_list, reply_to=None, defer=True): | 44 def send_mail(subject, message, from_email, recipient_list, reply_to=None, defer=True): |
35 """ | 45 """ |
36 The main send email function. Use this function to send email from the | 46 The main send email function. Use this function to send email from the |