From 6434fdf2f74a41371f52514b6cf0b5b587553411 Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Fri, 10 Jun 2022 18:05:15 -0700 Subject: [PATCH] Update safe_path function signature Signed-off-by: Jono Yang --- src/commoncode/paths.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/commoncode/paths.py b/src/commoncode/paths.py index 6f1602c..ef1c667 100644 --- a/src/commoncode/paths.py +++ b/src/commoncode/paths.py @@ -26,7 +26,7 @@ # Build OS-portable and safer paths -def safe_path(path, posix=False, preserve_spaces=False): +def safe_path(path, posix=False, preserve_spaces=False, posix_only=False): """ Convert `path` to a safe and portable POSIX path usable on multiple OSes. The returned path is an ASCII-only byte string, resolved for relative @@ -52,7 +52,13 @@ def safe_path(path, posix=False, preserve_spaces=False): _pathmod, path_sep = path_handlers(path, posix) segments = [s.strip() for s in path.split(path_sep) if s.strip()] - segments = [portable_filename(s, preserve_spaces=preserve_spaces) for s in segments] + segments = [ + portable_filename( + s, + preserve_spaces=preserve_spaces, + posix_only=posix_only + ) for s in segments + ] if not segments: return '_'