コード例 #1
0
 def test_convert_enametoolong(self):
     exception = OSError(errno.ENAMETOOLONG, "File name too long: test")
     with self.assertRaises(fs.errors.PathError) as ctx:
         with convert_os_errors("stat", "/tmp/test"):
             raise exception
     self.assertEqual(ctx.exception.exc, exception)
     self.assertEqual(ctx.exception.path, "/tmp/test")
コード例 #2
0
 def test_convert_enoent(self):
     exception = OSError(errno.ENOENT, "resource not found")
     with self.assertRaises(fs.errors.ResourceNotFound) as ctx:
         with convert_os_errors("stat", "/tmp/test"):
             raise exception
     self.assertEqual(ctx.exception.exc, exception)
     self.assertEqual(ctx.exception.path, "/tmp/test")
コード例 #3
0
ファイル: fs_prim_adapter.py プロジェクト: SETI/pdart
    def getinfo(self, path: str, namespaces: Any = None) -> Info:
        # The pyfilesystem2 documentation says namespaces should be a
        # list of strings, but the test-suite has a case expecting it
        # to succeed when it's a single string.  Geez.

        # I REALLY REALLY hate untyped languages.
        self.check()
        if not namespaces:
            namespaces = ["basic"]
        if type(namespaces) is not list:
            namespaces = [namespaces]
        node = self._resolve_path_to_node(path)
        if not node:
            raise ValueError(f"Invalid path: {path}.")
        info = {}  # Dict[str, Dict[str, object]]
        info["basic"] = {
            "is_dir": self.prims.is_dir(node),
            "name": fs.path.basename(node.path),
        }
        if "details" in namespaces:
            sys_path = self.getsyspath(path)
            if sys_path:
                with convert_os_errors("getinfo", path):
                    _stat = os.stat(sys_path)
                info["details"] = self._make_details_from_stat(_stat)
            else:
                info["details"] = self._make_default_details(node)

        return Info(info)
コード例 #4
0
ファイル: fs.py プロジェクト: whole-tale/girderfs
 def openbin(self, path, mode="r", buffering=-1, **options):
     _mode = Mode(mode)
     _mode.validate_bin()
     self.check()
     _path = self.validatepath(path)
     if _path == "/":
         raise FileExpected(path)
     with convert_os_errors("openbin", path):
         fd = self._fs.open(_path, os.O_RDONLY)
         fdict = self._fs.openFiles[path]
         self._fs._ensure_region_available(path, fdict, fd, 0,
                                           fdict["obj"]["size"])
         return open(fdict["path"], "r+b")
コード例 #5
0
ファイル: fs_prim_adapter.py プロジェクト: SETI/pdart
    def setinfo(self, path: str, info: Mapping[str, Mapping[str,
                                                            object]]) -> None:
        self.check()
        # Check for errors.
        self._resolve_path_to_node(path)
        if "details" in info:
            sys_path = self.getsyspath(path)
            if sys_path:
                details = info["details"]
                if "accessed" in details or "modified" in details:
                    accessed = cast(int, details.get("accessed"))
                    modified = cast(int, details.get("modified", accessed))
                    with convert_os_errors("setinfo", path):
                        os.utime(sys_path, (accessed, modified))

        return None
コード例 #6
0
    def assert_convert_os_errors(self):

        with self.assertRaises(fserrors.ResourceNotFound):
            with convert_os_errors('foo', 'test'):
                raise OSError(errno.ENOENT)