Discussion:
[Python-3000-checkins] r66779 - python/branches/py3k/Lib/ntpath.py
amaury.forgeotdarc
2008-10-04 07:33:35 UTC
Permalink
Author: amaury.forgeotdarc
Date: Fri Oct 3 22:32:33 2008
New Revision: 66779

Log:
Issue3187 again: test_ntpath failed when run with the -bb option
(BytesWarning: Comparison between bytes and string)


Modified:
python/branches/py3k/Lib/ntpath.py

Modified: python/branches/py3k/Lib/ntpath.py
==============================================================================
--- python/branches/py3k/Lib/ntpath.py (original)
+++ python/branches/py3k/Lib/ntpath.py Fri Oct 3 22:32:33 2008
@@ -331,17 +331,25 @@
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 @@
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 @@
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 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 @@
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

Loading...