Skip to content

Commit

Permalink
refactor: use Path instead of PurePath
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Oct 13, 2024
1 parent 66961cb commit b64b1b6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions py7zr/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def remove_trailing_slash(path: str) -> str:
return path


def canonical_path(target: pathlib.PurePath) -> pathlib.PurePath:
def canonical_path(target: pathlib.Path) -> pathlib.Path:
"""Return a canonical path of target argument."""
stack: list[str] = []
for p in target.parts:
Expand All @@ -442,10 +442,10 @@ def canonical_path(target: pathlib.PurePath) -> pathlib.PurePath:
pass # '/' + '../' -> '/'
else:
stack.pop() # 'foo/boo/' + '..' -> 'foo/'
return pathlib.PurePath(*stack)
return pathlib.Path(*stack)


def is_relative_to(my: pathlib.PurePath, *other) -> bool:
def is_relative_to(my: pathlib.Path, *other) -> bool:
"""Return True when path is relative to other path, otherwise False."""
try:
my.relative_to(canonical_path(*other))
Expand Down Expand Up @@ -480,7 +480,7 @@ def check_archive_path(arcname: str) -> bool:
It should not be evil traversal attack path.
Otherwise, returns True.
"""
if pathlib.PurePath(arcname).is_absolute():
if pathlib.Path(arcname).is_absolute():
return False
# test against dummy parent path
if sys.platform == "win32":
Expand Down

0 comments on commit b64b1b6

Please sign in to comment.