generated from jCloud/repository-template
Add class for existing files
This commit is contained in:
@@ -24,7 +24,7 @@ import types
|
||||
|
||||
class ExistingDirectory(pathlib.Path):
|
||||
'''
|
||||
pathlib.Path subclass that is a directory
|
||||
pathlib.Path subclass that is a directory.
|
||||
|
||||
ExistingDirectory represents a filesystem path but it also checks
|
||||
whether the path exists and is not a file but a directory. It
|
||||
@@ -37,6 +37,21 @@ class ExistingDirectory(pathlib.Path):
|
||||
raise NotADirectoryError(errno.ENOTDIR, 'not a directory', path)
|
||||
super().__init__(*(path, *args), **kwargs)
|
||||
|
||||
class ExistingFile(pathlib.Path):
|
||||
'''
|
||||
pathlib.Path subclass that is a file.
|
||||
|
||||
ExistingFile represents a filesystem path but it also checks whether
|
||||
the path exists and is not a directory but a file. It inherits from
|
||||
pathlib.Path.
|
||||
'''
|
||||
def __init__(self, path, *args, **kwargs) -> None:
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(errno.ENOENT, 'no such file or directory', path)
|
||||
if not os.path.isfile(path):
|
||||
raise IsADirectoryError(errno.EISDIR, 'is a directory', path)
|
||||
super().__init__(*(path, *args), **kwargs)
|
||||
|
||||
def _quote(string: str, quotation_mark: str) -> str:
|
||||
'''
|
||||
Quotes a string.
|
||||
|
||||
Reference in New Issue
Block a user