OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 logging | 6 import logging |
7 import mimetypes | 7 import mimetypes |
8 import posixpath | 8 import posixpath |
9 import traceback | 9 import traceback |
10 from urlparse import urlsplit | 10 from urlparse import urlsplit |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 content_provider.file_system).Redirect(self._request.host, path) | 91 content_provider.file_system).Redirect(self._request.host, path) |
92 if redirect is not None: | 92 if redirect is not None: |
93 return Response.Redirect(redirect, permanent=False) | 93 return Response.Redirect(redirect, permanent=False) |
94 | 94 |
95 content_and_type = content_provider.GetContentAndType(path).Get() | 95 content_and_type = content_provider.GetContentAndType(path).Get() |
96 if not content_and_type.content: | 96 if not content_and_type.content: |
97 logging.error('%s had empty content' % path) | 97 logging.error('%s had empty content' % path) |
98 | 98 |
99 content = content_and_type.content | 99 content = content_and_type.content |
100 if isinstance(content, Handlebar): | 100 if isinstance(content, Handlebar): |
| 101 template_content, template_warnings = ( |
| 102 server_instance.template_renderer.Render(content, self._request)) |
101 # HACK: the Google ID thing (google2ed...) doesn't have a title. | 103 # HACK: the Google ID thing (google2ed...) doesn't have a title. |
102 content, warnings = server_instance.document_renderer.Render( | 104 content, doc_warnings = server_instance.document_renderer.Render( |
103 server_instance.template_renderer.Render(content, self._request), | 105 template_content, |
104 render_title=path != 'google2ed1af765c529f57.html') | 106 render_title=path != 'google2ed1af765c529f57.html') |
| 107 warnings = template_warnings + doc_warnings |
105 if warnings: | 108 if warnings: |
106 sep = '\n - ' | 109 sep = '\n - ' |
107 logging.warning('Rendering %s:%s%s' % (path, sep, sep.join(warnings))) | 110 logging.warning('Rendering %s:%s%s' % (path, sep, sep.join(warnings))) |
108 | 111 |
109 content_type = content_and_type.content_type | 112 content_type = content_and_type.content_type |
110 if isinstance(content, unicode): | 113 if isinstance(content, unicode): |
111 content = content.encode('utf-8') | 114 content = content.encode('utf-8') |
112 content_type += '; charset=utf-8' | 115 content_type += '; charset=utf-8' |
113 | 116 |
114 return Response.Ok(content, headers=_MakeHeaders(content_type)) | 117 return Response.Ok(content, headers=_MakeHeaders(content_type)) |
OLD | NEW |