aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/plugins/custom_subtitles/tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/plugins/custom_subtitles/tools.py')
-rw-r--r--mediagoblin/plugins/custom_subtitles/tools.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/mediagoblin/plugins/custom_subtitles/tools.py b/mediagoblin/plugins/custom_subtitles/tools.py
index 2cc5157f..f947ba92 100644
--- a/mediagoblin/plugins/custom_subtitles/tools.py
+++ b/mediagoblin/plugins/custom_subtitles/tools.py
@@ -18,24 +18,18 @@ from mediagoblin import mg_globals
import os
def get_path(path):
- path = eval(path) # Converting string to a tuple
- return path
+ path = eval(path) # Converting string to a tuple
+ return path
def open_subtitle(path):
- subtitle_public_filepath = get_path(path)
- subtitle_public_file = mg_globals.public_store.get_file(
- subtitle_public_filepath, 'rb')
- try:
+ subtitle_public_filepath = get_path(path)
+ with mg_globals.public_store.get_file(
+ subtitle_public_filepath, 'rb') as subtitle_public_file:
text = subtitle_public_file.read().decode('utf-8')
return text
- finally:
- subtitle_public_file.close()
def save_subtitle(path,text):
- subtitle_public_filepath = get_path(path)
- subtitle_public_file = mg_globals.public_store.get_file(
- subtitle_public_filepath, 'wb')
- try:
- subtitle_public_file.write(text)
- finally:
- subtitle_public_file.close() \ No newline at end of file
+ subtitle_public_filepath = get_path(path)
+ with mg_globals.public_store.get_file(
+ subtitle_public_filepath, 'wb') as subtitle_public_file:
+ subtitle_public_file.write(text) \ No newline at end of file