Replace several uses of str(path) with fspath(path)
Helps make it more explicit. Did not do this to tests because use of paths is more involved there.
This commit is contained in:
@@ -29,8 +29,8 @@ def re_symlink(input_file, soft_link_name, log=None):
|
||||
"""
|
||||
Helper function: relinks soft symbolic link if necessary
|
||||
"""
|
||||
input_file = str(input_file) # For Py3.5
|
||||
soft_link_name = str(soft_link_name)
|
||||
input_file = fspath(input_file) # For Py3.5
|
||||
soft_link_name = fspath(soft_link_name)
|
||||
if log is None:
|
||||
prdebug = partial(print, file=sys.stderr)
|
||||
else:
|
||||
@@ -108,14 +108,14 @@ def is_file_writable(test_file):
|
||||
# defaults to strict=False. This implements strict=False like behavior
|
||||
# for Python 3.5.
|
||||
if sys.version_info[0:2] <= (3, 5):
|
||||
p = Path(os.path.realpath(str(p)))
|
||||
p = Path(os.path.realpath(fspath(p)))
|
||||
else:
|
||||
p = p.resolve(strict=False)
|
||||
|
||||
# p.is_file() throws an exception in some cases
|
||||
if p.exists() and p.is_file():
|
||||
return os.access(
|
||||
str(p), os.W_OK,
|
||||
fspath(p), os.W_OK,
|
||||
effective_ids=(os.access in os.supports_effective_ids))
|
||||
else:
|
||||
try:
|
||||
|
||||
@@ -39,7 +39,7 @@ PNG_QUALITY = (65, 75)
|
||||
|
||||
|
||||
def img_name(root, xref, ext):
|
||||
return str(root / '{:08d}{}'.format(xref, ext))
|
||||
return fspath(root / '{:08d}{}'.format(xref, ext))
|
||||
|
||||
|
||||
def png_name(root, xref):
|
||||
@@ -193,7 +193,7 @@ def convert_to_jbig2(pike, jbig2_groups, root, log, options):
|
||||
prefix = 'group{:08d}'.format(group)
|
||||
future = executor.submit(
|
||||
jbig2enc.convert_group,
|
||||
cwd=str(root),
|
||||
cwd=fspath(root),
|
||||
infiles=(img_name(root, xref, ext) for xref, ext in xref_exts),
|
||||
out_prefix=prefix
|
||||
)
|
||||
@@ -229,8 +229,8 @@ def transcode_jpegs(pike, jpegs, root, log, options):
|
||||
# DEBUG:PIL.Image:Error closing: 'NoneType' object has no attribute
|
||||
# 'close'. Seems to be mostly harmless
|
||||
# https://github.com/python-pillow/Pillow/issues/1144
|
||||
with Image.open(str(in_jpg)) as im:
|
||||
im.save(str(opt_jpg),
|
||||
with Image.open(fspath(in_jpg)) as im:
|
||||
im.save(fspath(opt_jpg),
|
||||
optimize=True,
|
||||
quality=JPEG_QUALITY)
|
||||
if opt_jpg.stat().st_size > in_jpg.stat().st_size:
|
||||
|
||||
@@ -575,7 +575,7 @@ def _pdf_get_pageinfo(pdf, pageno: int, infile):
|
||||
|
||||
page = pdf.pages[pageno]
|
||||
|
||||
pageinfo['textinfo'] = _page_get_textblocks(str(infile), pageno)
|
||||
pageinfo['textinfo'] = _page_get_textblocks(fspath(infile), pageno)
|
||||
|
||||
mediabox = [Decimal(d) for d in page.MediaBox.as_list()]
|
||||
width_pt = mediabox[2] - mediabox[0]
|
||||
|
||||
Reference in New Issue
Block a user