[Python-checkins] CVS: python/dist/src/Mac/Modules/cf cfsupport.py,1.2,1.3

Jack Jansen jackjansen@users.sourceforge.net
Thu, 28 Jun 2001 15:08:28 -0700


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

Modified Files:
	cfsupport.py 
Log Message:
Added CFURL support, and got base chaining to really work.

Index: cfsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cf/cfsupport.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** cfsupport.py	2001/06/27 22:00:55	1.2
--- cfsupport.py	2001/06/28 22:08:26	1.3
***************
*** 28,36 ****
  
  /* For now we declare them forward here. They'll go to mactoolbox later */
! extern PyObject *CFTypeRefObj_New(CFTypeRef);
! extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
! extern PyObject *CFStringRefObj_New(CFStringRef);
! extern int CFStringRefObj_Convert(PyObject *, CFStringRef *);
  
  // ADD declarations
  #ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
--- 28,38 ----
  
  /* For now we declare them forward here. They'll go to mactoolbox later */
! staticforward PyObject *CFTypeRefObj_New(CFTypeRef);
! staticforward int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
! staticforward PyObject *CFStringRefObj_New(CFStringRef);
! staticforward int CFStringRefObj_Convert(PyObject *, CFStringRef *);
  
+ staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
+ 
  // ADD declarations
  #ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
***************
*** 43,47 ****
  
  /*
! ** Parse/generate RGB records
  */
  PyObject *CFRange_New(CFRange *itself)
--- 45,49 ----
  
  /*
! ** Parse/generate CFRange records
  */
  PyObject *CFRange_New(CFRange *itself)
***************
*** 62,65 ****
--- 64,78 ----
  }
  
+ /* Optional CFURL argument or None (passed as NULL) */
+ int
+ OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
+ {
+     if ( v == Py_None ) {
+     	p_itself = NULL;
+     	return 1;
+     }
+     return CFURLRefObj_Convert(v, p_itself);
+ }
+ 
  """
  
***************
*** 76,80 ****
  CFOptionFlags = Type("CFOptionFlags", "l")
  CFStringEncoding = Type("CFStringEncoding", "l")
! CFComparisonResult = Type("CFComparisonResult", "l")  # a bit dangerous...
  
  char_ptr = stringptr
--- 89,94 ----
  CFOptionFlags = Type("CFOptionFlags", "l")
  CFStringEncoding = Type("CFStringEncoding", "l")
! CFComparisonResult = Type("CFComparisonResult", "l")  # a bit dangerous, it's an enum
! CFURLPathStyle = Type("CFURLPathStyle", "l") #  a bit dangerous, it's an enum
  
  char_ptr = stringptr
***************
*** 97,100 ****
--- 111,116 ----
  CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")
  CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
+ CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
+ OptionalCFURLRef  = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
  # ADD object type here
  
***************
*** 161,165 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFArrayRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 177,181 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFArrayRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 173,177 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 189,193 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 185,189 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 201,205 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 197,201 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 213,217 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 209,213 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFDataRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 225,229 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFDataRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 221,225 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 237,241 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 233,237 ****
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFStringRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 249,253 ----
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFStringRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 244,249 ****
  		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
  		OutLbrace()
  		Output("char buf[100];")
! 		Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
--- 260,277 ----
  		Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
  		OutLbrace()
+ 		Output("char buf[100];")
+ 		Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ 		Output("return PyString_FromString(buf);")
+ 		OutRbrace()
+ 
+ class CFURLRefObjectDefinition(MyGlobalObjectDefinition):
+ 	basechain = "&CFTypeRefObj_chain"
+ 	
+ 	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%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
  		Output("return PyString_FromString(buf);")
  		OutRbrace()
***************
*** 257,268 ****
  module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
  CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef')
! CFArrayRef_object = CFTypeRefObjectDefinition('CFArrayRef', 'CFArrayRefObj', 'CFArrayRef')
! CFMutableArrayRef_object = CFTypeRefObjectDefinition('CFMutableArrayRef', 'CFMutableArrayRefObj', 'CFMutableArrayRef')
! CFDictionaryRef_object = CFTypeRefObjectDefinition('CFDictionaryRef', 'CFDictionaryRefObj', 'CFDictionaryRef')
! CFMutableDictionaryRef_object = CFTypeRefObjectDefinition('CFMutableDictionaryRef', 'CFMutableDictionaryRefObj', 'CFMutableDictionaryRef')
! CFDataRef_object = CFTypeRefObjectDefinition('CFDataRef', 'CFDataRefObj', 'CFDataRef')
! CFMutableDataRef_object = CFTypeRefObjectDefinition('CFMutableDataRef', 'CFMutableDataRefObj', 'CFMutableDataRef')
! CFStringRef_object = CFTypeRefObjectDefinition('CFStringRef', 'CFStringRefObj', 'CFStringRef')
! CFMutableStringRef_object = CFTypeRefObjectDefinition('CFMutableStringRef', 'CFMutableStringRefObj', 'CFMutableStringRef')
  
  # ADD object here
--- 285,297 ----
  module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
  CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef')
! CFArrayRef_object = CFArrayRefObjectDefinition('CFArrayRef', 'CFArrayRefObj', 'CFArrayRef')
! CFMutableArrayRef_object = CFMutableArrayRefObjectDefinition('CFMutableArrayRef', 'CFMutableArrayRefObj', 'CFMutableArrayRef')
! CFDictionaryRef_object = CFDictionaryRefObjectDefinition('CFDictionaryRef', 'CFDictionaryRefObj', 'CFDictionaryRef')
! CFMutableDictionaryRef_object = CFMutableDictionaryRefObjectDefinition('CFMutableDictionaryRef', 'CFMutableDictionaryRefObj', 'CFMutableDictionaryRef')
! CFDataRef_object = CFDataRefObjectDefinition('CFDataRef', 'CFDataRefObj', 'CFDataRef')
! CFMutableDataRef_object = CFMutableDataRefObjectDefinition('CFMutableDataRef', 'CFMutableDataRefObj', 'CFMutableDataRef')
! CFStringRef_object = CFStringRefObjectDefinition('CFStringRef', 'CFStringRefObj', 'CFStringRef')
! CFMutableStringRef_object = CFMutableStringRefObjectDefinition('CFMutableStringRef', 'CFMutableStringRefObj', 'CFMutableStringRef')
! CFURLRef_object = CFURLRefObjectDefinition('CFURLRef', 'CFURLRefObj', 'CFURLRef')
  
  # ADD object here
***************
*** 277,280 ****
--- 306,310 ----
  module.addobject(CFStringRef_object)
  module.addobject(CFMutableStringRef_object)
+ module.addobject(CFURLRef_object)
  # ADD addobject call here
  
***************
*** 294,297 ****
--- 324,328 ----
  CFStringRef_methods = []
  CFMutableStringRef_methods = []
+ CFURLRef_methods = []
  
  # ADD _methods initializer here
***************
*** 311,314 ****
--- 342,346 ----
  for f in CFStringRef_methods: CFStringRef_object.add(f)
  for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f)
+ for f in CFURLRef_methods: CFURLRef_object.add(f)
  
  # ADD add forloop here