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:
|
if not filepath.is_file:
|
||||||
raise FileNotFoundError(filepath)
|
raise FileNotFoundError(filepath)
|
||||||
|
|
||||||
f = open(filepath.absolute_path, 'rb')
|
f = filepath.open('rb')
|
||||||
with f:
|
with f:
|
||||||
while True:
|
while True:
|
||||||
chunk = f.read(chunk_size)
|
chunk = f.read(chunk_size)
|
||||||
|
|
|
@ -104,7 +104,7 @@ def read_directories_file():
|
||||||
directories_file = pathclass.Path(__file__).parent.with_child('gitcheckup.txt')
|
directories_file = pathclass.Path(__file__).parent.with_child('gitcheckup.txt')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handle = open(directories_file.absolute_path, 'r', encoding='utf-8')
|
handle = directories_file.open('r', encoding='utf-8')
|
||||||
except FileNotFoundError as exc:
|
except FileNotFoundError as exc:
|
||||||
raise NoConfigFile(exc.filename) from 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')
|
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:
|
with handle:
|
||||||
handle.write('\n'.join(directories))
|
handle.write('\n'.join(directories))
|
||||||
|
|
|
@ -8,7 +8,7 @@ from voussoirkit import spinal
|
||||||
|
|
||||||
def hash_file(file):
|
def hash_file(file):
|
||||||
hasher = hashlib.md5()
|
hasher = hashlib.md5()
|
||||||
with open(file.absolute_path, 'rb') as handle:
|
with file.open('rb') as handle:
|
||||||
while True:
|
while True:
|
||||||
chunk = handle.read(2**20)
|
chunk = handle.read(2**20)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
|
|
|
@ -46,11 +46,11 @@ def all_terms_match(search_text, terms, match_function):
|
||||||
|
|
||||||
def search_contents_generic(filepath, content_args):
|
def search_contents_generic(filepath, content_args):
|
||||||
try:
|
try:
|
||||||
with open(filepath.absolute_path, 'r') as handle:
|
with filepath.open('r') as handle:
|
||||||
text = handle.read()
|
text = handle.read()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
try:
|
try:
|
||||||
with open(filepath.absolute_path, 'r', encoding='utf-8') as handle:
|
with filepath.open('r', encoding='utf-8') as handle:
|
||||||
text = handle.read()
|
text = handle.read()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
#safeprint.safeprint(filepath.absolute_path)
|
#safeprint.safeprint(filepath.absolute_path)
|
||||||
|
|
|
@ -21,7 +21,7 @@ def loop_once(extension):
|
||||||
path = pathclass.Path(passwordy.urandom_hex(12)).add_extension(extension)
|
path = pathclass.Path(passwordy.urandom_hex(12)).add_extension(extension)
|
||||||
pyperclip.copy('')
|
pyperclip.copy('')
|
||||||
print(path.basename, text)
|
print(path.basename, text)
|
||||||
h = open(path.absolute_path, 'w', encoding='utf-8')
|
h = path.open('w', encoding='utf-8')
|
||||||
h.write(text)
|
h.write(text)
|
||||||
h.close()
|
h.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue