]> granicus.if.org Git - python/commitdiff
Allow unicode pathnames where FSRefs are expected. Fixes 696253.
authorJack Jansen <jack.jansen@cwi.nl>
Tue, 11 Mar 2003 21:48:57 +0000 (21:48 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Tue, 11 Mar 2003 21:48:57 +0000 (21:48 +0000)
Lib/test/test_macfs.py
Mac/Modules/file/_Filemodule.c
Mac/Modules/file/filesupport.py

index c9ca06b836357c54c8bd94be4c2d22bc3c674608..d02d9e15d6fb868f9b9ab67c267688bf77fe59f8 100644 (file)
@@ -26,6 +26,11 @@ class TestMacfs(unittest.TestCase):
     def test_fsref(self):
         fsr = macfs.FSRef(test_support.TESTFN)
         self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname())
+        
+    def test_fsref_unicode(self):
+        testfn_unicode = unicode(test_support.TESTFN)
+        fsr = macfs.FSRef(testfn_unicode)
+        self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname())
 
     def test_coercion(self):
         fss = macfs.FSSpec(test_support.TESTFN)
index 89394372979f002691c4364008557ff36fa8012a..d61172e2b53f3dcf10eaef6ba9ba375669aeb4eb 100644 (file)
@@ -3222,8 +3222,11 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
 
 #if TARGET_API_MAC_OSX
        /* On OSX we now try a pathname */
-       if ( PyString_Check(v) ) {
-               if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
+       if ( PyString_Check(v) || PyUnicode_Check(v)) {
+               char *path = NULL;
+               if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
+                       return NULL;
+               if ( (err=FSPathMakeRef(path, fsr, NULL)) ) {
                        PyMac_Error(err);
                        return 0;
                }
index 9d6005cef6bb47f5bc08950921d576fe2dad0d1d..1237d2200efd54b5070b865fae8fbf8a908ffb1b 100644 (file)
@@ -280,8 +280,11 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
 
 #if TARGET_API_MAC_OSX
        /* On OSX we now try a pathname */
-       if ( PyString_Check(v) ) {
-               if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
+       if ( PyString_Check(v) || PyUnicode_Check(v)) {
+               char *path = NULL;
+               if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
+                       return NULL;
+               if ( (err=FSPathMakeRef(path, fsr, NULL)) ) {
                        PyMac_Error(err);
                        return 0;
                }