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

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

Issue 10834329: Extension docs server: many changes to bring down the latency of the server, (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 os 5 import os
6 6
7 class FileNotFoundError(Exception): 7 class FileNotFoundError(Exception):
8 def __init__(self, filename): 8 def __init__(self, filename):
9 Exception.__init__(self, filename) 9 Exception.__init__(self, filename)
10 10
11 class StatInfo(object):
12 """The result of calling Stat on a FileSystem.
13 """
14 def __init__(self, version, child_versions=None):
15 self.version = version
16 self.child_versions = child_versions
17
11 def _ProcessFileData(data, path): 18 def _ProcessFileData(data, path):
12 if os.path.splitext(path)[-1] not in ['.js', '.html', '.json']: 19 if os.path.splitext(path)[-1] not in ['.js', '.html', '.json']:
13 return data 20 return data
14 try: 21 try:
15 return unicode(data, 'utf-8') 22 return unicode(data, 'utf-8')
16 except: 23 except:
17 return unicode(data, 'latin-1') 24 return unicode(data, 'latin-1')
18 25
19 class FileSystem(object): 26 class FileSystem(object):
20 """A FileSystem interface that can read files and directories. 27 """A FileSystem interface that can read files and directories.
21 """ 28 """
22 class StatInfo(object):
23 """The result of calling Stat on a FileSystem.
24 """
25 def __init__(self, version, child_versions=None):
26 self.version = version
27 self.child_versions = child_versions
28 29
29 def Read(self, paths, binary=False): 30 def Read(self, paths, binary=False):
30 """Reads each file in paths and returns a dictionary mapping the path to the 31 """Reads each file in paths and returns a dictionary mapping the path to the
31 contents. If a path in paths ends with a '/', it is assumed to be a 32 contents. If a path in paths ends with a '/', it is assumed to be a
32 directory, and a list of files in the directory is mapped to the path. 33 directory, and a list of files in the directory is mapped to the path.
33 34
34 If binary=False, the contents of each file will be unicode parsed as utf-8, 35 If binary=False, the contents of each file will be unicode parsed as utf-8,
35 and failing that as latin-1 (some extension docs use latin-1). If 36 and failing that as latin-1 (some extension docs use latin-1). If
36 binary=True then the contents will be a str. 37 binary=True then the contents will be a str.
37 """ 38 """
38 raise NotImplementedError() 39 raise NotImplementedError()
39 40
40 def ReadSingle(self, path): 41 def ReadSingle(self, path):
41 """Reads a single file from the FileSystem. 42 """Reads a single file from the FileSystem.
42 """ 43 """
43 return self.Read([path]).Get()[path] 44 return self.Read([path]).Get()[path]
44 45
45 def Stat(self, path): 46 def Stat(self, path):
46 """Returns a |StatInfo| object containing the version of |path|. If |path| 47 """Returns a |StatInfo| object containing the version of |path|. If |path|
47 is a directory, |StatInfo| will have the versions of all the children of 48 is a directory, |StatInfo| will have the versions of all the children of
48 the directory in |StatInfo.child_versions|. 49 the directory in |StatInfo.child_versions|.
49 """ 50 """
50 raise NotImplementedError() 51 raise NotImplementedError()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698