mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue3187 again: test_ntpath failed when run with the -bb option
(BytesWarning: Comparison between bytes and string)
This commit is contained in:
parent
84e1715dd7
commit
3b44e6114e
1 changed files with 18 additions and 21 deletions
|
@ -331,17 +331,25 @@ def expandvars(path):
|
||||||
return path
|
return path
|
||||||
import string
|
import string
|
||||||
varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii')
|
varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii')
|
||||||
|
quote = b'\''
|
||||||
|
percent = b'%'
|
||||||
|
brace = b'{'
|
||||||
|
dollar = b'$'
|
||||||
else:
|
else:
|
||||||
if '$' not in path and '%' not in path:
|
if '$' not in path and '%' not in path:
|
||||||
return path
|
return path
|
||||||
import string
|
import string
|
||||||
varchars = string.ascii_letters + string.digits + '_-'
|
varchars = string.ascii_letters + string.digits + '_-'
|
||||||
|
quote = '\''
|
||||||
|
percent = '%'
|
||||||
|
brace = '{'
|
||||||
|
dollar = '$'
|
||||||
res = path[:0]
|
res = path[:0]
|
||||||
index = 0
|
index = 0
|
||||||
pathlen = len(path)
|
pathlen = len(path)
|
||||||
while index < pathlen:
|
while index < pathlen:
|
||||||
c = path[index:index+1]
|
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:]
|
path = path[index + 1:]
|
||||||
pathlen = len(path)
|
pathlen = len(path)
|
||||||
try:
|
try:
|
||||||
|
@ -350,11 +358,7 @@ def expandvars(path):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
res = res + path
|
res = res + path
|
||||||
index = pathlen - 1
|
index = pathlen - 1
|
||||||
elif c in ('%', b'%'): # variable or '%'
|
elif c == percent: # variable or '%'
|
||||||
if isinstance(path, bytes):
|
|
||||||
percent = b'%'
|
|
||||||
else:
|
|
||||||
percent = '%'
|
|
||||||
if path[index + 1:index + 2] == percent:
|
if path[index + 1:index + 2] == percent:
|
||||||
res = res + c
|
res = res + c
|
||||||
index = index + 1
|
index = index + 1
|
||||||
|
@ -377,11 +381,11 @@ def expandvars(path):
|
||||||
if isinstance(path, bytes):
|
if isinstance(path, bytes):
|
||||||
value = value.encode('ascii')
|
value = value.encode('ascii')
|
||||||
res = res + value
|
res = res + value
|
||||||
elif c in ('$', b'$'): # variable or '$$'
|
elif c == dollar: # variable or '$$'
|
||||||
if path[index + 1:index + 2] == '$':
|
if path[index + 1:index + 2] == dollar:
|
||||||
res = res + c
|
res = res + c
|
||||||
index = index + 1
|
index = index + 1
|
||||||
elif path[index + 1:index + 2] in ('{', b'{'):
|
elif path[index + 1:index + 2] == brace:
|
||||||
path = path[index+2:]
|
path = path[index+2:]
|
||||||
pathlen = len(path)
|
pathlen = len(path)
|
||||||
try:
|
try:
|
||||||
|
@ -438,6 +442,7 @@ def expandvars(path):
|
||||||
def normpath(path):
|
def normpath(path):
|
||||||
"""Normalize path, eliminating double slashes, etc."""
|
"""Normalize path, eliminating double slashes, etc."""
|
||||||
sep = _get_sep(path)
|
sep = _get_sep(path)
|
||||||
|
dotdot = _get_dot(path) * 2
|
||||||
path = path.replace(_get_altsep(path), sep)
|
path = path.replace(_get_altsep(path), sep)
|
||||||
prefix, path = splitdrive(path)
|
prefix, path = splitdrive(path)
|
||||||
# We need to be careful here. If the prefix is empty, and the path starts
|
# 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)
|
comps = path.split(sep)
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(comps):
|
while i < len(comps):
|
||||||
if comps[i] in ('.', '', b'.', b''):
|
if not comps[i] or comps[i] == _get_dot(path):
|
||||||
del comps[i]
|
del comps[i]
|
||||||
elif comps[i] == '..':
|
elif comps[i] == dotdot:
|
||||||
if i > 0 and comps[i-1] != '..':
|
if i > 0 and comps[i-1] != dotdot:
|
||||||
del comps[i-1:i+1]
|
del comps[i-1:i+1]
|
||||||
i -= 1
|
i -= 1
|
||||||
elif i == 0 and prefix.endswith("\\"):
|
elif i == 0 and prefix.endswith(_get_sep(path)):
|
||||||
del comps[i]
|
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
elif comps[i] == b'..':
|
|
||||||
if i > 0 and comps[i-1] != b'..':
|
|
||||||
del comps[i-1:i+1]
|
|
||||||
i -= 1
|
|
||||||
elif i == 0 and prefix.endswith(b"\\"):
|
|
||||||
del comps[i]
|
del comps[i]
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue