diff options
Diffstat (limited to 'sphinx/websupport')
-rw-r--r-- | sphinx/websupport/__init__.py | 12 | ||||
-rw-r--r-- | sphinx/websupport/search/__init__.py | 8 | ||||
-rw-r--r-- | sphinx/websupport/search/nullsearch.py | 2 | ||||
-rw-r--r-- | sphinx/websupport/search/whooshsearch.py | 2 |
4 files changed, 10 insertions, 14 deletions
diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py index 606d549a6..69914da95 100644 --- a/sphinx/websupport/__init__.py +++ b/sphinx/websupport/__init__.py @@ -130,11 +130,8 @@ class WebSupport(object): """Load and return the "global context" pickle.""" if not self._globalcontext: infilename = path.join(self.datadir, 'globalcontext.pickle') - f = open(infilename, 'rb') - try: + with open(infilename, 'rb') as f: self._globalcontext = pickle.load(f) - finally: - f.close() return self._globalcontext def get_document(self, docname, username='', moderator=False): @@ -185,14 +182,11 @@ class WebSupport(object): infilename = docpath + '.fpickle' try: - f = open(infilename, 'rb') + with open(infilename, 'rb') as f: + document = pickle.load(f) except IOError: raise errors.DocumentNotFoundError( 'The document "%s" could not be found' % docname) - try: - document = pickle.load(f) - finally: - f.close() comment_opts = self._make_comment_options(username, moderator) comment_meta = self._make_metadata( diff --git a/sphinx/websupport/search/__init__.py b/sphinx/websupport/search/__init__.py index 844a3b468..80b5a3535 100644 --- a/sphinx/websupport/search/__init__.py +++ b/sphinx/websupport/search/__init__.py @@ -34,19 +34,20 @@ class BaseSearch(object): """ pass - def feed(self, pagename, title, doctree): + def feed(self, pagename, filename, title, doctree): """Called by the builder to add a doctree to the index. Converts the `doctree` to text and passes it to :meth:`add_document`. You probably won't want to override this unless you need access to the `doctree`. Override :meth:`add_document` instead. :param pagename: the name of the page to be indexed + :param filename: the name of the original source file :param title: the title of the page to be indexed :param doctree: is the docutils doctree representation of the page """ - self.add_document(pagename, title, doctree.astext()) + self.add_document(pagename, filename, title, doctree.astext()) - def add_document(self, pagename, title, text): + def add_document(self, pagename, filename, title, text): """Called by :meth:`feed` to add a document to the search index. This method should should do everything necessary to add a single document to the search index. @@ -59,6 +60,7 @@ class BaseSearch(object): query. :param pagename: the name of the page being indexed + :param filename: the name of the original source file :param title: the page's title :param text: the full text of the page """ diff --git a/sphinx/websupport/search/nullsearch.py b/sphinx/websupport/search/nullsearch.py index 9e990b1cf..4d0db9553 100644 --- a/sphinx/websupport/search/nullsearch.py +++ b/sphinx/websupport/search/nullsearch.py @@ -17,7 +17,7 @@ class NullSearch(BaseSearch): """A search adapter that does nothing. Used when no search adapter is specified. """ - def feed(self, pagename, title, doctree): + def feed(self, pagename, filename, title, doctree): pass def query(self, q): diff --git a/sphinx/websupport/search/whooshsearch.py b/sphinx/websupport/search/whooshsearch.py index 4b0769f50..f31dc4d52 100644 --- a/sphinx/websupport/search/whooshsearch.py +++ b/sphinx/websupport/search/whooshsearch.py @@ -44,7 +44,7 @@ class WhooshSearch(BaseSearch): def finish_indexing(self): self.index_writer.commit() - def add_document(self, pagename, title, text): + def add_document(self, pagename, filename, title, text): self.index_writer.add_document(path=text_type(pagename), title=title, text=text) |