summaryrefslogtreecommitdiffstats
path: root/Mac/Modules
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1999-12-12 22:57:29 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1999-12-12 22:57:29 (GMT)
commit2d76c25f596538727ac409114d0ebae0279ac716 (patch)
tree0c085430784e02a0c19faee726072714ca6a6e47 /Mac/Modules
parentc5d0959a22425d9f82fc8cdd900cff866ea6c6be (diff)
downloadcpython-2d76c25f596538727ac409114d0ebae0279ac716.zip
cpython-2d76c25f596538727ac409114d0ebae0279ac716.tar.gz
cpython-2d76c25f596538727ac409114d0ebae0279ac716.tar.bz2
In places where a ResObj is expected for PyArg_Parse and the object passed in isn't but it does have an as_Resource method use that. This makes life a lot easier
for appearance portability (and was needed anyway).
Diffstat (limited to 'Mac/Modules')
-rw-r--r--Mac/Modules/res/Resmodule.c30
-rw-r--r--Mac/Modules/res/ressupport.py33
2 files changed, 53 insertions, 10 deletions
diff --git a/Mac/Modules/res/Resmodule.c b/Mac/Modules/res/Resmodule.c
index b5857e7..4f0f3c8 100644
--- a/Mac/Modules/res/Resmodule.c
+++ b/Mac/Modules/res/Resmodule.c
@@ -76,6 +76,17 @@ ResObj_Convert(v, p_itself)
{
if (!ResObj_Check(v))
{
+ PyObject *tmp;
+ if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) )
+ {
+ *p_itself = ((ResourceObject *)tmp)->ob_itself;
+ Py_DECREF(tmp);
+ return 1;
+ }
+ PyErr_Clear();
+ }
+ if (!ResObj_Check(v))
+ {
PyErr_SetString(PyExc_TypeError, "Resource required");
return 0;
}
@@ -1388,17 +1399,26 @@ OptResObj_Convert(v, p_itself)
PyObject *v;
Handle *p_itself;
{
+ PyObject *tmp;
+
if ( v == Py_None ) {
*p_itself = NULL;
return 1;
}
- if (!ResObj_Check(v))
+ if (ResObj_Check(v))
{
- PyErr_SetString(PyExc_TypeError, "Resource required");
- return 0;
+ *p_itself = ((ResourceObject *)v)->ob_itself;
+ return 1;
}
- *p_itself = ((ResourceObject *)v)->ob_itself;
- return 1;
+ /* If it isn't a resource yet see whether it is convertible */
+ if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) {
+ *p_itself = ((ResourceObject *)tmp)->ob_itself;
+ Py_DECREF(tmp);
+ return 1;
+ }
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "Resource required");
+ return 0;
}
diff --git a/Mac/Modules/res/ressupport.py b/Mac/Modules/res/ressupport.py
index 5d45f2e..c0466a7 100644
--- a/Mac/Modules/res/ressupport.py
+++ b/Mac/Modules/res/ressupport.py
@@ -44,17 +44,26 @@ OptResObj_Convert(v, p_itself)
PyObject *v;
Handle *p_itself;
{
+ PyObject *tmp;
+
if ( v == Py_None ) {
*p_itself = NULL;
return 1;
}
- if (!ResObj_Check(v))
+ if (ResObj_Check(v))
{
- PyErr_SetString(PyExc_TypeError, "Resource required");
- return 0;
+ *p_itself = ((ResourceObject *)v)->ob_itself;
+ return 1;
}
- *p_itself = ((ResourceObject *)v)->ob_itself;
- return 1;
+ /* If it isn't a resource yet see whether it is convertible */
+ if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) {
+ *p_itself = ((ResourceObject *)tmp)->ob_itself;
+ Py_DECREF(tmp);
+ return 1;
+ }
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "Resource required");
+ return 0;
}
"""
@@ -115,6 +124,20 @@ class ResDefiniton(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ def outputCheckConvertArg(self):
+ # if it isn't a resource we may be able to coerce it
+ Output("if (!%s_Check(v))", self.prefix)
+ OutLbrace()
+ Output("PyObject *tmp;")
+ Output('if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) )')
+ OutLbrace()
+ Output("*p_itself = ((ResourceObject *)tmp)->ob_itself;")
+ Output("Py_DECREF(tmp);")
+ Output("return 1;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ OutRbrace()
def outputGetattrHook(self):
Output(getattrHookCode)