| 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 import logging | 5 import logging |
| 6 | 6 |
| 7 DOCS_PATH = 'docs/' | 7 DOCS_PATH = 'docs/' |
| 8 STATIC_PATH = DOCS_PATH + 'static/' | 8 STATIC_PATH = DOCS_PATH + 'static/' |
| 9 | 9 |
| 10 class ServerInstance(object): | 10 class ServerInstance(object): |
| 11 """This class is used to hold a data source and fetcher for an instance of a | 11 """This class is used to hold a data source and fetcher for an instance of a |
| 12 server. Each new branch will get its own ServerInstance. | 12 server. Each new branch will get its own ServerInstance. |
| 13 """ | 13 """ |
| 14 def __init__(self, data_source, fetcher): | 14 def __init__(self, api_data_source, template_data_source, fetcher): |
| 15 self._data_source = data_source | 15 self._api_data_source = api_data_source |
| 16 self._template_data_source = template_data_source |
| 16 self._fetcher = fetcher | 17 self._fetcher = fetcher |
| 17 | 18 |
| 19 |
| 18 def Run(self, path, request_handler): | 20 def Run(self, path, request_handler): |
| 19 parts = path.split('/') | 21 parts = path.split('/') |
| 20 filename = parts[-1] | 22 filename = parts[-1] |
| 21 content = self._data_source.Render(filename, '{"test": "Hello"}') | 23 content = self._template_data_source.Render(filename, |
| 24 self._api_data_source[filename]) |
| 22 if not content: | 25 if not content: |
| 23 logging.info('Template not found for: ' + filename) | 26 logging.info('Template not found for: ' + filename) |
| 24 try: | 27 try: |
| 25 result = self._fetcher.FetchResource(STATIC_PATH + filename) | 28 result = self._fetcher.FetchResource(STATIC_PATH + filename) |
| 26 for key in result.headers: | 29 for key in result.headers: |
| 27 request_handler.response.headers[key] = result.headers[key] | 30 request_handler.response.headers[key] = result.headers[key] |
| 28 content = result.content | 31 content = result.content |
| 29 except: | 32 except: |
| 30 request_handler.response.set_status(404) | 33 request_handler.response.set_status(404) |
| 31 # TODO should be an actual not found page. | 34 # TODO should be an actual not found page. |
| 32 content = 'File not found.' | 35 content = 'File not found.' |
| 33 logging.info | 36 logging.info |
| 34 request_handler.response.out.write(content) | 37 request_handler.response.out.write(content) |
| OLD | NEW |