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

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: 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 9
10 class ServerInstance(object): 10 class ServerInstance(object):
11 """This class is used to hold a data source and fetcher for an instance of a 11 """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. 12 server. Each new branch will get its own ServerInstance.
13 """ 13 """
14 def __init__(self, template_data_source, cache_builder): 14 def __init__(self, template_data_source, zip_data_source, cache_builder):
15 self._template_data_source = template_data_source 15 self._template_data_source = template_data_source
16 self._zip_data_source = zip_data_source
16 self._cache = cache_builder.build(lambda x: x) 17 self._cache = cache_builder.build(lambda x: x)
17 mimetypes.init() 18 mimetypes.init()
18 19
19 def _FetchStaticResource(self, path, request_handler): 20 def _FetchStaticResource(self, path, request_handler):
20 """Fetch a resource in the 'static' directory. 21 """Fetch a resource in the 'static' directory.
21 """ 22 """
22 try: 23 try:
23 result = self._cache.get(STATIC_DIR_PREFIX + path) 24 result = self._cache.get(STATIC_DIR_PREFIX + path)
24 base, ext = os.path.splitext(path) 25 base, ext = os.path.splitext(path)
25 request_handler.response.headers['content-type'] = ( 26 request_handler.response.headers['content-type'] = (
26 mimetypes.types_map[ext]) 27 mimetypes.types_map[ext])
27 return result 28 return result
28 except: 29 except:
29 return '' 30 return ''
30 31
31 def Get(self, path, request_handler): 32 def Get(self, path, request_handler):
32 if path.startswith('static'): 33 if path.endswith('.zip'):
not at google - send to devlin 2012/07/11 00:35:09 I'd be more comfortable if this was restricted spe
cduvall 2012/07/11 20:56:30 Done. I used re because glob is only for the files
34 content = self._zip_data_source[path]
35 request_handler.response.headers['content-type'] = (
36 mimetypes.types_map['.zip'])
37 elif path.startswith('static'):
33 content = self._FetchStaticResource(path, request_handler) 38 content = self._FetchStaticResource(path, request_handler)
34 else: 39 else:
35 content = self._template_data_source.Render(path) 40 content = self._template_data_source.Render(path)
36 if content: 41 if content:
37 request_handler.response.out.write(content) 42 request_handler.response.out.write(content)
38 else: 43 else:
39 # TODO: Actual 404 page. 44 # TODO: Actual 404 page.
40 request_handler.response.set_status(404); 45 request_handler.response.set_status(404);
41 request_handler.response.out.write('File not found.') 46 request_handler.response.out.write('File not found.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698