Definition at line 5 of file TypedPath.py.
◆ __init__()
| selfie_lib.TypedPath.TypedPath.__init__ |
( |
| self, |
|
|
str | absolute_path ) |
Definition at line 6 of file TypedPath.py.
6 def __init__(self, absolute_path: str):
7 self.absolute_path = absolute_path
8
◆ __eq__()
| bool selfie_lib.TypedPath.TypedPath.__eq__ |
( |
| self, |
|
|
object | other ) |
Definition at line 59 of file TypedPath.py.
59 def __eq__(self, other: object) -> bool:
60 if not isinstance(other, TypedPath):
61 return NotImplemented
62 return self.absolute_path == other.absolute_path
63
◆ __hash__()
| selfie_lib.TypedPath.TypedPath.__hash__ |
( |
| self | ) |
|
Definition at line 9 of file TypedPath.py.
9 def __hash__(self):
10 return hash(self.absolute_path)
11
◆ __lt__()
| bool selfie_lib.TypedPath.TypedPath.__lt__ |
( |
| self, |
|
|
"TypedPath" | other ) |
Definition at line 64 of file TypedPath.py.
64 def __lt__(self, other: "TypedPath") -> bool:
65 return self.absolute_path < other.absolute_path
66
◆ __str__()
| str selfie_lib.TypedPath.TypedPath.__str__ |
( |
| self | ) |
|
Definition at line 12 of file TypedPath.py.
12 def __str__(self) -> str:
13 return self.absolute_path
14
◆ assert_folder()
| None selfie_lib.TypedPath.TypedPath.assert_folder |
( |
| self | ) |
|
Definition at line 28 of file TypedPath.py.
28 def assert_folder(self) -> None:
29 if not self.is_folder:
30 raise AssertionError(
31 f"Expected {self} to be a folder but it doesn't end with `/`"
32 )
33
◆ is_folder()
| bool selfie_lib.TypedPath.TypedPath.is_folder |
( |
| self | ) |
|
Definition at line 25 of file TypedPath.py.
25 def is_folder(self) -> bool:
26 return self.absolute_path.endswith("/")
27
◆ name()
| str selfie_lib.TypedPath.TypedPath.name |
( |
| self | ) |
|
Definition at line 16 of file TypedPath.py.
16 def name(self) -> str:
17 if self.absolute_path.endswith("/"):
18 path = self.absolute_path[:-1]
19 else:
20 path = self.absolute_path
21 last_slash = path.rfind("/")
22 return path[last_slash + 1 :]
23
◆ of_file()
| "TypedPath" selfie_lib.TypedPath.TypedPath.of_file |
( |
| cls, |
|
|
str | path ) |
Definition at line 75 of file TypedPath.py.
75 def of_file(cls, path: str) -> "TypedPath":
76 unix_path = path.replace("\\", "/")
77 if unix_path.endswith("/"):
78 raise ValueError("Expected path to not end with a slash for a file")
79 return cls(unix_path)
◆ of_folder()
| "TypedPath" selfie_lib.TypedPath.TypedPath.of_folder |
( |
| cls, |
|
|
str | path ) |
Definition at line 68 of file TypedPath.py.
68 def of_folder(cls, path: str) -> "TypedPath":
69 unix_path = path.replace("\\", "/")
70 if not unix_path.endswith("/"):
71 unix_path += "/"
72 return cls(unix_path)
73
◆ parent_folder()
| "TypedPath" selfie_lib.TypedPath.TypedPath.parent_folder |
( |
| self | ) |
|
Definition at line 34 of file TypedPath.py.
34 def parent_folder(self) -> "TypedPath":
35 if self.absolute_path == "/":
36 raise ValueError("Path does not have a parent folder")
37 trimmed_path = self.absolute_path.rstrip("/")
38 last_idx = trimmed_path.rfind("/")
39 return TypedPath.of_folder(trimmed_path[: last_idx + 1])
40
◆ relativize()
| str selfie_lib.TypedPath.TypedPath.relativize |
( |
| self, |
|
|
"TypedPath" | child ) |
Definition at line 53 of file TypedPath.py.
53 def relativize(self, child: "TypedPath") -> str:
54 self.assert_folder()
55 if not child.absolute_path.startswith(self.absolute_path):
56 raise ValueError(f"Expected {child} to start with {self.absolute_path}")
57 return child.absolute_path[len(self.absolute_path) :]
58
◆ resolve_file()
| "TypedPath" selfie_lib.TypedPath.TypedPath.resolve_file |
( |
| self, |
|
|
str | child ) |
Definition at line 41 of file TypedPath.py.
41 def resolve_file(self, child: str) -> "TypedPath":
42 self.assert_folder()
43 if child.startswith("/") or child.endswith("/"):
44 raise ValueError("Child path is not valid for file resolution")
45 return self.of_file(f"{self.absolute_path}{child}")
46
◆ resolve_folder()
| "TypedPath" selfie_lib.TypedPath.TypedPath.resolve_folder |
( |
| self, |
|
|
str | child ) |
Definition at line 47 of file TypedPath.py.
47 def resolve_folder(self, child: str) -> "TypedPath":
48 self.assert_folder()
49 if child.startswith("/"):
50 raise ValueError("Child path starts with a slash")
51 return self.of_folder(f"{self.absolute_path}{child}/")
52
◆ absolute_path
| selfie_lib.TypedPath.TypedPath.absolute_path = absolute_path |
◆ is_folder
| selfie_lib.TypedPath.TypedPath.is_folder |
The documentation for this class was generated from the following file: