[Python-checkins] python/dist/src/Mac/Modules/cf cfscan.py, 1.12, 1.13 cfsupport.py, 1.27, 1.28

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Jul 18 07:58:41 CEST 2004


Update of /cvsroot/python/python/dist/src/Mac/Modules/cf
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29056/Modules/cf
Modified Files:
	cfscan.py cfsupport.py 
Log Message:
Whitespace normalization, via reindent.py.
Index: cfscan.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/cfscan.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** cfscan.py	15 Aug 2002 21:48:13 -0000	1.12
--- cfscan.py	18 Jul 2004 05:58:08 -0000	1.13
***************
*** 9,142 ****
 LONG = "CoreFoundation"
 SHORT = "cf"
! OBJECTS = ("CFTypeRef", 
! 		"CFArrayRef", "CFMutableArrayRef",
! 		"CFDataRef", "CFMutableDataRef",
! 		"CFDictionaryRef", "CFMutableDictionaryRef",
! 		"CFStringRef", "CFMutableStringRef",
! 		"CFURLRef",
! ##		"CFPropertyListRef",
! 		)
 # ADD object typenames here
 
 def main():
! 	input = [
! 		"CFBase.h",
! 		"CFArray.h",
! ##		"CFBag.h",
! ##		"CFBundle.h",
! ##		"CFCharacterSet.h",
! 		"CFData.h",
! ##		"CFDate.h",
! 		"CFDictionary.h",
! ##		"CFNumber.h",
! ##		"CFPlugIn.h",
! 		"CFPreferences.h",
! 		"CFPropertyList.h",
! ##		"CFSet.h",
! 		"CFString.h",
! ##		"CFStringEncodingExt.h",
! ##		"CFTimeZone.h",
! 		"CFURL.h",
! 		]
! 	output = SHORT + "gen.py"
! 	defsoutput = TOOLBOXDIR + LONG + ".py"
! 	scanner = MyScanner(input, output, defsoutput)
! 	scanner.scan()
! 	scanner.gentypetest(SHORT+"typetest.py")
! 	scanner.close()
! 	print "=== Testing definitions output code ==="
! 	execfile(defsoutput, {}, {})
! 	print "=== Done scanning and generating, now importing the generated code... ==="
! 	exec "import " + SHORT + "support"
! 	print "=== Done. It's up to you to compile it now! ==="
 
 class MyScanner(Scanner_OSX):
 
! 	def destination(self, type, name, arglist):
! 		classname = "Function"
! 		listname = "functions"
! 		if arglist and name[:13] != 'CFPreferences':
! 			t, n, m = arglist[0]
! 			if t in OBJECTS and m == "InMode":
! 				classname = "Method"
! 				listname = t + "_methods"
! 			# Special case for the silly first AllocatorRef argument
! 			if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
! 				t, n, m = arglist[1]
! 				if t in OBJECTS and m == "InMode":
! 					classname = "MethodSkipArg1"
! 					listname = t + "_methods"
! 		return classname, listname
 
! 	def writeinitialdefs(self):
! 		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
 
! 	def makeblacklistnames(self):
! 		return [
! 			# Memory allocator functions
! 			"CFAllocatorGetDefault",
! 			"CFAllocatorSetDefault",
! 			"CFAllocatorAllocate",
! 			"CFAllocatorReallocate",
! 			"CFAllocatorDeallocate",
! 			"CFGetAllocator",
! 			# Array functions we skip for now.
! 			"CFArrayGetValueAtIndex",
! 			# Data pointer functions. Skip for now.
! 			"CFDataGetBytePtr",
! 			"CFDataGetMutableBytePtr",
! 			"CFDataGetBytes", # XXXX Should support this one
! 			# String functions
! 			"CFStringGetPascalString", # Use the C-string methods.
! 			"CFStringGetPascalStringPtr", # TBD automatically
! 			"CFStringGetCStringPtr", 
! 			"CFStringGetCharactersPtr",
! 			"CFStringGetCString", 
! 			"CFStringGetCharacters",
! 			"CFURLCreateStringWithFileSystemPath", # Gone in later releases
! 			"CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue...
! 			"CFStringSetExternalCharactersNoCopy",
! 			"CFStringGetCharacterAtIndex", # No format for single unichars yet.
! 			"kCFStringEncodingInvalidId", # incompatible constant declaration
! 			"CFPropertyListCreateFromXMLData", # Manually generated
! 			]
 
! 	def makegreylist(self):
! 		return []
 
! 	def makeblacklisttypes(self):
! 		return [
! 			"CFComparatorFunction", # Callback function pointer
! 			"CFAllocatorContext", # Not interested in providing our own allocator
! 			"void_ptr_ptr", # Tricky. This is the initializer for arrays...
! 			"void_ptr", # Ditto for various array lookup methods
! 			"CFArrayApplierFunction", # Callback function pointer
! 			"CFDictionaryApplierFunction", # Callback function pointer
! 			"va_list", # For printf-to-a-cfstring. Use Python.
! 			"const_CFStringEncoding_ptr", # To be done, I guess
! 			]
 
! 	def makerepairinstructions(self):
! 		return [
! 			# Buffers in CF seem to be passed as UInt8 * normally.
! 			([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
! 			 [("UcharInBuffer", "*", "*")]),
! 			 
! 			([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
! 			 [("UnicodeInBuffer", "*", "*")]),
 
- 			# Some functions return a const char *. Don't worry, we won't modify it.
- 			([("const_char_ptr", "*", "ReturnMode")],
- 			 [("return_stringptr", "*", "*")]),
- 			 
- 			# base URLs are optional (pass None for NULL)
- 			([("CFURLRef", "baseURL", "InMode")],
- 			 [("OptionalCFURLRef", "*", "*")]),
- 			 
- 			# We handle CFPropertyListRef objects as plain CFTypeRef
- 			([("CFPropertyListRef", "*", "*")],
- 			 [("CFTypeRef", "*", "*")]),
- 			]
- 			
 if __name__ == "__main__":
! 	main()
--- 9,142 ----
 LONG = "CoreFoundation"
 SHORT = "cf"
! OBJECTS = ("CFTypeRef",
! "CFArrayRef", "CFMutableArrayRef",
! "CFDataRef", "CFMutableDataRef",
! "CFDictionaryRef", "CFMutableDictionaryRef",
! "CFStringRef", "CFMutableStringRef",
! "CFURLRef",
! ## "CFPropertyListRef",
! )
 # ADD object typenames here
 
 def main():
! input = [
! "CFBase.h",
! "CFArray.h",
! ## "CFBag.h",
! ## "CFBundle.h",
! ## "CFCharacterSet.h",
! "CFData.h",
! ## "CFDate.h",
! "CFDictionary.h",
! ## "CFNumber.h",
! ## "CFPlugIn.h",
! "CFPreferences.h",
! "CFPropertyList.h",
! ## "CFSet.h",
! "CFString.h",
! ## "CFStringEncodingExt.h",
! ## "CFTimeZone.h",
! "CFURL.h",
! ]
! output = SHORT + "gen.py"
! defsoutput = TOOLBOXDIR + LONG + ".py"
! scanner = MyScanner(input, output, defsoutput)
! scanner.scan()
! scanner.gentypetest(SHORT+"typetest.py")
! scanner.close()
! print "=== Testing definitions output code ==="
! execfile(defsoutput, {}, {})
! print "=== Done scanning and generating, now importing the generated code... ==="
! exec "import " + SHORT + "support"
! print "=== Done. It's up to you to compile it now! ==="
 
 class MyScanner(Scanner_OSX):
 
! def destination(self, type, name, arglist):
! classname = "Function"
! listname = "functions"
! if arglist and name[:13] != 'CFPreferences':
! t, n, m = arglist[0]
! if t in OBJECTS and m == "InMode":
! classname = "Method"
! listname = t + "_methods"
! # Special case for the silly first AllocatorRef argument
! if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
! t, n, m = arglist[1]
! if t in OBJECTS and m == "InMode":
! classname = "MethodSkipArg1"
! listname = t + "_methods"
! return classname, listname
 
! def writeinitialdefs(self):
! self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
 
! def makeblacklistnames(self):
! return [
! # Memory allocator functions
! "CFAllocatorGetDefault",
! "CFAllocatorSetDefault",
! "CFAllocatorAllocate",
! "CFAllocatorReallocate",
! "CFAllocatorDeallocate",
! "CFGetAllocator",
! # Array functions we skip for now.
! "CFArrayGetValueAtIndex",
! # Data pointer functions. Skip for now.
! "CFDataGetBytePtr",
! "CFDataGetMutableBytePtr",
! "CFDataGetBytes", # XXXX Should support this one
! # String functions
! "CFStringGetPascalString", # Use the C-string methods.
! "CFStringGetPascalStringPtr", # TBD automatically
! "CFStringGetCStringPtr",
! "CFStringGetCharactersPtr",
! "CFStringGetCString",
! "CFStringGetCharacters",
! "CFURLCreateStringWithFileSystemPath", # Gone in later releases
! "CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue...
! "CFStringSetExternalCharactersNoCopy",
! "CFStringGetCharacterAtIndex", # No format for single unichars yet.
! "kCFStringEncodingInvalidId", # incompatible constant declaration
! "CFPropertyListCreateFromXMLData", # Manually generated
! ]
 
! def makegreylist(self):
! return []
 
! def makeblacklisttypes(self):
! return [
! "CFComparatorFunction", # Callback function pointer
! "CFAllocatorContext", # Not interested in providing our own allocator
! "void_ptr_ptr", # Tricky. This is the initializer for arrays...
! "void_ptr", # Ditto for various array lookup methods
! "CFArrayApplierFunction", # Callback function pointer
! "CFDictionaryApplierFunction", # Callback function pointer
! "va_list", # For printf-to-a-cfstring. Use Python.
! "const_CFStringEncoding_ptr", # To be done, I guess
! ]
 
! def makerepairinstructions(self):
! return [
! # Buffers in CF seem to be passed as UInt8 * normally.
! ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
! [("UcharInBuffer", "*", "*")]),
! 
! ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
! [("UnicodeInBuffer", "*", "*")]),
! 
! # Some functions return a const char *. Don't worry, we won't modify it.
! ([("const_char_ptr", "*", "ReturnMode")],
! [("return_stringptr", "*", "*")]),
! 
! # base URLs are optional (pass None for NULL)
! ([("CFURLRef", "baseURL", "InMode")],
! [("OptionalCFURLRef", "*", "*")]),
! 
! # We handle CFPropertyListRef objects as plain CFTypeRef
! ([("CFPropertyListRef", "*", "*")],
! [("CFTypeRef", "*", "*")]),
! ]
 
 if __name__ == "__main__":
! main()
Index: cfsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/cfsupport.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** cfsupport.py	15 Jul 2004 14:25:48 -0000	1.27
--- cfsupport.py	18 Jul 2004 05:58:08 -0000	1.28
***************
*** 9,18 ****
 
 # Declarations that change for each manager
! MODNAME = '_CF'				# The name of the module
 
 # The following is *usually* unchanged but may still require tuning
! MODPREFIX = 'CF'			# The prefix for module-wide routines
 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
! OUTPUTFILE = MODNAME + "module.c"	# The file generated by this program
 
 from macsupport import *
--- 9,18 ----
 
 # Declarations that change for each manager
! MODNAME = '_CF' # The name of the module
 
 # The following is *usually* unchanged but may still require tuning
! MODPREFIX = 'CF' # The prefix for module-wide routines
 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
! OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
 
 from macsupport import *
***************
*** 21,41 ****
 # which we skip anyway, and the object as the second arg.
 class MethodSkipArg1(MethodGenerator):
! 	"""Similar to MethodGenerator, but has self as last argument"""
 
! 	def parseArgumentList(self, args):
! 		if len(args) < 2:
! 			raise ValueError, "MethodSkipArg1 expects at least 2 args"
! 		a0, a1, args = args[0], args[1], args[2:]
! 		t0, n0, m0 = a0
! 		if t0 != "CFAllocatorRef" and m0 != InMode:
! 			raise ValueError, "MethodSkipArg1 should have dummy AllocatorRef first arg"
! 		t1, n1, m1 = a1
! 		if m1 != InMode:
! 			raise ValueError, "method's 'self' must be 'InMode'"
! 		dummy = Variable(t0, n0, m0)
! 		self.argumentList.append(dummy)
! 		self.itself = Variable(t1, "_self->ob_itself", SelfMode)
! 		self.argumentList.append(self.itself)
! 		FunctionGenerator.parseArgumentList(self, args)
 
 
--- 21,41 ----
 # which we skip anyway, and the object as the second arg.
 class MethodSkipArg1(MethodGenerator):
! """Similar to MethodGenerator, but has self as last argument"""
 
! def parseArgumentList(self, args):
! if len(args) < 2:
! raise ValueError, "MethodSkipArg1 expects at least 2 args"
! a0, a1, args = args[0], args[1], args[2:]
! t0, n0, m0 = a0
! if t0 != "CFAllocatorRef" and m0 != InMode:
! raise ValueError, "MethodSkipArg1 should have dummy AllocatorRef first arg"
! t1, n1, m1 = a1
! if m1 != InMode:
! raise ValueError, "method's 'self' must be 'InMode'"
! dummy = Variable(t0, n0, m0)
! self.argumentList.append(dummy)
! self.itself = Variable(t1, "_self->ob_itself", SelfMode)
! self.argumentList.append(self.itself)
! FunctionGenerator.parseArgumentList(self, args)
 
 
***************
*** 112,116 ****
 {
 
! 	return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
 }
 
--- 112,116 ----
 {
 
! return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
 }
 
***************
*** 118,128 ****
 CFRange_Convert(PyObject *v, CFRange *p_itself)
 {
! 	long location, length;
! 	
! 	if( !PyArg_ParseTuple(v, "ll", &location, &length) )
! 		return 0;
! 	p_itself->location = (CFIndex)location;
! 	p_itself->length = (CFIndex)length;
! 	return 1;
 }
 
--- 118,128 ----
 CFRange_Convert(PyObject *v, CFRange *p_itself)
 {
! long location, length;
! 
! if( !PyArg_ParseTuple(v, "ll", &location, &length) )
! return 0;
! p_itself->location = (CFIndex)location;
! p_itself->length = (CFIndex)length;
! return 1;
 }
 
***************
*** 132,137 ****
 {
 if ( v == Py_None ) {
! 	p_itself = NULL;
! 	return 1;
 }
 return CFURLRefObj_Convert(v, p_itself);
--- 132,137 ----
 {
 if ( v == Py_None ) {
! p_itself = NULL;
! return 1;
 }
 return CFURLRefObj_Convert(v, p_itself);
***************
*** 144,183 ****
 PyObject *CFObj_New(CFTypeRef itself)
 {
! 	if (itself == NULL)
! 	{
! 		PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
! 		return NULL;
! 	}
! 	if (CFGetTypeID(itself) == CFArrayGetTypeID()) return CFArrayRefObj_New((CFArrayRef)itself);
! 	if (CFGetTypeID(itself) == CFDictionaryGetTypeID()) return CFDictionaryRefObj_New((CFDictionaryRef)itself);
! 	if (CFGetTypeID(itself) == CFDataGetTypeID()) return CFDataRefObj_New((CFDataRef)itself);
! 	if (CFGetTypeID(itself) == CFStringGetTypeID()) return CFStringRefObj_New((CFStringRef)itself);
! 	if (CFGetTypeID(itself) == CFURLGetTypeID()) return CFURLRefObj_New((CFURLRef)itself);
! 	/* XXXX Or should we use PyCF_CF2Python here?? */
! 	return CFTypeRefObj_New(itself);
 }
 int CFObj_Convert(PyObject *v, CFTypeRef *p_itself)
 {
 
! 	if (v == Py_None) { *p_itself = NULL; return 1; }
! 	/* Check for other CF objects here */
 
! 	if (!CFTypeRefObj_Check(v) &&
! 		!CFArrayRefObj_Check(v) &&
! 		!CFMutableArrayRefObj_Check(v) &&
! 		!CFDictionaryRefObj_Check(v) &&
! 		!CFMutableDictionaryRefObj_Check(v) &&
! 		!CFDataRefObj_Check(v) &&
! 		!CFMutableDataRefObj_Check(v) &&
! 		!CFStringRefObj_Check(v) &&
! 		!CFMutableStringRefObj_Check(v) &&
! 		!CFURLRefObj_Check(v) )
! 	{
! 		/* XXXX Or should we use PyCF_Python2CF here?? */
! 		PyErr_SetString(PyExc_TypeError, "CF object required");
! 		return 0;
! 	}
! 	*p_itself = ((CFTypeRefObject *)v)->ob_itself;
! 	return 1;
 }
 """
--- 144,183 ----
 PyObject *CFObj_New(CFTypeRef itself)
 {
! if (itself == NULL)
! {
! PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
! return NULL;
! }
! if (CFGetTypeID(itself) == CFArrayGetTypeID()) return CFArrayRefObj_New((CFArrayRef)itself);
! if (CFGetTypeID(itself) == CFDictionaryGetTypeID()) return CFDictionaryRefObj_New((CFDictionaryRef)itself);
! if (CFGetTypeID(itself) == CFDataGetTypeID()) return CFDataRefObj_New((CFDataRef)itself);
! if (CFGetTypeID(itself) == CFStringGetTypeID()) return CFStringRefObj_New((CFStringRef)itself);
! if (CFGetTypeID(itself) == CFURLGetTypeID()) return CFURLRefObj_New((CFURLRef)itself);
! /* XXXX Or should we use PyCF_CF2Python here?? */
! return CFTypeRefObj_New(itself);
 }
 int CFObj_Convert(PyObject *v, CFTypeRef *p_itself)
 {
 
! if (v == Py_None) { *p_itself = NULL; return 1; }
! /* Check for other CF objects here */
 
! if (!CFTypeRefObj_Check(v) &&
! !CFArrayRefObj_Check(v) &&
! !CFMutableArrayRefObj_Check(v) &&
! !CFDictionaryRefObj_Check(v) &&
! !CFMutableDictionaryRefObj_Check(v) &&
! !CFDataRefObj_Check(v) &&
! !CFMutableDataRefObj_Check(v) &&
! !CFStringRefObj_Check(v) &&
! !CFMutableStringRefObj_Check(v) &&
! !CFURLRefObj_Check(v) )
! {
! /* XXXX Or should we use PyCF_Python2CF here?? */
! PyErr_SetString(PyExc_TypeError, "CF object required");
! return 0;
! }
! *p_itself = ((CFTypeRefObject *)v)->ob_itself;
! return 1;
 }
 """
***************
*** 226,230 ****
 
 char_ptr = stringptr
! return_stringptr = Type("char *", "s")	# ONLY FOR RETURN VALUES!!
 
 CFAllocatorRef = FakeType("(CFAllocatorRef)NULL")
--- 226,230 ----
 
 char_ptr = stringptr
! return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!!
 
 CFAllocatorRef = FakeType("(CFAllocatorRef)NULL")
***************
*** 252,482 ****
 
 class MyGlobalObjectDefinition(PEP253Mixin, 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)
! 		Output("void (*ob_freeit)(CFTypeRef ptr);")
! 	def outputInitStructMembers(self):
! 		GlobalObjectDefinition.outputInitStructMembers(self)
! ##		Output("it->ob_freeit = NULL;")
! 		Output("it->ob_freeit = CFRelease;")
! 	def outputCheckConvertArg(self):
! 		Out("""
! 		if (v == Py_None) { *p_itself = NULL; return 1; }
! 		/* Check for other CF objects here */
! 		""")
! 	def outputCleanupStructMembers(self):
! 		Output("if (self->ob_freeit && self->ob_itself)")
! 		OutLbrace()
! 		Output("self->ob_freeit((CFTypeRef)self->ob_itself);")
! 		Output("self->ob_itself = NULL;")
! 		OutRbrace()
! 		
! 	def outputCompare(self):
! 		Output()
! 		Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype)
! 		OutLbrace()
! 		Output("/* XXXX Or should we use CFEqual?? */")
! 		Output("if ( self->ob_itself > other->ob_itself ) return 1;")
! 		Output("if ( self->ob_itself < other->ob_itself ) return -1;")
! 		Output("return 0;")
! 		OutRbrace()
! 		
! 	def outputHash(self):
! 		Output()
! 		Output("static int %s_hash(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("/* XXXX Or should we use CFHash?? */")
! 		Output("return (int)self->ob_itself;")
! 		OutRbrace()
! 		
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFTypeRef type-%%d object at 0x%%8.8x for 0x%%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
 
! 	def output_tp_newBody(self):
! 		Output("PyObject *self;")
! 		Output
! 		Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
! 		Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
! 		Output("((%s *)self)->ob_freeit = CFRelease;", self.objecttype)
! 		Output("return self;")
! 		
! 	def output_tp_initBody(self):
! 		Output("%s itself;", self.itselftype)
! 		Output("char *kw[] = {\"itself\", 0};")
! 		Output()
! 		Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
! 			self.prefix)
! 		OutLbrace()
! 		Output("((%s *)self)->ob_itself = itself;", self.objecttype)
! 		Output("return 0;")
! 		OutRbrace()
! 		if self.prefix != 'CFTypeRefObj':
! 			Output()
! 			Output("/* Any CFTypeRef descendent is allowed as initializer too */")
! 			Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, CFTypeRefObj_Convert, &itself))")
! 			OutLbrace()
! 			Output("((%s *)self)->ob_itself = itself;", self.objecttype)
! 			Output("return 0;")
! 			OutRbrace()
! 		Output("return -1;")
 
 class CFTypeRefObjectDefinition(MyGlobalObjectDefinition):
! 	pass
! 	
 class CFArrayRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFTypeRef_Type"
! 	
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
! 	
 class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFArrayRef_Type"
! 	
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
! 	
 class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFTypeRef_Type"
! 	
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
! 	
 class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFDictionaryRef_Type"
! 	
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
! 	
 class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFTypeRef_Type"
! 	
! 	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()
- 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
- 		OutLbrace()
- 		Output("char buf[100];")
- 		Output("""sprintf(buf, "<CFDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
- 		Output("return PyString_FromString(buf);")
- 		OutRbrace()
- 	
 class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFDataRef_Type"
! 	
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
 
 class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFTypeRef_Type"
! 	
! 	def outputCheckConvertArg(self):
! 		Out("""
! 		if (v == Py_None) { *p_itself = NULL; return 1; }
! 		if (PyString_Check(v)) {
! 		 char *cStr;
! 		 if (!PyArg_Parse(v, "es", "ascii", &cStr))
! 		 	return NULL;
! 			*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
! 			return 1;
! 		}
! 		if (PyUnicode_Check(v)) {
! 			/* We use the CF types here, if Python was configured differently that will give an error */
! 			CFIndex size = PyUnicode_GetSize(v);
! 			UniChar *unichars = PyUnicode_AsUnicode(v);
! 			if (!unichars) return 0;
! 			*p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
! 			return 1;
! 		}
! 			
! 		""")
 
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
 
 class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
! 	basetype = "CFStringRef_Type"
! 	
! 	def outputCheckConvertArg(self):
! 		# Mutable, don't allow Python strings
! 		return MyGlobalObjectDefinition.outputCheckConvertArg(self)
! 		
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
 
 class CFURLRefObjectDefinition(MyGlobalObjectDefinition):
! 	basetype = "CFTypeRef_Type"
! 	
! 	def outputRepr(self):
! 		Output()
! 		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! 		OutLbrace()
! 		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFURL object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! 		Output("return PyString_FromString(buf);")
! 		OutRbrace()
 
 
--- 252,482 ----
 
 class MyGlobalObjectDefinition(PEP253Mixin, 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)
! Output("void (*ob_freeit)(CFTypeRef ptr);")
! def outputInitStructMembers(self):
! GlobalObjectDefinition.outputInitStructMembers(self)
! ## Output("it->ob_freeit = NULL;")
! Output("it->ob_freeit = CFRelease;")
! def outputCheckConvertArg(self):
! Out("""
! if (v == Py_None) { *p_itself = NULL; return 1; }
! /* Check for other CF objects here */
! """)
! def outputCleanupStructMembers(self):
! Output("if (self->ob_freeit && self->ob_itself)")
! OutLbrace()
! Output("self->ob_freeit((CFTypeRef)self->ob_itself);")
! Output("self->ob_itself = NULL;")
! OutRbrace()
 
! def outputCompare(self):
! Output()
! Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype)
! OutLbrace()
! Output("/* XXXX Or should we use CFEqual?? */")
! Output("if ( self->ob_itself > other->ob_itself ) return 1;")
! Output("if ( self->ob_itself < other->ob_itself ) return -1;")
! Output("return 0;")
! OutRbrace()
! 
! def outputHash(self):
! Output()
! Output("static int %s_hash(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("/* XXXX Or should we use CFHash?? */")
! Output("return (int)self->ob_itself;")
! OutRbrace()
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFTypeRef type-%%d object at 0x%%8.8x for 0x%%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
! 
! def output_tp_newBody(self):
! Output("PyObject *self;")
! Output
! Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
! Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
! Output("((%s *)self)->ob_freeit = CFRelease;", self.objecttype)
! Output("return self;")
! 
! def output_tp_initBody(self):
! Output("%s itself;", self.itselftype)
! Output("char *kw[] = {\"itself\", 0};")
! Output()
! Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
! self.prefix)
! OutLbrace()
! Output("((%s *)self)->ob_itself = itself;", self.objecttype)
! Output("return 0;")
! OutRbrace()
! if self.prefix != 'CFTypeRefObj':
! Output()
! Output("/* Any CFTypeRef descendent is allowed as initializer too */")
! Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, CFTypeRefObj_Convert, &itself))")
! OutLbrace()
! Output("((%s *)self)->ob_itself = itself;", self.objecttype)
! Output("return 0;")
! OutRbrace()
! Output("return -1;")
 
 class CFTypeRefObjectDefinition(MyGlobalObjectDefinition):
! pass
! 
 class CFArrayRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFTypeRef_Type"
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
! 
 class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFArrayRef_Type"
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
! 
 class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFTypeRef_Type"
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
! 
 class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFDictionaryRef_Type"
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
! 
 class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFTypeRef_Type"
! 
! 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()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
 
 class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFDataRef_Type"
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
 
 class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFTypeRef_Type"
 
! def outputCheckConvertArg(self):
! Out("""
! if (v == Py_None) { *p_itself = NULL; return 1; }
! if (PyString_Check(v)) {
! char *cStr;
! if (!PyArg_Parse(v, "es", "ascii", &cStr))
! return NULL;
! *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
! return 1;
! }
! if (PyUnicode_Check(v)) {
! /* We use the CF types here, if Python was configured differently that will give an error */
! CFIndex size = PyUnicode_GetSize(v);
! UniChar *unichars = PyUnicode_AsUnicode(v);
! if (!unichars) return 0;
! *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
! return 1;
! }
! 
! """)
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
 
 class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
! basetype = "CFStringRef_Type"
! 
! def outputCheckConvertArg(self):
! # Mutable, don't allow Python strings
! return MyGlobalObjectDefinition.outputCheckConvertArg(self)
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
 
 class CFURLRefObjectDefinition(MyGlobalObjectDefinition):
! basetype = "CFTypeRef_Type"
! 
! def outputRepr(self):
! Output()
! Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
! OutLbrace()
! Output("char buf[100];")
! Output("""sprintf(buf, "<CFURL object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
! Output("return PyString_FromString(buf);")
! OutRbrace()
 
 
***************
*** 555,562 ****
 if( data == NULL ) return PyErr_NoMemory();
 if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
! 	_res = (PyObject *)PyString_FromString(data);
 } else {
! 	PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
! 	_res = NULL;
 }
 free(data);
--- 555,562 ----
 if( data == NULL ) return PyErr_NoMemory();
 if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
! _res = (PyObject *)PyString_FromString(data);
 } else {
! PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
! _res = NULL;
 }
 free(data);
