| OLD | NEW | 
|    1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |    1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|    2 # Use of this source code is governed by a BSD-style license that can be |    2 # Use of this source code is governed by a BSD-style license that can be | 
|    3 # found in the LICENSE file. |    3 # found in the LICENSE file. | 
|    4  |    4  | 
|    5 from HTMLParser import HTMLParser |    5 from HTMLParser import HTMLParser | 
|    6 import re |    6 import re | 
|    7 import logging |    7 import logging | 
|    8  |    8  | 
|    9 from docs_server_utils import FormatKey |    9 from docs_server_utils import FormatKey | 
|   10 from file_system import FileNotFoundError |   10 from file_system import FileNotFoundError | 
|   11 import compiled_file_system as compiled_fs |   11 import compiled_file_system as compiled_fs | 
|   12 from third_party.handlebar import Handlebar |   12 from third_party.handlebar import Handlebar | 
|   13  |   13  | 
|   14 # Increment this version if there are changes to the table of contents dict that |   14 # Increment this version if there are changes to the table of contents dict that | 
|   15 # IntroDataSource caches. |   15 # IntroDataSource caches. | 
|   16 _VERSION = 1 |   16 _VERSION = 2 | 
|   17  |   17  | 
|   18 _H1_REGEX = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL) |   18 _H1_REGEX = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL) | 
|   19  |   19  | 
|   20 class _IntroParser(HTMLParser): |   20 class _IntroParser(HTMLParser): | 
|   21   """ An HTML parser which will parse table of contents and page title info out |   21   """ An HTML parser which will parse table of contents and page title info out | 
|   22   of an intro. |   22   of an intro. | 
|   23   """ |   23   """ | 
|   24   def __init__(self): |   24   def __init__(self): | 
|   25     HTMLParser.__init__(self) |   25     HTMLParser.__init__(self) | 
|   26     self.toc = [] |   26     self.toc = [] | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   91         'extensions_toc': extensions_parser.toc, |   91         'extensions_toc': extensions_parser.toc, | 
|   92       } |   92       } | 
|   93  |   93  | 
|   94     def Create(self): |   94     def Create(self): | 
|   95       return IntroDataSource(self._cache, self._base_paths) |   95       return IntroDataSource(self._cache, self._base_paths) | 
|   96  |   96  | 
|   97   def __init__(self, cache, base_paths): |   97   def __init__(self, cache, base_paths): | 
|   98     self._cache = cache |   98     self._cache = cache | 
|   99     self._base_paths = base_paths |   99     self._base_paths = base_paths | 
|  100  |  100  | 
|  101   def __getitem__(self, key): |  | 
|  102     return self.get(key) |  | 
|  103  |  | 
|  104   def get(self, key): |  101   def get(self, key): | 
|  105     real_path = FormatKey(key) |  102     real_path = FormatKey(key) | 
|  106     error = None |  103     error = None | 
|  107     for base_path in self._base_paths: |  104     for base_path in self._base_paths: | 
|  108       try: |  105       try: | 
|  109         return self._cache.GetFromFile(base_path + '/' + real_path) |  106         return self._cache.GetFromFile(base_path + '/' + real_path) | 
|  110       except FileNotFoundError as error: |  107       except FileNotFoundError as error: | 
|  111         pass |  108         pass | 
|  112     raise ValueError(str(error) + ': No intro found for "%s".' % key) |  109     raise ValueError(str(error) + ': No intro found for "%s".' % key) | 
| OLD | NEW |