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

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

Issue 10826173: Extensions Docs Server: Proper path handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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_PATH = 'docs' 10 DOCS_PATH = 'docs'
(...skipping 18 matching lines...) Expand all
29 result = self._cache.GetFromFile(STATIC_DIR_PREFIX + '/' + path) 29 result = self._cache.GetFromFile(STATIC_DIR_PREFIX + '/' + path)
30 base, ext = os.path.splitext(path) 30 base, ext = os.path.splitext(path)
31 response.headers['content-type'] = mimetypes.types_map[ext] 31 response.headers['content-type'] = mimetypes.types_map[ext]
32 return result 32 return result
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, 'extensions/examples/*.zip'):
40 content = self._example_zipper.Create(path[:-len('.zip')]) 40 content = self._example_zipper.Create(
41 path[len('extensions/'):-len('.zip')])
41 response.headers['content-type'] = mimetypes.types_map['.zip'] 42 response.headers['content-type'] = mimetypes.types_map['.zip']
42 elif path.startswith('examples/'): 43 elif path.startswith('extensions/examples/'):
43 content = self._cache.GetFromFile(DOCS_PATH + '/' + path) 44 content = self._cache.GetFromFile(
45 DOCS_PATH + '/' + path[len('extensions/'):])
not at google - send to devlin 2012/08/06 23:13:46 I presume the apps samples page will be set up to
cduvall 2012/08/06 23:14:55 Right now they're just linked to the github page.
44 response.headers['content-type'] = 'text/plain' 46 response.headers['content-type'] = 'text/plain'
45 elif path.startswith('static/'): 47 elif path.startswith('static/'):
46 content = self._FetchStaticResource(path, response) 48 content = self._FetchStaticResource(path, response)
47 else: 49 else:
48 content = templates.Render(path) 50 content = templates.Render(path)
49 51
50 if content: 52 if content:
51 response.out.write(content) 53 response.out.write(content)
52 else: 54 else:
53 response.set_status(404); 55 response.set_status(404);
54 response.out.write(templates.Render('404')) 56 response.out.write(templates.Render('404'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698