Index: chrome/common/extensions/docs/server2/server_instance.py |
diff --git a/chrome/common/extensions/docs/server2/server_instance.py b/chrome/common/extensions/docs/server2/server_instance.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d3d745639322912d4c29e43e6e18c053a6eb9fa1 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/server_instance.py |
@@ -0,0 +1,29 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import logging |
+ |
+DOCS_PATH = 'docs/' |
+STATIC_PATH = DOCS_PATH + 'static/' |
+ |
+class ServerInstance(object): |
not at google - send to devlin
2012/06/08 01:42:53
Comment?
cduvall
2012/06/08 02:18:06
Done.
|
+ def __init__(self, data_source, fetcher): |
+ self._data_source = data_source |
+ self._fetcher = fetcher |
+ |
+ def Run(self, path, request_handler): |
+ parts = path.split('/') |
+ filename = parts[-1] |
+ content = self._data_source.Render(filename, '{"test": "Hello"}') |
+ if not content: |
+ logging.info('Template not found for: ' + filename) |
+ try: |
+ result = self._fetcher.FetchResource(STATIC_PATH + filename) |
+ for key in result.headers: |
+ request_handler.response.headers[key] = result.headers[key] |
+ content = result.content |
+ except: |
+ # 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.
|
+ content = 'File not found.' |
+ request_handler.response.out.write(content) |