Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4223)

Unified Diff: chrome/common/extensions/docs/server2/intro_data_source.py

Issue 10829348: Extensions Docs Server: Large performance increase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes and ObjectStore Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0629e4211ba98e90cbde989cafb772a225ff58f4 100644
--- a/chrome/common/extensions/docs/server2/intro_data_source.py
+++ b/chrome/common/extensions/docs/server2/intro_data_source.py
@@ -3,13 +3,15 @@
# found in the LICENSE file.
from HTMLParser import HTMLParser
-import logging
import re
from docs_server_utils import FormatKey
from file_system import FileNotFoundError
+import file_system_cache as fs_cache
from third_party.handlebar import Handlebar
+_intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL)
not at google - send to devlin 2012/08/21 00:30:11 should be _INTRO_REGEX or _H1_REGEX
cduvall 2012/08/21 01:33:33 Done.
+
class _IntroParser(HTMLParser):
""" An HTML parser which will parse table of contents and page title info out
of an intro.
@@ -53,23 +55,32 @@ 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,
+ fs_cache.INTRO)
+ self._base_paths = base_paths
+
+ def _MakeIntroDict(self, intro):
+ parser = _IntroParser()
+ parser.feed(intro)
+ intro = re.sub(_intro_regex, '', intro, count=1)
+ return {
+ 'intro': Handlebar(intro),
+ 'toc': parser.toc,
+ 'title': parser.page_title
+ }
+
+ def Create(self):
+ return IntroDataSource(self._cache, 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)

Powered by Google App Engine
This is Rietveld 408576698