Use pathclass.Path.open.
This commit is contained in:
parent
58e5097639
commit
81d0761292
5 changed files with 7 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue