From dded84802a0782960ba52a5d55b885fc9cc23a44 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Tue, 11 Mar 2003 21:48:57 +0000 Subject: Allow unicode pathnames where FSRefs are expected. Fixes 696253. --- Lib/test/test_macfs.py | 5 +++++ Mac/Modules/file/_Filemodule.c | 7 +++++-- Mac/Modules/file/filesupport.py | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_macfs.py b/Lib/test/test_macfs.py index c9ca06b..d02d9e1 100644 --- a/Lib/test/test_macfs.py +++ b/Lib/test/test_macfs.py @@ -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) diff --git a/Mac/Modules/file/_Filemodule.c b/Mac/Modules/file/_Filemodule.c index 8939437..d61172e 100644 --- a/Mac/Modules/file/_Filemodule.c +++ b/Mac/Modules/file/_Filemodule.c @@ -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; } diff --git a/Mac/Modules/file/filesupport.py b/Mac/Modules/file/filesupport.py index 9d6005c..1237d22 100644 --- a/Mac/Modules/file/filesupport.py +++ b/Mac/Modules/file/filesupport.py @@ -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; } -- cgit v0.12