async def handle_response( self, resp=None, item=None, path=None, new_name=None, conflict="warn", stream=None, ): if resp.status == 409: return await self.handle_conflict( resp=resp, item=item, path=path, new_name=new_name, conflict=conflict, stream=stream, ) else: raise { 400: exceptions.InvalidPathError(item), 401: exceptions.AuthError(f"Bad credentials provided"), 403: exceptions.Forbidden(f"Forbidden"), 404: exceptions.NotFoundError( f"Item at path '{path or item.name}' cannot be found."), 410: exceptions.Gone( f"Item at path '{path or item.name}' has been removed."), }[resp.status]
async def intra_copy(self, src_path, dest_path, dest_provider=None): try: if src_path.kind == "file": shutil.copy(src_path.path, dest_path.path) else: shutil.copytree(src_path.path, dest_path.child(src_path.path)) except FileNotFoundError as exc: raise exceptions.NotFoundError(exc.filename)
async def delete(self, item, comfirm_delete=False): if item.is_file: try: os.remove(item.path) except FileNotFoundError: raise exceptions.NotFoundError(item.path) else: if item.is_root: raise Exception("That's the root!") shutil.rmtree(item.path)
async def validate_item(self, path, **kwargs): if not os.path.exists(path) or os.path.isdir( path) and not path.endswith("/"): raise exceptions.NotFoundError( f"Item at '{path}' could not be found, folders must end with '/'" ) if path == "/": return FileSystemMetadata.root() return FileSystemMetadata(path=path)
async def rename(self, item, new_name): try: os.rename(item.path, item.rename(new_name)) except FileNotFoundError as exc: raise exceptions.NotFoundError(exc.filename)
async def intra_move(self, src_path, dest_path, dest_provider=None): try: shutil.move(src_path.path, dest_path.path) except FileNotFoundError as exc: raise exceptions.NotFoundError(exc.filename)