Chromium Code Reviews| 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): | |
|
not at google - send to devlin
2012/06/08 01:42:53
Comment?
cduvall
2012/06/08 02:18:06
Done.
| |
| 11 def __init__(self, data_source, fetcher): | |
| 12 self._data_source = data_source | |
| 13 self._fetcher = fetcher | |
| 14 | |
| 15 def Run(self, path, request_handler): | |
| 16 parts = path.split('/') | |
| 17 filename = parts[-1] | |
| 18 content = self._data_source.Render(filename, '{"test": "Hello"}') | |
| 19 if not content: | |
| 20 logging.info('Template not found for: ' + filename) | |
| 21 try: | |
| 22 result = self._fetcher.FetchResource(STATIC_PATH + filename) | |
| 23 for key in result.headers: | |
| 24 request_handler.response.headers[key] = result.headers[key] | |
| 25 content = result.content | |
| 26 except: | |
| 27 # TODO should be an actual not found page. | |
|
not at google - send to devlin
2012/06/08 01:42:53
Should make the response code 404, too.
I presume
cduvall
2012/06/08 02:18:06
Done. Just checked and default is 200.
| |
| 28 content = 'File not found.' | |
| 29 request_handler.response.out.write(content) | |
| OLD | NEW |