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

Unified Diff: chrome/common/extensions/docs/server2/handler.py

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix example zipper 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/handler.py
diff --git a/chrome/common/extensions/docs/server2/handler.py b/chrome/common/extensions/docs/server2/handler.py
index 53c40c40c0de5a6b78504e1ad7fa5e381f888530..abaf186067d442c14d5e4cec91bdcc2c0d50d26b 100644
--- a/chrome/common/extensions/docs/server2/handler.py
+++ b/chrome/common/extensions/docs/server2/handler.py
@@ -2,66 +2,55 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-from appengine_wrappers import webapp
from cron_servlet import CronServlet
-from render_servlet import RenderServlet
-from servlet import Request
+from instance_servlet import InstanceServlet
+from servlet import Servlet, Request, Response
_SERVLETS = {
'cron': CronServlet,
}
-
-class Handler(webapp.RequestHandler):
- def __init__(self, request, response):
- super(Handler, self).__init__(request, response)
-
- def _RedirectSpecialCases(self, path):
- if not path or path == 'index.html':
- self.redirect('http://developer.google.com/chrome')
- return True
-
- if path == 'apps.html':
- self.redirect('/apps/about_apps.html')
- return True
-
- return False
-
- def _RedirectFromCodeDotGoogleDotCom(self, path):
- if (not self.request.url.startswith(('http://code.google.com',
- 'https://code.google.com'))):
- return False
-
- new_url = 'http://developer.chrome.com/'
-
- # switch to https if necessary
- if (self.request.url.startswith('https')):
- new_url = new_url.replace('http', 'https', 1)
-
- path = path.split('/')
- if len(path) > 0 and path[0] == 'chrome':
- path.pop(0)
- for channel in BranchUtility.GetAllBranchNames():
- if channel in path:
- position = path.index(channel)
- path.pop(position)
- path.insert(0, channel)
- new_url += '/'.join(path)
- self.redirect(new_url)
- return True
-
- def get(self):
- path, request, response = (self.request.path.lstrip('/'),
- self.request,
- self.response)
+_DEFAULT_SERVLET = InstanceServlet.GetConstructor()
+
+def _RedirectSpecialCases(path):
+ if not path or path == 'index.html':
+ return Response.Redirect('http://developer.google.com/chrome')
+ if path == 'apps.html':
+ return Response.Redirect('/apps/about_apps.html')
+ return None
+
+def _RedirectFromCodeDotGoogleDotCom(path):
+ if not path.startswith(('http://code.google.com', 'https://code.google.com')):
+ return None
+
+ new_url = 'http://developer.chrome.com/'
+
+ # switch to https if necessary
+ if path.startswith('https'):
+ new_url = new_url.replace('http', 'https', 1)
+
+ path = path.split('/')
cduvall 2013/05/08 03:09:14 this is a little confusing reassigning the list of
not at google - send to devlin 2013/05/08 18:26:19 Oops. Done. Moving these back into instance method
+ if len(path) > 0 and path[0] == 'chrome':
+ path.pop(0)
+ for channel in BranchUtility.GetAllChannelNames():
+ if channel in path:
+ position = path.index(channel)
+ path.pop(position)
+ path.insert(0, channel)
+ new_url += '/'.join(path)
+ return Response.Redirect(new_url)
+
+class Handler(Servlet):
+ def Get(self):
+ path = self._request.path
if path in ['favicon.ico', 'robots.txt']:
- response.set_status(404)
- return
+ return Response.NotFound('')
- if self._RedirectSpecialCases(path):
- return
- if self._RedirectFromCodeDotGoogleDotCom(path):
- return
+ redirect = _RedirectSpecialCases(path)
+ if redirect is None:
+ redirect = _RedirectFromCodeDotGoogleDotCom(path)
+ if redirect is not None:
+ return redirect
if path.startswith('_'):
servlet_path = path[1:]
@@ -70,15 +59,9 @@ class Handler(webapp.RequestHandler):
servlet_name, servlet_path = servlet_path.split('/', 1)
servlet = _SERVLETS.get(servlet_name)
if servlet is None:
- response.out.write('"%s" servlet not found' % servlet_path)
- response.set_status(404)
- return
+ return Response.NotFound('"%s" servlet not found' % servlet_path)
else:
servlet_path = path
- servlet = RenderServlet
-
- servlet_response = servlet(Request(servlet_path, request.headers)).Get()
+ servlet = _DEFAULT_SERVLET
- response.out.write(servlet_response.content.ToString())
- response.headers.update(servlet_response.headers)
- response.status = servlet_response.status
+ return servlet(Request(servlet_path, self._request.headers)).Get()

Powered by Google App Engine
This is Rietveld 408576698