mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix annotations for fileobj in HTML builder
This commit is contained in:
parent
21b689aae2
commit
afafe52396
@ -956,11 +956,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
try:
|
try:
|
||||||
searchindexfn = path.join(self.outdir, self.searchindex_filename)
|
searchindexfn = path.join(self.outdir, self.searchindex_filename)
|
||||||
if self.indexer_dumps_unicode:
|
if self.indexer_dumps_unicode:
|
||||||
f = open(searchindexfn, 'r', encoding='utf-8') # type: ignore
|
with open(searchindexfn, 'r', encoding='utf-8') as ft: # type: ignore
|
||||||
|
self.indexer.load(ft, self.indexer_format)
|
||||||
else:
|
else:
|
||||||
f = open(searchindexfn, 'rb')
|
with open(searchindexfn, 'rb') as fb:
|
||||||
with f:
|
self.indexer.load(fb, self.indexer_format)
|
||||||
self.indexer.load(f, self.indexer_format)
|
|
||||||
except (IOError, OSError, ValueError):
|
except (IOError, OSError, ValueError):
|
||||||
if keep:
|
if keep:
|
||||||
logger.warning(__('search index couldn\'t be loaded, but not all '
|
logger.warning(__('search index couldn\'t be loaded, but not all '
|
||||||
@ -1175,11 +1175,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
# first write to a temporary file, so that if dumping fails,
|
# first write to a temporary file, so that if dumping fails,
|
||||||
# the existing index won't be overwritten
|
# the existing index won't be overwritten
|
||||||
if self.indexer_dumps_unicode:
|
if self.indexer_dumps_unicode:
|
||||||
f = open(searchindexfn + '.tmp', 'w', encoding='utf-8') # type: ignore
|
with open(searchindexfn + '.tmp', 'w', encoding='utf-8') as ft: # type: ignore
|
||||||
|
self.indexer.dump(ft, self.indexer_format)
|
||||||
else:
|
else:
|
||||||
f = open(searchindexfn + '.tmp', 'wb')
|
with open(searchindexfn + '.tmp', 'wb') as fb:
|
||||||
with f:
|
self.indexer.dump(fb, self.indexer_format)
|
||||||
self.indexer.dump(f, self.indexer_format)
|
|
||||||
movefile(searchindexfn + '.tmp', searchindexfn)
|
movefile(searchindexfn + '.tmp', searchindexfn)
|
||||||
logger.info(__('done'))
|
logger.info(__('done'))
|
||||||
|
|
||||||
@ -1433,11 +1433,11 @@ class SerializingHTMLBuilder(StandaloneHTMLBuilder):
|
|||||||
def dump_context(self, context, filename):
|
def dump_context(self, context, filename):
|
||||||
# type: (Dict, unicode) -> None
|
# type: (Dict, unicode) -> None
|
||||||
if self.implementation_dumps_unicode:
|
if self.implementation_dumps_unicode:
|
||||||
f = open(filename, 'w', encoding='utf-8') # type: ignore
|
with open(filename, 'w', encoding='utf-8') as ft: # type: ignore
|
||||||
|
self.implementation.dump(context, ft, *self.additional_dump_args)
|
||||||
else:
|
else:
|
||||||
f = open(filename, 'wb')
|
with open(filename, 'wb') as fb:
|
||||||
with f:
|
self.implementation.dump(context, fb, *self.additional_dump_args)
|
||||||
self.implementation.dump(context, f, *self.additional_dump_args)
|
|
||||||
|
|
||||||
def handle_page(self, pagename, ctx, templatename='page.html',
|
def handle_page(self, pagename, ctx, templatename='page.html',
|
||||||
outfilename=None, event_arg=None):
|
outfilename=None, event_arg=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user