[Python-checkins] python/dist/src/Mac/Modules/cf cfsupport.py,1.16,1.17
jackjansen@sourceforge.net
jackjansen@sourceforge.net
Sun, 12 May 2002 15:04:16 -0700
Update of /cvsroot/python/python/dist/src/Mac/Modules/cf
In directory usw-pr-cvs1:/tmp/cvs-serv3036/Python/Mac/Modules/cf
Modified Files:
cfsupport.py
Log Message:
- Better exception when a NULL CF object is encountered.
- Manually generate a routine with funny error semantics.
Index: cfsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/cfsupport.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** cfsupport.py 10 May 2002 22:51:58 -0000 1.16
--- cfsupport.py 12 May 2002 22:04:14 -0000 1.17
***************
*** 204,208 ****
class MyGlobalObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
! Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputStructMembers(self):
GlobalObjectDefinition.outputStructMembers(self)
--- 204,212 ----
class MyGlobalObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
! Output('if (itself == NULL)')
! OutLbrace()
! Output('PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");')
! Output('return NULL;')
! OutRbrace()
def outputStructMembers(self):
GlobalObjectDefinition.outputStructMembers(self)
***************
*** 502,509 ****
CFStringRef_object.add(f)
- toPython_body = """
- return PyCF_CF2Python(_self->ob_itself);
- """
-
# Get data from CFDataRef
getasdata_body = """
--- 506,509 ----
***************
*** 519,523 ****
--- 519,552 ----
CFDataRef_object.add(f)
+ # Manual generator for CFPropertyListCreateFromXMLData because of funny error return
+ fromxml_body = """
+ CFTypeRef _rv;
+ CFOptionFlags mutabilityOption;
+ CFStringRef errorString;
+ if (!PyArg_ParseTuple(_args, "l",
+ &mutabilityOption))
+ return NULL;
+ _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ mutabilityOption,
+ &errorString);
+ if (errorString)
+ CFRelease(errorString);
+ if (_rv == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
+ return NULL;
+ }
+ _res = Py_BuildValue("O&",
+ CFTypeRefObj_New, _rv);
+ return _res;
+ """
+ f = ManualGenerator("CFPropertyListCreateFromXMLData", fromxml_body)
+ f.docstring = lambda: "(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)"
+ CFTypeRef_object.add(f)
+ # Convert CF objects to Python objects
+ toPython_body = """
+ return PyCF_CF2Python(_self->ob_itself);
+ """
f = ManualGenerator("toPython", toPython_body);