Re-add the normalize_sep function, but more conservative.

Formerly I was normalizing backslash to forwardslash on unix, which is
bad. Then I removed the function because I thought normpath was the
right tool for the job. Now I'm finding a few situations I just want to
norm the sep again.
master
voussoir 2022-01-09 16:59:09 -08:00
parent 4b8ae01786
commit d34103917f
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 17 additions and 0 deletions

View File

@ -686,5 +686,22 @@ def normalize_pathpart(name):
return name return name
return PathPart(name) return PathPart(name)
def normalize_sep(path) -> str:
'''
Normalize path separators as appropriate for the operating system.
On Windows, forward slash / is replaced with backslash \\.
Note: os.path.normpath also performs separator normalization, but it also
eliminates leading ./ which you may want to keep in your string.
'''
if os.name == 'nt':
path = path.replace('/', '\\')
# On unix, backslashes are valid filename characters so we do not normalize
# them to forward slash.
return path
def system_root(): def system_root():
return Path(os.sep) return Path(os.sep)