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 fnmatch import fnmatch | 5 from fnmatch import fnmatch |
6 import mimetypes | 6 import mimetypes |
7 import os | 7 import os |
8 | 8 |
9 STATIC_DIR_PREFIX = 'docs/server2' | 9 STATIC_DIR_PREFIX = 'docs/server2' |
10 DOCS_PREFIX = 'docs' | 10 DOCS_PATH = 'docs' |
11 | 11 |
12 class ServerInstance(object): | 12 class ServerInstance(object): |
13 """This class is used to hold a data source and fetcher for an instance of a | 13 """This class is used to hold a data source and fetcher for an instance of a |
14 server. Each new branch will get its own ServerInstance. | 14 server. Each new branch will get its own ServerInstance. |
15 """ | 15 """ |
16 def __init__(self, | 16 def __init__(self, |
17 template_data_source_factory, | 17 template_data_source_factory, |
18 example_zipper, | 18 example_zipper, |
19 cache_builder): | 19 cache_builder): |
20 self._template_data_source_factory = template_data_source_factory | 20 self._template_data_source_factory = template_data_source_factory |
(...skipping 12 matching lines...) Expand all Loading... |
33 except Exception: | 33 except Exception: |
34 return '' | 34 return '' |
35 | 35 |
36 def Get(self, path, request, response): | 36 def Get(self, path, request, response): |
37 templates = self._template_data_source_factory.Create(request) | 37 templates = self._template_data_source_factory.Create(request) |
38 | 38 |
39 if fnmatch(path, 'examples/*.zip'): | 39 if fnmatch(path, 'examples/*.zip'): |
40 content = self._example_zipper.Create(path[:-len('.zip')]) | 40 content = self._example_zipper.Create(path[:-len('.zip')]) |
41 response.headers['content-type'] = mimetypes.types_map['.zip'] | 41 response.headers['content-type'] = mimetypes.types_map['.zip'] |
42 elif path.startswith('examples/'): | 42 elif path.startswith('examples/'): |
43 content = self._cache.GetFromFile(DOCS_PREFIX + '/' + path) | 43 content = self._cache.GetFromFile(DOCS_PATH + '/' + path) |
44 response.headers['content-type'] = 'text/plain' | 44 response.headers['content-type'] = 'text/plain' |
45 elif path.startswith('static/'): | 45 elif path.startswith('static/'): |
46 content = self._FetchStaticResource(path, response) | 46 content = self._FetchStaticResource(path, response) |
47 else: | 47 else: |
48 content = templates.Render(path) | 48 content = templates.Render(path) |
49 | 49 |
50 if content: | 50 if content: |
51 response.out.write(content) | 51 response.out.write(content) |
52 else: | 52 else: |
53 response.set_status(404); | 53 response.set_status(404); |
54 response.out.write(templates.Render('404')) | 54 response.out.write(templates.Render('404')) |
OLD | NEW |