[Python-checkins] r78248 - in python/branches/release26-maint: 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

ezio.melotti python-checkins at python.org
Sat Feb 20 10:16:05 CET 2010


Author: ezio.melotti
Date: Sat Feb 20 10:16:04 2010
New Revision: 78248

Log:
Merged revisions 78247 via svnmerge from 
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.
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/macpath.py
   python/branches/release26-maint/Lib/ntpath.py
   python/branches/release26-maint/Lib/os2emxpath.py
   python/branches/release26-maint/Lib/posixpath.py
   python/branches/release26-maint/Lib/test/test_macpath.py
   python/branches/release26-maint/Lib/test/test_ntpath.py
   python/branches/release26-maint/Lib/test/test_posixpath.py
   python/branches/release26-maint/Misc/NEWS

Modified: python/branches/release26-maint/Lib/macpath.py
==============================================================================
--- python/branches/release26-maint/Lib/macpath.py	(original)
+++ python/branches/release26-maint/Lib/macpath.py	Sat Feb 20 10:16:04 2010
@@ -186,7 +186,11 @@
 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

Modified: python/branches/release26-maint/Lib/ntpath.py
==============================================================================
--- python/branches/release26-maint/Lib/ntpath.py	(original)
+++ python/branches/release26-maint/Lib/ntpath.py	Sat Feb 20 10:16:04 2010
@@ -449,7 +449,11 @@
     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 @@
                 path = _getfullpathname(path)
             except WindowsError:
                 pass # Bad path - return unchanged.
+        elif isinstance(path, unicode):
+            path = os.getcwdu()
         else:
             path = os.getcwd()
         return normpath(path)

Modified: python/branches/release26-maint/Lib/os2emxpath.py
==============================================================================
--- python/branches/release26-maint/Lib/os2emxpath.py	(original)
+++ python/branches/release26-maint/Lib/os2emxpath.py	Sat Feb 20 10:16:04 2010
@@ -146,7 +146,11 @@
 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

Modified: python/branches/release26-maint/Lib/posixpath.py
==============================================================================
--- python/branches/release26-maint/Lib/posixpath.py	(original)
+++ python/branches/release26-maint/Lib/posixpath.py	Sat Feb 20 10:16:04 2010
@@ -337,7 +337,11 @@
 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)
 
 

Modified: python/branches/release26-maint/Lib/test/test_macpath.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_macpath.py	(original)
+++ python/branches/release26-maint/Lib/test/test_macpath.py	Sat Feb 20 10:16:04 2010
@@ -1,3 +1,4 @@
+import os
 import macpath
 from test import test_support
 import unittest
@@ -8,6 +9,22 @@
     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"))

Modified: python/branches/release26-maint/Lib/test/test_ntpath.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_ntpath.py	(original)
+++ python/branches/release26-maint/Lib/test/test_ntpath.py	Sat Feb 20 10:16:04 2010
@@ -164,13 +164,32 @@
         # 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')

Modified: python/branches/release26-maint/Lib/test/test_posixpath.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_posixpath.py	(original)
+++ python/branches/release26-maint/Lib/test/test_posixpath.py	Sat Feb 20 10:16:04 2010
@@ -390,6 +390,21 @@
     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):

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Sat Feb 20 10:16:04 2010
@@ -66,6 +66,8 @@
 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.
 


More information about the Python-checkins mailing list