diff -r cf70f030a744 Lib/macpath.py --- a/Lib/macpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/macpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -6,6 +6,14 @@ import genericpath from genericpath import * +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", "getatime","getctime", "islink","exists","lexists","isdir","isfile", @@ -186,7 +194,7 @@ def abspath(path): """Return an absolute path.""" if not isabs(path): - if isinstance(path, unicode): + if isinstance(path, _unicode): cwd = os.getcwdu() else: cwd = os.getcwd() diff -r cf70f030a744 Lib/ntpath.py --- a/Lib/ntpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/ntpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -13,6 +13,14 @@ from genericpath import * +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", "getatime","getctime", "islink","exists","lexists","isdir","isfile", @@ -294,7 +302,7 @@ return path import string varchars = string.ascii_letters + string.digits + '_-' - if isinstance(path, unicode): + if isinstance(path, _unicode): encoding = sys.getfilesystemencoding() def getenv(var): return os.environ[var.encode(encoding)].decode(encoding) @@ -377,7 +385,7 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" # Preserve unicode (if path is unicode) - backslash, dot = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.') + backslash, dot = (u'\\', u'.') if isinstance(path, _unicode) else ('\\', '.') if path.startswith(('\\\\.\\', '\\\\?\\')): # in the case of paths with these prefixes: # \\.\ -> device names @@ -434,7 +442,7 @@ def abspath(path): """Return the absolute version of a path.""" if not isabs(path): - if isinstance(path, unicode): + if isinstance(path, _unicode): cwd = os.getcwdu() else: cwd = os.getcwd() @@ -450,7 +458,7 @@ path = _getfullpathname(path) except WindowsError: pass # Bad path - return unchanged. - elif isinstance(path, unicode): + elif isinstance(path, _unicode): path = os.getcwdu() else: path = os.getcwd() diff -r cf70f030a744 Lib/os2emxpath.py --- a/Lib/os2emxpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/os2emxpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -11,6 +11,14 @@ from ntpath import (expanduser, expandvars, isabs, islink, splitdrive, splitext, split, walk) +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", "getatime","getctime", "islink","exists","lexists","isdir","isfile", @@ -146,7 +154,7 @@ def abspath(path): """Return the absolute version of a path""" if not isabs(path): - if isinstance(path, unicode): + if isinstance(path, _unicode): cwd = os.getcwdu() else: cwd = os.getcwd() diff -r cf70f030a744 Lib/posixpath.py --- a/Lib/posixpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/posixpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -294,16 +294,16 @@ if '$' not in path: return path if isinstance(path, _unicode): + if not _uvarprog: + import re + _uvarprog = re.compile(ur'\$(\w+|\{[^}]*\})', re.UNICODE) + varprog = _uvarprog + encoding = sys.getfilesystemencoding() + else: if not _varprog: import re _varprog = re.compile(r'\$(\w+|\{[^}]*\})') varprog = _varprog - encoding = sys.getfilesystemencoding() - else: - if not _uvarprog: - import re - _uvarprog = re.compile(_unicode(r'\$(\w+|\{[^}]*\})'), re.UNICODE) - varprog = _uvarprog encoding = None i = 0 while True: diff -r cf70f030a744 Lib/test/test_genericpath.py --- a/Lib/test/test_genericpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/test/test_genericpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -243,11 +243,13 @@ def test_realpath(self): self.assertIn("foo", self.pathmodule.realpath("foo")) + @test_support.requires_unicode def test_normpath_issue5827(self): # Make sure normpath preserves unicode for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'): self.assertIsInstance(self.pathmodule.normpath(path), unicode) + @test_support.requires_unicode def test_abspath_issue3426(self): # Check that abspath returns unicode when the arg is unicode # with both ASCII and non-ASCII cwds. diff -r cf70f030a744 Lib/test/test_macpath.py --- a/Lib/test/test_macpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/test/test_macpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -39,6 +39,7 @@ self.assertEqual(splitext(""), ('', '')) self.assertEqual(splitext("foo.bar.ext"), ('foo.bar', '.ext')) + @test_support.requires_unicode def test_normpath(self): # Issue 5827: Make sure normpath preserves unicode for path in (u'', u'.', u'/', u'\\', u':', u'///foo/.//bar//'): diff -r cf70f030a744 Lib/test/test_ntpath.py --- a/Lib/test/test_ntpath.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/test/test_ntpath.py Mon Jun 23 21:59:11 2014 +0300 @@ -52,8 +52,9 @@ ('', '\\\\conky\\\\mountpoint\\foo\\bar')) tester('ntpath.splitunc("//conky//mountpoint/foo/bar")', ('', '//conky//mountpoint/foo/bar')) - self.assertEqual(ntpath.splitunc(u'//conky/MOUNTPO\u0130NT/foo/bar'), - (u'//conky/MOUNTPO\u0130NT', u'/foo/bar')) + if test_support.have_unicode: + self.assertEqual(ntpath.splitunc(u'//conky/MOUNTPO%cNT/foo/bar' % 0x0130), + (u'//conky/MOUNTPO%cNT' % 0x0130, u'/foo/bar')) def test_split(self): tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))