diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-10-03 20:32:33 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-10-03 20:32:33 (GMT) |
commit | 3b44e6114e3531a73944385a558e381d95e6ddf2 (patch) | |
tree | b4c34592a458ff3b44221ad5c87e7f78bed9c25e /Lib/ntpath.py | |
parent | 84e1715dd70552e0b2edbff9e1b45fa8f19e8ffa (diff) | |
download | cpython-3b44e6114e3531a73944385a558e381d95e6ddf2.zip cpython-3b44e6114e3531a73944385a558e381d95e6ddf2.tar.gz cpython-3b44e6114e3531a73944385a558e381d95e6ddf2.tar.bz2 |
Issue3187 again: test_ntpath failed when run with the -bb option
(BytesWarning: Comparison between bytes and string)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 79c3d4d..4b78d8d 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -331,17 +331,25 @@ def expandvars(path): return path import string varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii') + quote = b'\'' + percent = b'%' + brace = b'{' + dollar = b'$' else: if '$' not in path and '%' not in path: return path import string varchars = string.ascii_letters + string.digits + '_-' + quote = '\'' + percent = '%' + brace = '{' + dollar = '$' res = path[:0] index = 0 pathlen = len(path) while index < pathlen: c = path[index:index+1] - if c in ('\'', b'\''): # no expansion within single quotes + if c == quote: # no expansion within single quotes path = path[index + 1:] pathlen = len(path) try: @@ -350,11 +358,7 @@ def expandvars(path): except ValueError: res = res + path index = pathlen - 1 - elif c in ('%', b'%'): # variable or '%' - if isinstance(path, bytes): - percent = b'%' - else: - percent = '%' + elif c == percent: # variable or '%' if path[index + 1:index + 2] == percent: res = res + c index = index + 1 @@ -377,11 +381,11 @@ def expandvars(path): if isinstance(path, bytes): value = value.encode('ascii') res = res + value - elif c in ('$', b'$'): # variable or '$$' - if path[index + 1:index + 2] == '$': + elif c == dollar: # variable or '$$' + if path[index + 1:index + 2] == dollar: res = res + c index = index + 1 - elif path[index + 1:index + 2] in ('{', b'{'): + elif path[index + 1:index + 2] == brace: path = path[index+2:] pathlen = len(path) try: @@ -438,6 +442,7 @@ def expandvars(path): def normpath(path): """Normalize path, eliminating double slashes, etc.""" sep = _get_sep(path) + dotdot = _get_dot(path) * 2 path = path.replace(_get_altsep(path), sep) prefix, path = splitdrive(path) # We need to be careful here. If the prefix is empty, and the path starts @@ -462,21 +467,13 @@ def normpath(path): comps = path.split(sep) i = 0 while i < len(comps): - if comps[i] in ('.', '', b'.', b''): + if not comps[i] or comps[i] == _get_dot(path): del comps[i] - elif comps[i] == '..': - if i > 0 and comps[i-1] != '..': - del comps[i-1:i+1] - i -= 1 - elif i == 0 and prefix.endswith("\\"): - del comps[i] - else: - i += 1 - elif comps[i] == b'..': - if i > 0 and comps[i-1] != b'..': + elif comps[i] == dotdot: + if i > 0 and comps[i-1] != dotdot: del comps[i-1:i+1] i -= 1 - elif i == 0 and prefix.endswith(b"\\"): + elif i == 0 and prefix.endswith(_get_sep(path)): del comps[i] else: i += 1 |