]> granicus.if.org Git - python/commitdiff
Merged revisions 78247 via svnmerge from
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 20 Feb 2010 09:16:04 +0000 (09:16 +0000)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 20 Feb 2010 09:16:04 +0000 (09:16 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78247 | ezio.melotti | 2010-02-20 10:09:39 +0200 (Sat, 20 Feb 2010) | 1 line

  #3426: os.path.abspath now returns unicode when its arg is unicode.
........

Lib/macpath.py
Lib/ntpath.py
Lib/os2emxpath.py
Lib/posixpath.py
Lib/test/test_macpath.py
Lib/test/test_ntpath.py
Lib/test/test_posixpath.py
Misc/NEWS

index 14e49a312e66054bd5f055969793b0c352f2ca92..15714c6c2cd55ed9d68cd6dca80a8c736db22430 100644 (file)
@@ -186,7 +186,11 @@ def walk(top, func, arg):
 def abspath(path):
     """Return an absolute path."""
     if not isabs(path):
-        path = join(os.getcwd(), path)
+        if isinstance(path, unicode):
+            cwd = os.getcwdu()
+        else:
+            cwd = os.getcwd()
+        path = join(cwd, path)
     return normpath(path)
 
 # realpath is a no-op on systems without islink support
index 02d8584736dea686276e668f66432c35bfecab87..a124dfd0c4343344740248102b023919528ef035 100644 (file)
@@ -449,7 +449,11 @@ except ImportError: # not running on Windows - mock up something sensible
     def abspath(path):
         """Return the absolute version of a path."""
         if not isabs(path):
-            path = join(os.getcwd(), path)
+            if isinstance(path, unicode):
+                cwd = os.getcwdu()
+            else:
+                cwd = os.getcwd()
+            path = join(cwd, path)
         return normpath(path)
 
 else:  # use native Windows method on Windows
@@ -461,6 +465,8 @@ else:  # use native Windows method on Windows
                 path = _getfullpathname(path)
             except WindowsError:
                 pass # Bad path - return unchanged.
+        elif isinstance(path, unicode):
+            path = os.getcwdu()
         else:
             path = os.getcwd()
         return normpath(path)
index 4e85c4d48dfc6b79e87dcddae08f61f2f9d0a075..1bed51d4fabbce40cefbba6e66f7add74a9d401c 100644 (file)
@@ -146,7 +146,11 @@ def normpath(path):
 def abspath(path):
     """Return the absolute version of a path"""
     if not isabs(path):
-        path = join(os.getcwd(), path)
+        if isinstance(path, unicode):
+            cwd = os.getcwdu()
+        else:
+            cwd = os.getcwd()
+        path = join(cwd, path)
     return normpath(path)
 
 # realpath is a no-op on systems without islink support
index 35dcffbe88b6d6e68ac2a9b0b70c0f6033e7a9cf..44519d4c1c76d5fb5939e26a4ee4ac9621376dca 100644 (file)
@@ -337,7 +337,11 @@ def normpath(path):
 def abspath(path):
     """Return an absolute path."""
     if not isabs(path):
-        path = join(os.getcwd(), path)
+        if isinstance(path, unicode):
+            cwd = os.getcwdu()
+        else:
+            cwd = os.getcwd()
+        path = join(cwd, path)
     return normpath(path)
 
 
index 2449b0a1fb0909de4fa4589dee6bb929c3e788b9..81374d1a3f2e11e272a45320713e2b54bdf38992 100644 (file)
@@ -1,3 +1,4 @@
+import os
 import macpath
 from test import test_support
 import unittest
@@ -8,6 +9,22 @@ class MacPathTestCase(unittest.TestCase):
     def test_abspath(self):
         self.assert_(macpath.abspath("xx:yy") == "xx:yy")
 
+        # Issue 3426: check that abspath retuns unicode when the arg is unicode
+        # and str when it's str, with both ASCII and non-ASCII cwds
+        saved_cwd = os.getcwd()
+        for cwd in (u'cwd', u'\xe7w\xf0'):
+            try:
+                os.mkdir(cwd)
+                os.chdir(cwd)
+                for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
+                    self.assertTrue(isinstance(macpath.abspath(path), str))
+                for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
+                    self.assertTrue(isinstance(macpath.abspath(upath), unicode))
+            finally:
+                os.chdir(saved_cwd)
+                os.rmdir(cwd)
+
+
     def test_isabs(self):
         isabs = macpath.isabs
         self.assert_(isabs("xx:yy"))
index 10bbe3a3a2634836fb8f5197c76403e91ea1b255..89b3f614af8704031a53eaabe75ae98635188891 100644 (file)
@@ -164,13 +164,32 @@ class TestNtpath(unittest.TestCase):
         # the rest of the tests for the ntpath module to be run to completion
         # on any platform, since most of the module is intended to be usable
         # from any platform.
+        # XXX this needs more tests
         try:
             import nt
         except ImportError:
-            pass
+            # check that the function is there even if we are not on Windows
+            ntpath.abspath
         else:
             tester('ntpath.abspath("C:\\")', "C:\\")
 
+            # Issue 3426: check that abspath retuns unicode when the arg is
+            # unicode and str when it's str, with both ASCII and non-ASCII cwds
+            saved_cwd = os.getcwd()
+            for cwd in (u'cwd', u'\xe7w\xf0'):
+                try:
+                    os.mkdir(cwd)
+                    os.chdir(cwd)
+                    for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
+                        self.assertTrue(isinstance(ntpath.abspath(path), str))
+                    for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
+                        self.assertTrue(isinstance(ntpath.abspath(upath),
+                                                   unicode))
+                finally:
+                    os.chdir(saved_cwd)
+                    os.rmdir(cwd)
+
+
     def test_relpath(self):
         currentdir = os.path.split(os.getcwd())[-1]
         tester('ntpath.relpath("a")', 'a')
index c2f3a4a47bb0d838ca99af5cfb9a5821b7632975..ef3429f2ad2e3f6b722894d07f6d57df12891fcb 100644 (file)
@@ -390,6 +390,21 @@ class PosixPathTest(unittest.TestCase):
     def test_abspath(self):
         self.assert_("foo" in posixpath.abspath("foo"))
 
+        # Issue 3426: check that abspath retuns unicode when the arg is unicode
+        # and str when it's str, with both ASCII and non-ASCII cwds
+        saved_cwd = os.getcwd()
+        for cwd in (u'cwd', u'\xe7w\xf0'):
+            try:
+                os.mkdir(cwd)
+                os.chdir(cwd)
+                for path in ('', 'foo', 'f\xf2\xf2', '/foo', 'C:\\'):
+                    self.assertTrue(isinstance(posixpath.abspath(path), str))
+                for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
+                    self.assertTrue(isinstance(posixpath.abspath(upath), unicode))
+            finally:
+                os.chdir(saved_cwd)
+                os.rmdir(cwd)
+
         self.assertRaises(TypeError, posixpath.abspath)
 
     def test_realpath(self):
index 9c9c387c0217ab7ffe01dbae005ddbba96d0bc83..3baf44976e644e044380a97a716546061574ae6d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #3426: ``os.path.abspath`` now returns unicode when its arg is unicode.
+
 - Issue #7835: shelve should no longer produce mysterious warnings during
   interpreter shutdown.