Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/common/extensions/docs/server2/render_servlet.py

Issue 22824042: Docserver: SidenavDataSource refactor, transition to DataSourceRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup, deleted unused files/import Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 from urlparse import urlsplit 8 from urlparse import urlsplit
9 9
10 from data_source_registry import CreateDataSources
10 from file_system import FileNotFoundError 11 from file_system import FileNotFoundError
11 from servlet import Servlet, Response 12 from servlet import Servlet, Response
12 import svn_constants 13 import svn_constants
13 14
14 def _IsBinaryMimetype(mimetype): 15 def _IsBinaryMimetype(mimetype):
15 return any( 16 return any(
16 mimetype.startswith(prefix) for prefix in ['audio', 'image', 'video']) 17 mimetype.startswith(prefix) for prefix in ['audio', 'image', 'video'])
17 18
18 class RenderServlet(Servlet): 19 class RenderServlet(Servlet):
19 '''Servlet which renders templates. 20 '''Servlet which renders templates.
(...skipping 22 matching lines...) Expand all
42 if redirect is not None: 43 if redirect is not None:
43 return Response.Redirect(redirect) 44 return Response.Redirect(redirect)
44 45
45 canonical_result = server_instance.path_canonicalizer.Canonicalize(path) 46 canonical_result = server_instance.path_canonicalizer.Canonicalize(path)
46 redirect = canonical_result.path.lstrip('/') 47 redirect = canonical_result.path.lstrip('/')
47 if path != redirect: 48 if path != redirect:
48 return Response.Redirect('/' + redirect, 49 return Response.Redirect('/' + redirect,
49 permanent=canonical_result.permanent) 50 permanent=canonical_result.permanent)
50 51
51 templates = server_instance.template_data_source_factory.Create( 52 templates = server_instance.template_data_source_factory.Create(
52 self._request, path) 53 self._request,
54 CreateDataSources(server_instance, self._request))
53 55
54 content = None 56 content = None
55 content_type = None 57 content_type = None
56 58
57 try: 59 try:
58 # At this point, any valid paths ending with '/' have been redirected. 60 # At this point, any valid paths ending with '/' have been redirected.
59 # Therefore, the response should be a 404 Not Found. 61 # Therefore, the response should be a 404 Not Found.
60 if path.endswith('/'): 62 if path.endswith('/'):
61 pass 63 pass
62 elif fnmatch(path, 'extensions/examples/*.zip'): 64 elif fnmatch(path, 'extensions/examples/*.zip'):
(...skipping 27 matching lines...) Expand all
90 return Response.NotFound(content, headers=headers) 92 return Response.NotFound(content, headers=headers)
91 93
92 if not content: 94 if not content:
93 logging.error('%s had empty content' % path) 95 logging.error('%s had empty content' % path)
94 96
95 headers.update({ 97 headers.update({
96 'content-type': content_type, 98 'content-type': content_type,
97 'cache-control': 'max-age=300', 99 'cache-control': 'max-age=300',
98 }) 100 })
99 return Response.Ok(content, headers=headers) 101 return Response.Ok(content, headers=headers)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/redirector_test.py ('k') | chrome/common/extensions/docs/server2/server_instance.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698