Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / local_file_system.py
index 9b405ad..c9d13f8 100644 (file)
@@ -8,13 +8,18 @@ import sys
 from docs_server_utils import StringIdentity
 from file_system import FileSystem, FileNotFoundError, StatInfo
 from future import Gettable, Future
+from path_util import AssertIsDirectory, AssertIsValid
+from test_util import ChromiumPath
+
 
 def _ConvertToFilepath(path):
   return path.replace('/', os.sep)
 
+
 def _ConvertFromFilepath(path):
   return path.replace(os.sep, '/')
 
+
 def _ReadFile(filename):
   try:
     with open(filename, 'rb') as f:
@@ -22,6 +27,7 @@ def _ReadFile(filename):
   except IOError as e:
     raise FileNotFoundError('Read failed for %s: %s' % (filename, e))
 
+
 def _ListDir(dir_name):
   all_files = []
   try:
@@ -38,6 +44,7 @@ def _ListDir(dir_name):
       all_files.append(posix_path)
   return all_files
 
+
 def _CreateStatInfo(path):
   try:
     path_mtime = os.stat(path).st_mtime
@@ -56,22 +63,24 @@ def _CreateStatInfo(path):
   except OSError as e:
     raise FileNotFoundError('os.stat failed for %s: %s' % (path, e))
 
+
 class LocalFileSystem(FileSystem):
   '''FileSystem implementation which fetches resources from the local
   filesystem.
   '''
   def __init__(self, base_path):
+    AssertIsDirectory(base_path)
     self._base_path = _ConvertToFilepath(base_path)
 
   @staticmethod
-  def Create(root=''):
-    return LocalFileSystem(
-        os.path.join(sys.path[0], '..', '..', '..', '..', '..', root))
+  def Create(*path):
+    return LocalFileSystem(ChromiumPath(*path))
 
   def Read(self, paths):
     def resolve():
       result = {}
       for path in paths:
+        AssertIsValid(path)
         full_path = os.path.join(self._base_path,
                                  _ConvertToFilepath(path).lstrip(os.sep))
         if path == '' or path.endswith('/'):
@@ -85,6 +94,7 @@ class LocalFileSystem(FileSystem):
     return Future(value=())
 
   def Stat(self, path):
+    AssertIsValid(path)
     full_path = os.path.join(self._base_path,
                              _ConvertToFilepath(path).lstrip(os.sep))
     return _CreateStatInfo(full_path)