Kaydet (Commit) dded8480 authored tarafından Jack Jansen's avatar Jack Jansen

Allow unicode pathnames where FSRefs are expected. Fixes 696253.

üst d65ec37f
......@@ -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)
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment