Discourage writes to pathclass._absolute_path.

master
voussoir 2021-09-09 17:30:46 -07:00
parent d37e6fdf0b
commit 0416f0babf
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 9 additions and 6 deletions

View File

@ -107,7 +107,7 @@ class Path:
self._case_correct = _case_correct self._case_correct = _case_correct
if isinstance(path, Path): if isinstance(path, Path):
self.absolute_path = path.absolute_path absolute_path = path.absolute_path
else: else:
path = path.strip() path = path.strip()
if re.search('^[A-Za-z]:$', path): if re.search('^[A-Za-z]:$', path):
@ -115,10 +115,9 @@ class Path:
path += self.sep path += self.sep
path = normalize_sep(path) path = normalize_sep(path)
path = os.path.normpath(path) path = os.path.normpath(path)
path = os.path.abspath(path) absolute_path = os.path.abspath(path)
self.absolute_path = path
self.absolute_path = normalize_sep(self.absolute_path, self.sep) self._absolute_path = normalize_sep(absolute_path, self.sep)
def __contains__(self, other): def __contains__(self, other):
other = self.spawn(other) other = self.spawn(other)
@ -146,6 +145,10 @@ class Path:
def __repr__(self): def __repr__(self):
return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path)) return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path))
@property
def absolute_path(self):
return self._absolute_path
def assert_exists(self): def assert_exists(self):
if not self.exists: if not self.exists:
raise NotExists(self) raise NotExists(self)
@ -191,8 +194,8 @@ class Path:
def correct_case(self): def correct_case(self):
if self._case_correct: if self._case_correct:
return self return self
self.absolute_path = get_path_casing(self.absolute_path) absolute_path = get_path_casing(self._absolute_path)
self.absolute_path = self.absolute_path.replace('/', self.sep).replace('\\', self.sep) self._absolute_path = normalize_sep(absolute_path, self.sep)
self._case_correct = True self._case_correct = True
return self return self