From e2fd04ccf100e47384dd1c2468451937c2b1e126 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 2 Dec 2021 19:32:08 -0800 Subject: [PATCH] Remove .absolute_path thanks to fspath. --- voussoirkit/downloady.py | 4 ++-- voussoirkit/pathclass.py | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/voussoirkit/downloady.py b/voussoirkit/downloady.py index 29f877c..5b28764 100644 --- a/voussoirkit/downloady.py +++ b/voussoirkit/downloady.py @@ -152,7 +152,7 @@ def download_plan(plan): raise NotEnoughBytes(message) if plan.download_into != plan.real_localname: - os.rename(plan.download_into.absolute_path, plan.real_localname.absolute_path) + os.rename(plan.download_into, plan.real_localname) return plan.real_localname @@ -285,7 +285,7 @@ def prepare_plan( # Chapter 6: Redeem your meal vouchers here if real_exists: if overwrite: - os.remove(real_localname.absolute_path) + os.remove(real_localname) if user_provided_range: return plan_partial diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 82933c4..6135375 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -270,7 +270,7 @@ class Path: @property def exists(self): - return os.path.exists(self.absolute_path) + return os.path.exists(self) @property def extension(self): @@ -318,7 +318,7 @@ class Path: @property def is_directory(self): - return os.path.isdir(self.absolute_path) + return os.path.isdir(self) # Aliases for your convenience. is_dir = is_directory @@ -326,11 +326,11 @@ class Path: @property def is_file(self): - return os.path.isfile(self.absolute_path) + return os.path.isfile(self) @property def is_link(self): - return os.path.islink(self.absolute_path) + return os.path.islink(self) def join(self, subpath, **spawn_kwargs): ''' @@ -342,7 +342,7 @@ class Path: return Path(path, **spawn_kwargs) def listdir(self): - children = os.listdir(self.absolute_path) + children = os.listdir(self) children = [self.with_child(child, _case_correct=self._case_correct) for child in children] return children @@ -353,14 +353,14 @@ class Path: return [p for p in self.listdir() if p.is_file] def makedirs(self, mode=0o777, exist_ok=False): - return os.makedirs(self.absolute_path, mode=mode, exist_ok=exist_ok) + return os.makedirs(self, mode=mode, exist_ok=exist_ok) @property def normcase(self): return os.path.normcase(self.absolute_path) def open(self, *args, **kwargs): - return open(self.absolute_path, *args, **kwargs) + return open(self, *args, **kwargs) @property def parent(self): @@ -431,20 +431,20 @@ class Path: def size(self): self.assert_exists() if self.is_file: - return os.path.getsize(self.absolute_path) + return os.path.getsize(self) elif self.is_dir: return sum(file.size for file in self.walk() if file.is_file) @property def stat(self): - return os.stat(self.absolute_path) + return os.stat(self) def touch(self): ''' Update the file's mtime if it exists, or create it. ''' try: - os.utime(self.absolute_path) + os.utime(self) except FileNotFoundError: self.open('a').close() @@ -454,8 +454,7 @@ class Path: ''' directories = [] - entries = os.scandir(self.absolute_path) - for entry in entries: + for entry in os.scandir(self): child = self.with_child(entry.name, _case_correct=self._case_correct) if entry.is_dir(): directories.append(child)