| Index: chrome/common/extensions/docs/server2/intro_data_source.py
|
| diff --git a/chrome/common/extensions/docs/server2/intro_data_source.py b/chrome/common/extensions/docs/server2/intro_data_source.py
|
| index 14315ad784ed4b9026699b46a986c3f166278ee1..d2a1717ce7c04709129f572c284c8607de707ca9 100644
|
| --- a/chrome/common/extensions/docs/server2/intro_data_source.py
|
| +++ b/chrome/common/extensions/docs/server2/intro_data_source.py
|
| @@ -5,6 +5,7 @@
|
| from HTMLParser import HTMLParser
|
| import logging
|
| import re
|
| +import time
|
|
|
| from docs_server_utils import FormatKey
|
| from file_system import FileNotFoundError
|
| @@ -53,28 +54,43 @@ class _IntroParser(HTMLParser):
|
| self._current_heading['title'] += data
|
|
|
| class IntroDataSource(object):
|
| + class Factory(object):
|
| + def __init__(self, cache_builder, base_paths):
|
| + self._cache = cache_builder.build(self._MakeIntroDict)
|
| + self._base_paths = base_paths
|
| + self._intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL)
|
| +
|
| + def _MakeIntroDict(self, intro):
|
| + parser = _IntroParser()
|
| + parser.feed(intro)
|
| + intro = re.sub(self._intro_regex, '', intro, count=1)
|
| + return {
|
| + 'intro': Handlebar(intro),
|
| + 'toc': parser.toc,
|
| + 'title': parser.page_title
|
| + }
|
| +
|
| + def Create(self):
|
| + return IntroDataSource(self._cache.ScopeToRequest(), self._base_paths)
|
| +
|
| """This class fetches the intros for a given API. From this intro, a table
|
| of contents dictionary is created, which contains the headings in the intro.
|
| """
|
| - def __init__(self, cache_builder, base_paths):
|
| - self._cache = cache_builder.build(self._MakeIntroDict)
|
| + def __init__(self, cache, base_paths):
|
| + self._cache = cache
|
| self._base_paths = base_paths
|
| - self._intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL)
|
| -
|
| - def _MakeIntroDict(self, intro):
|
| - parser = _IntroParser()
|
| - parser.feed(intro)
|
| - intro = re.sub(self._intro_regex, '', intro, count=1)
|
| - return {
|
| - 'intro': Handlebar(intro),
|
| - 'toc': parser.toc,
|
| - 'title': parser.page_title
|
| - }
|
|
|
| def __getitem__(self, key):
|
| return self.get(key)
|
|
|
| def get(self, key):
|
| + start_time = time.time()
|
| + try:
|
| + return self._do_get(key)
|
| + finally:
|
| + logging.info("IntroDataSource: %sms", (time.time() - start_time) * 1000)
|
| +
|
| + def _do_get(self, key):
|
| real_path = FormatKey(key)
|
| error = None
|
| for base_path in self._base_paths:
|
|
|