Index: Lib/posixpath.py =================================================================== --- Lib/posixpath.py (revision 71823) +++ Lib/posixpath.py (working copy) @@ -306,8 +306,10 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" + # Preserve unicode (if path is unicode) + slash, dot = (u'/', u'.') if isinstance(path, unicode) else ('/', '.') if path == '': - return '.' + return dot initial_slashes = path.startswith('/') # POSIX allows one or two initial slashes, but treats three or more # as single slash. @@ -325,10 +327,10 @@ elif new_comps: new_comps.pop() comps = new_comps - path = '/'.join(comps) + path = slash.join(comps) if initial_slashes: - path = '/'*initial_slashes + path - return path or '.' + path = slash*initial_slashes + path + return path or dot def abspath(path): Index: Lib/ntpath.py =================================================================== --- Lib/ntpath.py (revision 71823) +++ Lib/ntpath.py (working copy) @@ -396,6 +396,8 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" + # Preserve unicode (if path is unicode) + slash, 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 @@ -410,12 +412,12 @@ if prefix == '': # No drive letter - preserve initial backslashes while path[:1] == "\\": - prefix = prefix + "\\" + prefix = prefix + slash path = path[1:] else: # We have a drive letter - collapse initial backslashes if path.startswith("\\"): - prefix = prefix + "\\" + prefix = prefix + slash path = path.lstrip("\\") comps = path.split("\\") i = 0 @@ -434,8 +436,8 @@ 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 + slash.join(comps) # Return an absolute path. Index: Lib/test/test_ntpath.py =================================================================== --- Lib/test/test_ntpath.py (revision 71823) +++ Lib/test/test_ntpath.py (working copy) @@ -123,6 +123,11 @@ tester("ntpath.normpath('C:////a/b')", r'C:\a\b') tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b') + # Make sure normpath preserves unicode + self.assertEqual(type(ntpath.normpath(u"")), unicode) + self.assertEqual(type(ntpath.normpath(u"/")), unicode) + self.assertEqual(type(ntpath.normpath(u"///foo/.//bar//")), unicode) + def test_expandvars(self): oldenv = os.environ.copy() try: Index: Lib/test/test_posixpath.py =================================================================== --- Lib/test/test_posixpath.py (revision 71823) +++ Lib/test/test_posixpath.py (working copy) @@ -386,6 +386,11 @@ self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), "/foo/baz") self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar") + # Make sure normpath preserves unicode + self.assertEqual(type(posixpath.normpath(u"")), unicode) + self.assertEqual(type(posixpath.normpath(u"/")), unicode) + self.assertEqual(type(posixpath.normpath(u"///foo/.//bar//")), unicode) + self.assertRaises(TypeError, posixpath.normpath) def test_abspath(self):