OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging |
| 6 |
| 7 DOCS_PATH = 'docs/' |
| 8 STATIC_PATH = DOCS_PATH + 'static/' |
| 9 |
| 10 class ServerInstance(object): |
| 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. |
| 13 """ |
| 14 def __init__(self, data_source, fetcher): |
| 15 self._data_source = data_source |
| 16 self._fetcher = fetcher |
| 17 |
| 18 def Run(self, path, request_handler): |
| 19 parts = path.split('/') |
| 20 filename = parts[-1] |
| 21 content = self._data_source.Render(filename, '{"test": "Hello"}') |
| 22 if not content: |
| 23 logging.info('Template not found for: ' + filename) |
| 24 try: |
| 25 result = self._fetcher.FetchResource(STATIC_PATH + filename) |
| 26 for key in result.headers: |
| 27 request_handler.response.headers[key] = result.headers[key] |
| 28 content = result.content |
| 29 except: |
| 30 request_handler.response.set_status(404) |
| 31 # TODO should be an actual not found page. |
| 32 content = 'File not found.' |
| 33 logging.info |
| 34 request_handler.response.out.write(content) |
OLD | NEW |