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

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

Issue 240303006: Docs: Remove unnecessary redirects from directories to 'index' files since we (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move check up, remove nacl redirect Created 6 years, 8 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 mimetypes 6 import mimetypes
7 import posixpath 7 import posixpath
8 import traceback 8 import traceback
9 9
10 from compiled_file_system import SingleFile 10 from compiled_file_system import SingleFile
11 from directory_zipper import DirectoryZipper 11 from directory_zipper import DirectoryZipper
12 from docs_server_utils import ToUnicode 12 from docs_server_utils import ToUnicode
13 from file_system import FileNotFoundError 13 from file_system import FileNotFoundError
14 from future import Future 14 from future import Future
15 from path_canonicalizer import PathCanonicalizer 15 from path_canonicalizer import PathCanonicalizer
16 from path_util import AssertIsValid, Join, ToDirectory 16 from path_util import AssertIsValid, IsDirectory, Join, ToDirectory
17 from special_paths import SITE_VERIFICATION_FILE 17 from special_paths import SITE_VERIFICATION_FILE
18 from third_party.handlebar import Handlebar 18 from third_party.handlebar import Handlebar
19 from third_party.markdown import markdown 19 from third_party.markdown import markdown
20 20
21 21
22 _MIMETYPE_OVERRIDES = { 22 _MIMETYPE_OVERRIDES = {
23 # SVG is not supported by mimetypes.guess_type on AppEngine. 23 # SVG is not supported by mimetypes.guess_type on AppEngine.
24 '.svg': 'image/svg+xml', 24 '.svg': 'image/svg+xml',
25 } 25 }
26 26
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 lambda: ContentAndType(zip_future.Get(), 'application/zip', None)) 141 lambda: ContentAndType(zip_future.Get(), 'application/zip', None))
142 142
143 # If there is no file extension, look for a file with one of the default 143 # If there is no file extension, look for a file with one of the default
144 # extensions. If one cannot be found, check if the path is a directory. 144 # extensions. If one cannot be found, check if the path is a directory.
145 # If it is, then check for an index file with one of the default 145 # If it is, then check for an index file with one of the default
146 # extensions. 146 # extensions.
147 if not ext: 147 if not ext:
148 new_path = self._AddExt(path) 148 new_path = self._AddExt(path)
149 # Add a trailing / to check if it is a directory and not a file with 149 # Add a trailing / to check if it is a directory and not a file with
150 # no extension. 150 # no extension.
151 if new_path is None and self.file_system.Exists(path + '/').Get(): 151 if new_path is None and self.file_system.Exists(ToDirectory(path)).Get():
152 new_path = self._AddExt(path + '/index') 152 new_path = self._AddExt(Join(path, 'index'))
153 # If an index file wasn't found in this directly then we're never going
154 # to find a file.
155 if new_path is None:
156 return FileNotFoundError.RaiseInFuture('"%s" is a directory' % path)
153 if new_path is not None: 157 if new_path is not None:
154 path = new_path 158 path = new_path
155 159
156 return self._content_cache.GetFromFile(path) 160 return self._content_cache.GetFromFile(path)
157 161
158 def _AddExt(self, path): 162 def _AddExt(self, path):
159 '''Tries to append each of the default file extensions to path and returns 163 '''Tries to append each of the default file extensions to path and returns
160 the first one that is an existing file. 164 the first one that is an existing file.
161 ''' 165 '''
162 for default_ext in self._default_extensions: 166 for default_ext in self._default_extensions:
(...skipping 16 matching lines...) Expand all
179 self.GetContentAndType(Join(root, base)))) 183 self.GetContentAndType(Join(root, base))))
180 # TODO(kalman): Cache .zip files for each directory (if supported). 184 # TODO(kalman): Cache .zip files for each directory (if supported).
181 def resolve(): 185 def resolve():
182 for label, future in futures: 186 for label, future in futures:
183 try: future.Get() 187 try: future.Get()
184 except: logging.error('%s: %s' % (label, traceback.format_exc())) 188 except: logging.error('%s: %s' % (label, traceback.format_exc()))
185 return Future(callback=resolve) 189 return Future(callback=resolve)
186 190
187 def __repr__(self): 191 def __repr__(self):
188 return 'ContentProvider of <%s>' % repr(self.file_system) 192 return 'ContentProvider of <%s>' % repr(self.file_system)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | chrome/common/extensions/docs/server2/content_provider_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698