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

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

Issue 10828042: Extensions Docs Server: Integration testing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for CQ 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_PREFIX = 'docs' 10 DOCS_PATH = 'docs'
11 11
12 class ServerInstance(object): 12 class ServerInstance(object):
13 """This class is used to hold a data source and fetcher for an instance of a 13 """This class is used to hold a data source and fetcher for an instance of a
14 server. Each new branch will get its own ServerInstance. 14 server. Each new branch will get its own ServerInstance.
15 """ 15 """
16 def __init__(self, 16 def __init__(self,
17 template_data_source_factory, 17 template_data_source_factory,
18 example_zipper, 18 example_zipper,
19 cache_builder): 19 cache_builder):
20 self._template_data_source_factory = template_data_source_factory 20 self._template_data_source_factory = template_data_source_factory
(...skipping 12 matching lines...) Expand all
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, 'examples/*.zip'):
40 content = self._example_zipper.Create(path[:-len('.zip')]) 40 content = self._example_zipper.Create(path[:-len('.zip')])
41 response.headers['content-type'] = mimetypes.types_map['.zip'] 41 response.headers['content-type'] = mimetypes.types_map['.zip']
42 elif path.startswith('examples/'): 42 elif path.startswith('examples/'):
43 content = self._cache.GetFromFile(DOCS_PREFIX + '/' + path) 43 content = self._cache.GetFromFile(DOCS_PATH + '/' + path)
44 response.headers['content-type'] = 'text/plain' 44 response.headers['content-type'] = 'text/plain'
45 elif path.startswith('static/'): 45 elif path.startswith('static/'):
46 content = self._FetchStaticResource(path, response) 46 content = self._FetchStaticResource(path, response)
47 else: 47 else:
48 content = templates.Render(path) 48 content = templates.Render(path)
49 49
50 if content: 50 if content:
51 response.out.write(content) 51 response.out.write(content)
52 else: 52 else:
53 response.set_status(404); 53 response.set_status(404);
54 response.out.write(templates.Render('404')) 54 response.out.write(templates.Render('404'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698