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

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

Issue 10689144: Extensions Docs Server: Samples zip files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Samples page with full links and descriptions Created 8 years, 5 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 import mimetypes 5 import mimetypes
6 import os 6 import os
7 7
8 STATIC_DIR_PREFIX = 'docs/server2/' 8 STATIC_DIR_PREFIX = 'docs/server2'
9 DOCS_PREFIX = 'docs'
9 10
10 class ServerInstance(object): 11 class ServerInstance(object):
11 """This class is used to hold a data source and fetcher for an instance of a 12 """This class is used to hold a data source and fetcher for an instance of a
12 server. Each new branch will get its own ServerInstance. 13 server. Each new branch will get its own ServerInstance.
13 """ 14 """
14 def __init__(self, template_data_source, cache_builder): 15 def __init__(self, template_data_source, example_zipper, cache_builder):
15 self._template_data_source = template_data_source 16 self._template_data_source = template_data_source
17 self._example_zipper = example_zipper
16 self._cache = cache_builder.build(lambda x: x) 18 self._cache = cache_builder.build(lambda x: x)
17 mimetypes.init() 19 mimetypes.init()
18 20
19 def _FetchStaticResource(self, path, request_handler): 21 def _FetchStaticResource(self, path, request_handler):
20 """Fetch a resource in the 'static' directory. 22 """Fetch a resource in the 'static' directory.
21 """ 23 """
22 try: 24 try:
23 result = self._cache.get(STATIC_DIR_PREFIX + path) 25 result = self._cache.get(STATIC_DIR_PREFIX + '/' + path)
24 base, ext = os.path.splitext(path) 26 base, ext = os.path.splitext(path)
25 request_handler.response.headers['content-type'] = ( 27 request_handler.response.headers['content-type'] = (
26 mimetypes.types_map[ext]) 28 mimetypes.types_map[ext])
27 return result 29 return result
28 except: 30 except:
29 return '' 31 return ''
30 32
31 def Get(self, path, request_handler): 33 def Get(self, path, request_handler):
32 if path.startswith('static'): 34 if path.endswith('.zip'):
not at google - send to devlin 2012/07/12 00:22:48 Could be even smarter here: if fnmatch(path, 'exa
cduvall 2012/07/12 01:51:23 Done.
35 content = self._example_zipper[path]
36 request_handler.response.headers['content-type'] = (
37 mimetypes.types_map['.zip'])
38 elif path.startswith('example'):
39 content = self._cache.get(DOCS_PREFIX + '/' + path)
40 request_handler.response.headers['content-type'] = 'text/plain'
not at google - send to devlin 2012/07/12 00:22:48 This has the potential to be pretty cool if we wan
41 elif path.startswith('static'):
33 content = self._FetchStaticResource(path, request_handler) 42 content = self._FetchStaticResource(path, request_handler)
34 else: 43 else:
35 content = self._template_data_source.Render(path) 44 content = self._template_data_source.Render(path)
36 if content: 45 if content:
37 request_handler.response.out.write(content) 46 request_handler.response.out.write(content)
38 else: 47 else:
39 # TODO: Actual 404 page. 48 # TODO: Actual 404 page.
40 request_handler.response.set_status(404); 49 request_handler.response.set_status(404);
41 request_handler.response.out.write('File not found.') 50 request_handler.response.out.write('File not found.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698