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

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

Issue 10830252: Extensions Docs Server: Uniform handling of file not found errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 import re 5 import re
6 import xml.dom.minidom as xml 6 import xml.dom.minidom as xml
7 7
8 import file_system 8 import file_system
9 from future import Future 9 from future import Future
10 10
11 class SubversionFileSystem(file_system.FileSystem): 11 class SubversionFileSystem(file_system.FileSystem):
12 """Class to fetch resources from src.chromium.org. 12 """Class to fetch resources from src.chromium.org.
13 """ 13 """
14 def __init__(self, fetcher): 14 def __init__(self, fetcher):
15 self._fetcher = fetcher 15 self._fetcher = fetcher
16 16
17 def Read(self, paths, binary=False): 17 def Read(self, paths, binary=False):
18 return Future(delegate=_AsyncFetchFuture(paths, self._fetcher, binary)) 18 return Future(delegate=_AsyncFetchFuture(paths, self._fetcher, binary))
19 19
20 def Stat(self, path): 20 def Stat(self, path):
21 directory = path.rsplit('/', 1)[0] 21 directory = path.rsplit('/', 1)[0]
22 dir_html = self._fetcher.Fetch(directory + '/').content 22 dir_html = self._fetcher.Fetch(directory + '/').content
23 return self.StatInfo(int(re.search('([0-9]+)', dir_html).group(0))) 23 return self.StatInfo(int(re.search('([0-9]+)', dir_html).group(0)))
not at google - send to devlin 2012/08/10 06:12:16 also need to do something here too?
cduvall 2012/08/10 17:25:16 Done.
24 24
25 class _AsyncFetchFuture(object): 25 class _AsyncFetchFuture(object):
26 def __init__(self, paths, fetcher, binary): 26 def __init__(self, paths, fetcher, binary):
27 # A list of tuples of the form (path, Future). 27 # A list of tuples of the form (path, Future).
28 self._fetches = [] 28 self._fetches = []
29 self._value = {} 29 self._value = {}
30 self._error = None 30 self._error = None
31 self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths] 31 self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths]
32 self._binary = binary 32 self._binary = binary
33 33
34 def _ListDir(self, directory): 34 def _ListDir(self, directory):
35 dom = xml.parseString(directory) 35 dom = xml.parseString(directory)
36 files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')] 36 files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')]
37 if '..' in files: 37 if '..' in files:
38 files.remove('..') 38 files.remove('..')
39 return files 39 return files
40 40
41 def Get(self): 41 def Get(self):
42 for path, future in self._fetches: 42 for path, future in self._fetches:
43 result = future.Get() 43 result = future.Get()
44 if result.status_code == 404: 44 if result.status_code == 404:
45 self._value[path] = None 45 raise file_system.FileNotFoundError(path)
46 elif path.endswith('/'): 46 elif path.endswith('/'):
47 self._value[path] = self._ListDir(result.content) 47 self._value[path] = self._ListDir(result.content)
48 elif not self._binary: 48 elif not self._binary:
49 self._value[path] = file_system._ProcessFileData(result.content, path) 49 self._value[path] = file_system._ProcessFileData(result.content, path)
50 else: 50 else:
51 self._value[path] = result.content 51 self._value[path] = result.content
52 if self._error is not None: 52 if self._error is not None:
53 raise self._error 53 raise self._error
54 return self._value 54 return self._value
55 55
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698