mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
use contextmanagers for open()
This commit is contained in:
parent
94db9b84cd
commit
b5eda37c75
@ -52,7 +52,8 @@ class MOBIInput(InputFormatPlugin):
|
||||
if raw:
|
||||
if isinstance(raw, unicode_type):
|
||||
raw = raw.encode('utf-8')
|
||||
open(u'debug-raw.html', 'wb').write(raw)
|
||||
with open(u'debug-raw.html', 'wb') as f:
|
||||
f.write(raw)
|
||||
from calibre.ebooks.oeb.base import close_self_closing_tags
|
||||
for f, root in parse_cache.items():
|
||||
raw = html.tostring(root, encoding='utf-8', method='xml',
|
||||
|
@ -65,7 +65,8 @@ class RecipeInput(InputFormatPlugin):
|
||||
zf = ZipFile(recipe_or_file, 'r')
|
||||
zf.extractall()
|
||||
zf.close()
|
||||
self.recipe_source = open(u'download.recipe', 'rb').read()
|
||||
with open('download.recipe', 'rb') as f:
|
||||
self.recipe_source = f.read()
|
||||
recipe = compile_recipe(self.recipe_source)
|
||||
recipe.needs_subscription = False
|
||||
self.recipe_object = recipe(opts, log, self.report_progress)
|
||||
@ -87,7 +88,8 @@ class RecipeInput(InputFormatPlugin):
|
||||
self.recipe_source = self.recipe_source.encode('utf-8')
|
||||
recipe = compile_recipe(self.recipe_source)
|
||||
elif os.access(recipe_or_file, os.R_OK):
|
||||
self.recipe_source = open(recipe_or_file, 'rb').read()
|
||||
with open(recipe_or_file, 'rb') as f:
|
||||
self.recipe_source = f.read()
|
||||
recipe = compile_recipe(self.recipe_source)
|
||||
log('Using custom recipe')
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user