mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Added a convenience routine pathname() which accepts either a string, unicode,
FSSpec or FSRef object and returns an 8-bit pathname (utf8 encoded).
This commit is contained in:
parent
2cf08ab4c2
commit
9c564755b8
2 changed files with 37 additions and 3 deletions
|
@ -2999,6 +2999,23 @@ static PyObject *File_FSUpdateAlias(PyObject *_self, PyObject *_args)
|
||||||
return _res;
|
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[] = {
|
static PyMethodDef File_methods[] = {
|
||||||
{"UnmountVol", (PyCFunction)File_UnmountVol, 1,
|
{"UnmountVol", (PyCFunction)File_UnmountVol, 1,
|
||||||
PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
|
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)")},
|
PyDoc_STR("(Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
|
||||||
{"FSUpdateAlias", (PyCFunction)File_FSUpdateAlias, 1,
|
{"FSUpdateAlias", (PyCFunction)File_FSUpdateAlias, 1,
|
||||||
PyDoc_STR("(FSRef fromFile, FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
|
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}
|
{NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -844,6 +844,21 @@ f = ManualGenerator("as_tuple", FSSpec_as_tuple_body)
|
||||||
f.docstring = lambda: "() -> (vRefNum, dirID, name)"
|
f.docstring = lambda: "() -> (vRefNum, dirID, name)"
|
||||||
fsspec_methods.append(f)
|
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
|
# add the populated lists to the generator groups
|
||||||
# (in a different wordl the scan program would generate this)
|
# (in a different wordl the scan program would generate this)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue