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.
This commit is contained in:
parent
4b8ae01786
commit
d34103917f
1 changed files with 17 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue