[Python-checkins] python/dist/src/Mac/Modules/cf cfsupport.py,1.15,1.16

jackjansen@sourceforge.net jackjansen@sourceforge.net
Fri, 10 May 2002 15:52:00 -0700


Update of /cvsroot/python/python/dist/src/Mac/Modules/cf
In directory usw-pr-cvs1:/tmp/cvs-serv16891/Python/Mac/Modules/cf

Modified Files:
	cfsupport.py 
Log Message:
- Get data from CFData objects as Python strings and vv.
- Started on supporting CFPropertyLists.

Index: cfsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/cfsupport.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** cfsupport.py	7 May 2002 22:59:58 -0000	1.15
--- cfsupport.py	10 May 2002 22:51:58 -0000	1.16
***************
*** 50,53 ****
--- 50,54 ----
  #include <CFString.h>
  #include <CFURL.h>
+ #include <CFPropertyList.h>
  #else
  #include <CoreServices/CoreServices.h>
***************
*** 196,199 ****
--- 197,201 ----
  CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
  OptionalCFURLRef  = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
+ ##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj")
  # ADD object type here
  
***************
*** 302,305 ****
--- 304,319 ----
  	basechain = "&CFTypeRefObj_chain"
  	
+ 	def outputCheckConvertArg(self):
+ 		Out("""
+ 		if (v == Py_None) { *p_itself = NULL; return 1; }
+ 		if (PyString_Check(v)) {
+ 		    char *cStr;
+ 		    int cLen;
+ 		    if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
+ 		    *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
+ 		    return 1;
+ 		}
+ 		""")
+ 
  	def outputRepr(self):
  		Output()
***************
*** 491,494 ****
--- 505,523 ----
  return PyCF_CF2Python(_self->ob_itself);
  """
+ 
+ # Get data from CFDataRef
+ getasdata_body = """
+ int size = CFDataGetLength(_self->ob_itself);
+ char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
+ 
+ _res = (PyObject *)PyString_FromStringAndSize(data, size);
+ return _res;
+ """
+ 
+ f = ManualGenerator("CFDataGetData", getasdata_body);
+ f.docstring = lambda: "() -> (string _rv)"
+ CFDataRef_object.add(f)
+ 
+ 
  
  f = ManualGenerator("toPython", toPython_body);