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

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

Issue 149513014: Docserver: Add FileSystem.Exists method and start sanity checking path format (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 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 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 logging 5 import logging
6 import posixpath 6 import posixpath
7 import traceback 7 import traceback
8 8
9 from environment import IsPreviewServer 9 from environment import IsPreviewServer
10 from file_system import FileNotFoundError 10 from file_system import FileNotFoundError
(...skipping 18 matching lines...) Expand all
29 def CreateServerInstance(self): 29 def CreateServerInstance(self):
30 raise NotImplementedError(self.__class__) 30 raise NotImplementedError(self.__class__)
31 31
32 def __init__(self, request, delegate): 32 def __init__(self, request, delegate):
33 Servlet.__init__(self, request) 33 Servlet.__init__(self, request)
34 self._delegate = delegate 34 self._delegate = delegate
35 35
36 def Get(self): 36 def Get(self):
37 ''' Render the page for a request. 37 ''' Render the page for a request.
38 ''' 38 '''
39 # TODO(kalman): a consistent path syntax (even a Path class?) so that we
40 # can stop being so conservative with stripping and adding back the '/'s.
41 path = self._request.path.lstrip('/') 39 path = self._request.path.lstrip('/')
42 server_instance = self._delegate.CreateServerInstance() 40 server_instance = self._delegate.CreateServerInstance()
43 41
44 try: 42 try:
45 return self._GetSuccessResponse(path, server_instance) 43 return self._GetSuccessResponse(path, server_instance)
46 except FileNotFoundError: 44 except FileNotFoundError:
47 if IsPreviewServer(): 45 if IsPreviewServer():
48 logging.error(traceback.format_exc()) 46 logging.error(traceback.format_exc())
49 # Maybe it didn't find the file because its canonical location is 47 # Maybe it didn't find the file because its canonical location is
50 # somewhere else; this is distinct from "redirects", which are typically 48 # somewhere else; this is distinct from "redirects", which are typically
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if warnings: 102 if warnings:
105 sep = '\n - ' 103 sep = '\n - '
106 logging.warning('Rendering %s:%s%s' % (path, sep, sep.join(warnings))) 104 logging.warning('Rendering %s:%s%s' % (path, sep, sep.join(warnings)))
107 105
108 content_type = content_and_type.content_type 106 content_type = content_and_type.content_type
109 if isinstance(content, unicode): 107 if isinstance(content, unicode):
110 content = content.encode('utf-8') 108 content = content.encode('utf-8')
111 content_type += '; charset=utf-8' 109 content_type += '; charset=utf-8'
112 110
113 return Response.Ok(content, headers=_MakeHeaders(content_type)) 111 return Response.Ok(content, headers=_MakeHeaders(content_type))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698