]> granicus.if.org Git - python/commitdiff
Added a convenience routine pathname() which accepts either a string, unicode,
authorJack Jansen <jack.jansen@cwi.nl>
Sun, 19 Jan 2003 22:59:52 +0000 (22:59 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Sun, 19 Jan 2003 22:59:52 +0000 (22:59 +0000)
FSSpec or FSRef object and returns an 8-bit pathname (utf8 encoded).

Mac/Modules/file/_Filemodule.c
Mac/Modules/file/filesupport.py

index 0e288893557f62e5042818420e88e62e12c97dff..5d3901fbe73496ebe2442d2f188c69243f089ac2 100644 (file)
@@ -14,9 +14,9 @@
 
 /* Macro to test whether a weak-loaded CFM function exists */
 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
-       PyErr_SetString(PyExc_NotImplementedError, \
-       "Not available in this shared library/OS version"); \
-       return NULL; \
+        PyErr_SetString(PyExc_NotImplementedError, \
+        "Not available in this shared library/OS version"); \
+        return NULL; \
     }} while(0)
 
 
@@ -2999,6 +2999,23 @@ static PyObject *File_FSUpdateAlias(PyObject *_self, PyObject *_args)
        return _res;
 }
 
+static PyObject *File_pathname(PyObject *_self, PyObject *_args)
+{
+       PyObject *_res = NULL;
+
+       PyObject *obj;
+
+       if (!PyArg_ParseTuple(_args, "O", &obj))
+               return NULL;
+       if (PyString_Check(obj))
+               return obj;
+       if (PyUnicode_Check(obj))
+               return PyUnicode_AsEncodedString(obj, "utf8", "strict");
+       _res = PyObject_CallMethod(obj, "as_pathname", NULL);
+       return _res;
+
+}
+
 static PyMethodDef File_methods[] = {
        {"UnmountVol", (PyCFunction)File_UnmountVol, 1,
         PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
@@ -3100,6 +3117,8 @@ static PyMethodDef File_methods[] = {
         PyDoc_STR("(Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
        {"FSUpdateAlias", (PyCFunction)File_FSUpdateAlias, 1,
         PyDoc_STR("(FSRef fromFile, FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
+       {"pathname", (PyCFunction)File_pathname, 1,
+        PyDoc_STR("(str|unicode|FSSpec|FSref) -> pathname")},
        {NULL, NULL, 0}
 };
 
index 4f2796302449f39ec9636924d3af0125f4078a09..b7df7eb2e7f32ca2c617a25e51f84d3e556d490f 100644 (file)
@@ -844,6 +844,21 @@ f = ManualGenerator("as_tuple", FSSpec_as_tuple_body)
 f.docstring = lambda: "() -> (vRefNum, dirID, name)"
 fsspec_methods.append(f)
 
+pathname_body = """
+PyObject *obj;
+
+if (!PyArg_ParseTuple(_args, "O", &obj))
+       return NULL;
+if (PyString_Check(obj))
+       return obj;
+if (PyUnicode_Check(obj))
+       return PyUnicode_AsEncodedString(obj, "utf8", "strict");
+_res = PyObject_CallMethod(obj, "as_pathname", NULL);
+return _res;
+"""
+f = ManualGenerator("pathname", pathname_body)
+f.docstring = lambda: "(str|unicode|FSSpec|FSref) -> pathname"
+functions.append(f)
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)