summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/file/filesupport.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-01-19 22:59:52 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2003-01-19 22:59:52 (GMT)
commit9c564755b8ed82c77232d5dda25aa7147d55f13d (patch)
tree5089daa7c5ddda080755d459ab7c5c635cd6990f /Mac/Modules/file/filesupport.py
parent2cf08ab4c2ef9743b35e61414c978555e2c6815d (diff)
downloadcpython-9c564755b8ed82c77232d5dda25aa7147d55f13d.zip
cpython-9c564755b8ed82c77232d5dda25aa7147d55f13d.tar.gz
cpython-9c564755b8ed82c77232d5dda25aa7147d55f13d.tar.bz2
Added a convenience routine pathname() which accepts either a string, unicode,
FSSpec or FSRef object and returns an 8-bit pathname (utf8 encoded).
Diffstat (limited to 'Mac/Modules/file/filesupport.py')
-rw-r--r--Mac/Modules/file/filesupport.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Mac/Modules/file/filesupport.py b/Mac/Modules/file/filesupport.py
index 4f27963..b7df7eb 100644
--- a/Mac/Modules/file/filesupport.py
+++ b/Mac/Modules/file/filesupport.py
@@ -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)