]> granicus.if.org Git - python/commitdiff
FSRef and EasyDialogs pathname support was pretty much broken in MacPython-OS9. Fixed.
authorJack Jansen <jack.jansen@cwi.nl>
Sun, 26 Jan 2003 20:22:41 +0000 (20:22 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Sun, 26 Jan 2003 20:22:41 +0000 (20:22 +0000)
Lib/plat-mac/EasyDialogs.py
Mac/Modules/file/_Filemodule.c
Mac/Modules/file/filesupport.py

index 1d670919846d75b7b8f3baf93e54e72d679c5a6f..83daff8e70b60bd29ca6b87810fc1da7be050522 100644 (file)
@@ -34,6 +34,7 @@ from Carbon.ControlAccessor import *  # Also import Controls constants
 import Carbon.File
 import macresource
 import os
+import sys
 
 __all__ = ['Message', 'AskString', 'AskPassword', 'AskYesNoCancel',
        'GetArgv', 'AskFileForOpen', 'AskFileForSave', 'AskFolder',
@@ -635,9 +636,9 @@ def AskFileForOpen(
        if issubclass(tpwanted, Carbon.File.FSSpec):
                return tpwanted(rr.selection[0])
        if issubclass(tpwanted, str):
-               return tpwanted(rr.selection_fsr[0].FSRefMakePath())
+               return tpwanted(rr.selection_fsr[0].as_pathname())
        if issubclass(tpwanted, unicode):
-               return tpwanted(rr.selection_fsr[0].FSRefMakePath(), 'utf8')
+               return tpwanted(rr.selection_fsr[0].as_pathname(), 'utf8')
        raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)
 
 def AskFileForSave(
@@ -686,13 +687,16 @@ def AskFileForSave(
        if issubclass(tpwanted, Carbon.File.FSSpec):
                return tpwanted(rr.selection[0])
        if issubclass(tpwanted, (str, unicode)):
-               # This is gross, and probably incorrect too
-               vrefnum, dirid, name = rr.selection[0].as_tuple()
-               pardir_fss = Carbon.File.FSSpec((vrefnum, dirid, ''))
-               pardir_fsr = Carbon.File.FSRef(pardir_fss)
-               pardir_path = pardir_fsr.FSRefMakePath()  # This is utf-8
-               name_utf8 = unicode(name, 'macroman').encode('utf8')
-               fullpath = os.path.join(pardir_path, name_utf8)
+               if sys.platform == 'mac':
+                       fullpath = rr.selection[0].as_pathname()
+               else:
+                       # This is gross, and probably incorrect too
+                       vrefnum, dirid, name = rr.selection[0].as_tuple()
+                       pardir_fss = Carbon.File.FSSpec((vrefnum, dirid, ''))
+                       pardir_fsr = Carbon.File.FSRef(pardir_fss)
+                       pardir_path = pardir_fsr.FSRefMakePath()  # This is utf-8
+                       name_utf8 = unicode(name, 'macroman').encode('utf8')
+                       fullpath = os.path.join(pardir_path, name_utf8)
                if issubclass(tpwanted, unicode):
                        return unicode(fullpath, 'utf8')
                return tpwanted(fullpath)
@@ -741,14 +745,14 @@ def AskFolder(
        if issubclass(tpwanted, Carbon.File.FSSpec):
                return tpwanted(rr.selection[0])
        if issubclass(tpwanted, str):
-               return tpwanted(rr.selection_fsr[0].FSRefMakePath())
+               return tpwanted(rr.selection_fsr[0].as_pathname())
        if issubclass(tpwanted, unicode):
-               return tpwanted(rr.selection_fsr[0].FSRefMakePath(), 'utf8')
+               return tpwanted(rr.selection_fsr[0].as_pathname(), 'utf8')
        raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)
        
 
 def test():
-       import time, sys, macfs
+       import time, macfs
 
        Message("Testing EasyDialogs.")
        optionlist = (('v', 'Verbose'), ('verbose', 'Verbose as long option'), 
index 5d3901fbe73496ebe2442d2f188c69243f089ac2..8309b35a6244b5278c56cad959a91de857dbb8f8 100644 (file)
@@ -1840,7 +1840,26 @@ static PyObject *FSRef_as_pathname(FSRefObject *_self, PyObject *_args)
 {
        PyObject *_res = NULL;
 
+#if TARGET_API_MAC_OSX
+       if (!PyArg_ParseTuple(_args, ""))
+               return NULL;
        _res = FSRef_FSRefMakePath(_self, _args);
+#else
+       char strbuf[1024];
+       OSErr err;
+       FSSpec fss;
+
+       if (!PyArg_ParseTuple(_args, ""))
+               return NULL;
+       if ( !PyMac_GetFSSpec((PyObject *)_self, &fss))
+               return NULL;
+       err = PyMac_GetFullPathname(&fss, strbuf, sizeof(strbuf));
+       if ( err ) {
+               PyMac_Error(err);
+               return NULL;
+       }
+       _res = PyString_FromString(strbuf);
+#endif
        return _res;
 
 }
@@ -3190,6 +3209,7 @@ int
 PyMac_GetFSRef(PyObject *v, FSRef *fsr)
 {
        OSStatus err;
+       FSSpec fss;
        
        if (FSRef_Check(v)) {
                *fsr = ((FSRefObject *)v)->ob_itself;
@@ -3208,8 +3228,13 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
        /* XXXX Should try unicode here too */
 #endif
        /* Otherwise we try to go via an FSSpec */
+#if TARGET_API_MAC_OSX
        if (FSSpec_Check(v)) {
-               if ((err=FSpMakeFSRef(&((FSSpecObject *)v)->ob_itself, fsr)) == 0)
+               fss = ((FSSpecObject *)v)->ob_itself;
+#else
+       if (PyMac_GetFSSpec(v, &fss)) {
+#endif
+               if ((err=FSpMakeFSRef(&fss, fsr)) == 0)
                        return 1;
                PyMac_Error(err);
                return 0;
index b7df7eb2e7f32ca2c617a25e51f84d3e556d490f..26821ddd69a0f3d06994396178493f7dd74305f2 100644 (file)
@@ -271,6 +271,7 @@ int
 PyMac_GetFSRef(PyObject *v, FSRef *fsr)
 {
        OSStatus err;
+       FSSpec fss;
        
        if (FSRef_Check(v)) {
                *fsr = ((FSRefObject *)v)->ob_itself;
@@ -289,8 +290,13 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
        /* XXXX Should try unicode here too */
 #endif
        /* Otherwise we try to go via an FSSpec */
+#if TARGET_API_MAC_OSX
        if (FSSpec_Check(v)) {
-               if ((err=FSpMakeFSRef(&((FSSpecObject *)v)->ob_itself, fsr)) == 0)
+               fss = ((FSSpecObject *)v)->ob_itself;
+#else
+       if (PyMac_GetFSSpec(v, &fss)) {
+#endif
+               if ((err=FSpMakeFSRef(&fss, fsr)) == 0)
                        return 1;
                PyMac_Error(err);
                return 0;
@@ -808,7 +814,26 @@ f.docstring = lambda: "() -> string"
 fsref_methods.append(f)
 
 FSRef_as_pathname_body = """
+#if TARGET_API_MAC_OSX
+if (!PyArg_ParseTuple(_args, ""))
+       return NULL;
 _res = FSRef_FSRefMakePath(_self, _args);
+#else
+char strbuf[1024];
+OSErr err;
+FSSpec fss;
+
+if (!PyArg_ParseTuple(_args, ""))
+       return NULL;
+if ( !PyMac_GetFSSpec((PyObject *)_self, &fss))
+       return NULL;
+err = PyMac_GetFullPathname(&fss, strbuf, sizeof(strbuf));
+if ( err ) {
+       PyMac_Error(err);
+       return NULL;
+}
+_res = PyString_FromString(strbuf);
+#endif
 return _res;
 """
 f = ManualGenerator("as_pathname", FSRef_as_pathname_body)