***************
*** 606,610 ****
 if (!PyArg_ParseTuple(_args, "l",
 &mutabilityOption))
! 	return NULL;
 _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
 _self->ob_itself,
--- 606,610 ----
 if (!PyArg_ParseTuple(_args, "l",
 &mutabilityOption))
! return NULL;
 _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
 _self->ob_itself,
***************
*** 612,619 ****
 &errorString);
 if (errorString)
! 	CFRelease(errorString);
 if (_rv == NULL) {
! 	PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
! 	return NULL;
 }
 _res = Py_BuildValue("O&",
--- 612,619 ----
 &errorString);
 if (errorString)
! CFRelease(errorString);
 if (_rv == NULL) {
! PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
! return NULL;
 }
 _res = Py_BuildValue("O&",
***************
*** 640,654 ****
 
 if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
! 	return NULL;
 typeid = CFGetTypeID(rv);
 
 if (typeid == CFStringGetTypeID())
! 	return Py_BuildValue("O&", CFStringRefObj_New, rv);
 if (typeid == CFArrayGetTypeID())
! 	return Py_BuildValue("O&", CFArrayRefObj_New, rv);
 if (typeid == CFDictionaryGetTypeID())
! 	return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
 if (typeid == CFURLGetTypeID())
! 	return Py_BuildValue("O&", CFURLRefObj_New, rv);
 
 _res = Py_BuildValue("O&", CFTypeRefObj_New, rv);
--- 640,654 ----
 
 if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
! return NULL;
 typeid = CFGetTypeID(rv);
 
 if (typeid == CFStringGetTypeID())
! return Py_BuildValue("O&", CFStringRefObj_New, rv);
 if (typeid == CFArrayGetTypeID())
! return Py_BuildValue("O&", CFArrayRefObj_New, rv);
 if (typeid == CFDictionaryGetTypeID())
! return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
 if (typeid == CFURLGetTypeID())
! return Py_BuildValue("O&", CFURLRefObj_New, rv);
 
 _res = Py_BuildValue("O&", CFTypeRefObj_New, rv);
***************
*** 664,666 ****
 SetOutputFileName(OUTPUTFILE)
 module.generate()
- 
--- 664,665 ----


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /