diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-01-12 03:32:05 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-01-12 03:32:05 (GMT) |
commit | b5689de04425775932331b153feee7d9598755ad (patch) | |
tree | 15cbe6eeb2e7cbe83379c586ccf696583d617107 /Lib/ntpath.py | |
parent | 58a96efde53a52d501cdf6db810fedb1d86ecdb9 (diff) | |
download | cpython-b5689de04425775932331b153feee7d9598755ad.zip cpython-b5689de04425775932331b153feee7d9598755ad.tar.gz cpython-b5689de04425775932331b153feee7d9598755ad.tar.bz2 |
#5827: make sure that normpath preserves unicode
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 37f32f0..02d8584 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -397,6 +397,8 @@ def expandvars(path): def normpath(path): """Normalize path, eliminating double slashes, etc.""" + # Preserve unicode (if path is unicode) + backslash, dot = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.') path = path.replace("/", "\\") prefix, path = splitdrive(path) # We need to be careful here. If the prefix is empty, and the path starts @@ -411,12 +413,12 @@ def normpath(path): if prefix == '': # No drive letter - preserve initial backslashes while path[:1] == "\\": - prefix = prefix + "\\" + prefix = prefix + backslash path = path[1:] else: # We have a drive letter - collapse initial backslashes if path.startswith("\\"): - prefix = prefix + "\\" + prefix = prefix + backslash path = path.lstrip("\\") comps = path.split("\\") i = 0 @@ -435,8 +437,8 @@ def normpath(path): i += 1 # If the path is now empty, substitute '.' if not prefix and not comps: - comps.append('.') - return prefix + "\\".join(comps) + comps.append(dot) + return prefix + backslash.join(comps) # Return an absolute path. |