From 81d07612927c80f0c16b2aef9de2f78d4d24d892 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 20 Sep 2020 18:27:28 -0700 Subject: [PATCH] Use pathclass.Path.open. --- filetimelapse.py | 2 +- gitcheckup.py | 4 ++-- hash_hardlink.py | 2 +- search.py | 4 ++-- watchforlinks.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/filetimelapse.py b/filetimelapse.py index 2b66f25..96593d6 100644 --- a/filetimelapse.py +++ b/filetimelapse.py @@ -31,7 +31,7 @@ def read_filebytes(filepath, chunk_size=bytestring.MIBIBYTE): if not filepath.is_file: raise FileNotFoundError(filepath) - f = open(filepath.absolute_path, 'rb') + f = filepath.open('rb') with f: while True: chunk = f.read(chunk_size) diff --git a/gitcheckup.py b/gitcheckup.py index cff93cf..9042916 100644 --- a/gitcheckup.py +++ b/gitcheckup.py @@ -104,7 +104,7 @@ def read_directories_file(): directories_file = pathclass.Path(__file__).parent.with_child('gitcheckup.txt') try: - handle = open(directories_file.absolute_path, 'r', encoding='utf-8') + handle = directories_file.open('r', encoding='utf-8') except FileNotFoundError as exc: raise NoConfigFile(exc.filename) from exc @@ -128,7 +128,7 @@ def write_directories_file(directories): directories_file = pathclass.Path(__file__).parent.with_child('gitcheckup.txt') - handle = open(directories_file.absolute_path, 'w', encoding='utf-8') + handle = directories_file.open('w', encoding='utf-8') with handle: handle.write('\n'.join(directories)) diff --git a/hash_hardlink.py b/hash_hardlink.py index 55948b2..71b3095 100644 --- a/hash_hardlink.py +++ b/hash_hardlink.py @@ -8,7 +8,7 @@ from voussoirkit import spinal def hash_file(file): hasher = hashlib.md5() - with open(file.absolute_path, 'rb') as handle: + with file.open('rb') as handle: while True: chunk = handle.read(2**20) if not chunk: diff --git a/search.py b/search.py index bf47fb3..81ede87 100644 --- a/search.py +++ b/search.py @@ -46,11 +46,11 @@ def all_terms_match(search_text, terms, match_function): def search_contents_generic(filepath, content_args): try: - with open(filepath.absolute_path, 'r') as handle: + with filepath.open('r') as handle: text = handle.read() except UnicodeDecodeError: try: - with open(filepath.absolute_path, 'r', encoding='utf-8') as handle: + with filepath.open('r', encoding='utf-8') as handle: text = handle.read() except UnicodeDecodeError: #safeprint.safeprint(filepath.absolute_path) diff --git a/watchforlinks.py b/watchforlinks.py index 3f9c206..0baef27 100644 --- a/watchforlinks.py +++ b/watchforlinks.py @@ -21,7 +21,7 @@ def loop_once(extension): path = pathclass.Path(passwordy.urandom_hex(12)).add_extension(extension) pyperclip.copy('') print(path.basename, text) - h = open(path.absolute_path, 'w', encoding='utf-8') + h = path.open('w', encoding='utf-8') h.write(text) h.close()