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

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

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: rebase Created 7 years, 7 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 from appengine_url_fetcher import AppEngineUrlFetcher
6 from caching_file_system import CachingFileSystem
7 from caching_rietveld_patcher import CachingRietveldPatcher
8 from chained_compiled_file_system import (CompiledFileSystem,
9 ChainedCompiledFileSystem)
10 from instance_servlet import InstanceServlet
11 from render_servlet import RenderServlet
12 from rietveld_patcher import RietveldPatcher, RietveldPatcherError
13 from object_store_creator import ObjectStoreCreator
14 from patched_file_system import PatchedFileSystem
15 from server_instance import ServerInstance
16 from servlet import Request, Response, Servlet
17 import svn_constants
18 import url_constants
19
20 class PatchServlet(Servlet):
21 '''Servlet which renders patched docs.
22 '''
23 class Delegate(InstanceServlet.Delegate):
not at google - send to devlin 2013/05/11 20:39:53 see earlier comment about using composition over i
not at google - send to devlin 2013/05/11 20:39:53 Why InstanceServlet rather than RenderServlet? I w
24 def __init__(self, issue):
25 self._issue = issue
26
27 # Overriden in test.
28 def _GetChannel(self, channel):
not at google - send to devlin 2013/05/11 20:39:53 methods intended for overriding shouldn't start wi
29 return channel
30
31 def CreateServerInstanceForChannel(self, channel):
32 channel = self._GetChannel(channel)
33 base_object_store_creator = ObjectStoreCreator(channel,
34 start_empty=False)
35 object_store_creator = ObjectStoreCreator('trunk@%s' % self._issue,
36 start_empty=False)
37 # TODO(fj): Use OfflineFileSystem here once all json/idl files in api/
38 # are pulled into data store by cron jobs.
39 base_file_system = CachingFileSystem(self.CreateHostFileSystemForBranch(
40 channel), base_object_store_creator)
41 rietveld_patcher = CachingRietveldPatcher(
42 RietveldPatcher(svn_constants.EXTENSIONS_PATH,
43 self._issue,
44 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)),
45 object_store_creator)
46 patched_file_system = PatchedFileSystem(base_file_system,
47 rietveld_patcher)
48 base_compiled_fs_factory = CompiledFileSystem.Factory(
49 base_file_system, base_object_store_creator)
50 compiled_fs_factory = ChainedCompiledFileSystem.Factory(
51 patched_file_system, object_store_creator, base_compiled_fs_factory)
52 return ServerInstance(channel,
53 object_store_creator,
54 patched_file_system,
55 self.CreateAppSamplesFileSystem(
56 object_store_creator),
57 '/_patch/%s/static' % self._issue,
58 compiled_fs_factory)
59
60 def __init__(self, request, delegate=None):
61 self._request = request
62 self._delegate = delegate
not at google - send to devlin 2013/05/11 20:39:53 see below. self._issue = ... self._delegate = del
63
64 def Get(self):
65 path_with_issue = self._request.path.lstrip('/')
66 if '/' in path_with_issue:
67 issue, real_path = path_with_issue.split('/', 1)
68 else:
69 return Response.NotFound('Malformed URL.')
not at google - send to devlin 2013/05/11 20:39:53 Maybe print what the URL should look like
方觉(Fang Jue) 2013/05/12 03:01:47 Done.
70
71 fake_path = '/trunk/%s' % real_path
72
73 if self._delegate is None:
74 self._delegate = PatchServlet.Delegate(issue)
not at google - send to devlin 2013/05/11 20:39:53 everything above here can go in the constructor.
方觉(Fang Jue) 2013/05/12 03:01:47 but what about return Response.NotFound('Malformed
not at google - send to devlin 2013/05/12 03:28:27 I see. Ok. It's just weird overriding a field on s
75
76 try:
77 response = RenderServlet(Request(fake_path,
78 self._request.host,
79 self._request.headers),
80 self._delegate).Get()
81 # Disable cache for patched content.
82 response.headers.pop('cache-control', None)
83 except RietveldPatcherError as e:
84 response = Response.NotFound(e.message, {'Content-Type': 'text/plain'})
85
86 if response.IsRedirect():
not at google - send to devlin 2013/05/11 20:39:53 maybe this should actually be GetRedirect(). redi
方觉(Fang Jue) 2013/05/12 03:01:47 Done.
87 url = response.headers['Location']
88 if url.startswith('/trunk/'):
89 url = url.split('/trunk', 1)[1]
90 response.headers['Location'] = '/_patch/%s%s' % (issue, url)
91 return response
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698