2001-06-26 18:51:18 -03:00
|
|
|
# This script generates a Python interface for an Apple Macintosh Manager.
|
|
|
|
# It uses the "bgen" package to generate C code.
|
|
|
|
# The function specifications are generated by scanning the mamager's header file,
|
|
|
|
# using the "scantools" package (customized for this particular manager).
|
|
|
|
|
|
|
|
#error missing SetActionFilter
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Declarations that change for each manager
|
2004-07-18 03:16:08 -03:00
|
|
|
MODNAME = '_CF' # The name of the module
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
# The following is *usually* unchanged but may still require tuning
|
2004-07-18 03:16:08 -03:00
|
|
|
MODPREFIX = 'CF' # The prefix for module-wide routines
|
2001-06-26 18:51:18 -03:00
|
|
|
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
2004-07-18 03:16:08 -03:00
|
|
|
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
2001-07-17 17:47:13 -03:00
|
|
|
# Special case generator for the functions that have an AllocatorRef first argument,
|
|
|
|
# which we skip anyway, and the object as the second arg.
|
|
|
|
class MethodSkipArg1(MethodGenerator):
|
2004-07-18 03:16:08 -03:00
|
|
|
"""Similar to MethodGenerator, but has self as last argument"""
|
|
|
|
|
|
|
|
def parseArgumentList(self, args):
|
|
|
|
if len(args) < 2:
|
2007-08-22 20:05:23 -03:00
|
|
|
raise ValueError("MethodSkipArg1 expects at least 2 args")
|
2004-07-18 03:16:08 -03:00
|
|
|
a0, a1, args = args[0], args[1], args[2:]
|
|
|
|
t0, n0, m0 = a0
|
|
|
|
if t0 != "CFAllocatorRef" and m0 != InMode:
|
2007-08-22 20:05:23 -03:00
|
|
|
raise ValueError("MethodSkipArg1 should have dummy AllocatorRef first arg")
|
2004-07-18 03:16:08 -03:00
|
|
|
t1, n1, m1 = a1
|
|
|
|
if m1 != InMode:
|
2007-08-22 20:05:23 -03:00
|
|
|
raise ValueError("method's 'self' must be 'InMode'")
|
2004-07-18 03:16:08 -03:00
|
|
|
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)
|
2001-07-17 17:47:13 -03:00
|
|
|
|
|
|
|
|
2001-06-26 18:51:18 -03:00
|
|
|
# Create the type objects
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2001-08-03 12:36:23 -03:00
|
|
|
#include <CoreServices/CoreServices.h>
|
2001-06-26 18:51:18 -03:00
|
|
|
|
2002-05-07 20:00:03 -03:00
|
|
|
#include "pycfbridge.h"
|
|
|
|
|
2001-11-05 10:39:22 -04:00
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
2003-05-27 18:39:58 -03:00
|
|
|
extern PyObject *_CFObj_New(CFTypeRef);
|
|
|
|
extern int _CFObj_Convert(PyObject *, CFTypeRef *);
|
|
|
|
#define CFObj_New _CFObj_New
|
|
|
|
#define CFObj_Convert _CFObj_Convert
|
|
|
|
|
2001-11-05 10:39:22 -04:00
|
|
|
extern PyObject *_CFTypeRefObj_New(CFTypeRef);
|
|
|
|
extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
|
|
|
|
#define CFTypeRefObj_New _CFTypeRefObj_New
|
|
|
|
#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFStringRefObj_New(CFStringRef);
|
|
|
|
extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
|
|
|
|
#define CFStringRefObj_New _CFStringRefObj_New
|
|
|
|
#define CFStringRefObj_Convert _CFStringRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
|
|
|
|
extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
|
|
|
|
#define CFMutableStringRefObj_New _CFMutableStringRefObj_New
|
|
|
|
#define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFArrayRefObj_New(CFArrayRef);
|
|
|
|
extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
|
|
|
|
#define CFArrayRefObj_New _CFArrayRefObj_New
|
|
|
|
#define CFArrayRefObj_Convert _CFArrayRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
|
|
|
|
extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
|
|
|
|
#define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
|
|
|
|
#define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFDataRefObj_New(CFDataRef);
|
|
|
|
extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
|
|
|
|
#define CFDataRefObj_New _CFDataRefObj_New
|
|
|
|
#define CFDataRefObj_Convert _CFDataRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
|
|
|
|
extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
|
|
|
|
#define CFMutableDataRefObj_New _CFMutableDataRefObj_New
|
|
|
|
#define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
|
|
|
|
extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
|
|
|
|
#define CFDictionaryRefObj_New _CFDictionaryRefObj_New
|
|
|
|
#define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
|
|
|
|
extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
|
|
|
|
#define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
|
|
|
|
#define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
|
|
|
|
|
|
|
|
extern PyObject *_CFURLRefObj_New(CFURLRef);
|
|
|
|
extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
|
|
|
|
extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
|
|
|
|
#define CFURLRefObj_New _CFURLRefObj_New
|
|
|
|
#define CFURLRefObj_Convert _CFURLRefObj_Convert
|
|
|
|
#define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
|
2001-06-26 18:51:18 -03:00
|
|
|
#endif
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
/*
|
2001-06-28 19:08:26 -03:00
|
|
|
** Parse/generate CFRange records
|
2001-06-27 19:00:55 -03:00
|
|
|
*/
|
|
|
|
PyObject *CFRange_New(CFRange *itself)
|
|
|
|
{
|
|
|
|
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
|
2001-06-27 19:00:55 -03:00
|
|
|
}
|
|
|
|
|
2001-09-04 19:19:18 -03:00
|
|
|
int
|
2001-06-27 19:00:55 -03:00
|
|
|
CFRange_Convert(PyObject *v, CFRange *p_itself)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
long location, length;
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple(v, "ll", &location, &length) )
|
|
|
|
return 0;
|
|
|
|
p_itself->location = (CFIndex)location;
|
|
|
|
p_itself->length = (CFIndex)length;
|
|
|
|
return 1;
|
2001-06-27 19:00:55 -03:00
|
|
|
}
|
|
|
|
|
2001-06-28 19:08:26 -03:00
|
|
|
/* Optional CFURL argument or None (passed as NULL) */
|
|
|
|
int
|
|
|
|
OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
|
|
|
|
{
|
|
|
|
if ( v == Py_None ) {
|
2004-07-18 03:16:08 -03:00
|
|
|
p_itself = NULL;
|
|
|
|
return 1;
|
2001-06-28 19:08:26 -03:00
|
|
|
}
|
|
|
|
return CFURLRefObj_Convert(v, p_itself);
|
|
|
|
}
|
2003-05-27 18:39:58 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
finalstuff = finalstuff + """
|
|
|
|
|
|
|
|
/* Routines to convert any CF type to/from the corresponding CFxxxObj */
|
|
|
|
PyObject *CFObj_New(CFTypeRef itself)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
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);
|
2003-05-27 18:39:58 -03:00
|
|
|
}
|
|
|
|
int CFObj_Convert(PyObject *v, CFTypeRef *p_itself)
|
|
|
|
{
|
2001-06-28 19:08:26 -03:00
|
|
|
|
2004-07-18 03:16:08 -03:00
|
|
|
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;
|
2003-05-27 18:39:58 -03:00
|
|
|
}
|
2001-06-26 18:51:18 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
initstuff = initstuff + """
|
2003-05-31 19:09:33 -03:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFObj_Convert);
|
2001-11-05 10:39:22 -04:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
|
2001-06-26 18:51:18 -03:00
|
|
|
"""
|
|
|
|
|
2002-05-13 18:21:49 -03:00
|
|
|
variablestuff="""
|
|
|
|
#define _STRINGCONST(name) PyModule_AddObject(m, #name, CFStringRefObj_New(name))
|
|
|
|
_STRINGCONST(kCFPreferencesAnyApplication);
|
|
|
|
_STRINGCONST(kCFPreferencesCurrentApplication);
|
|
|
|
_STRINGCONST(kCFPreferencesAnyHost);
|
|
|
|
_STRINGCONST(kCFPreferencesCurrentHost);
|
|
|
|
_STRINGCONST(kCFPreferencesAnyUser);
|
|
|
|
_STRINGCONST(kCFPreferencesCurrentUser);
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2001-06-26 18:51:18 -03:00
|
|
|
Boolean = Type("Boolean", "l")
|
|
|
|
CFTypeID = Type("CFTypeID", "l") # XXXX a guess, seems better than OSTypeType.
|
|
|
|
CFHashCode = Type("CFHashCode", "l")
|
|
|
|
CFIndex = Type("CFIndex", "l")
|
2001-06-27 19:00:55 -03:00
|
|
|
CFRange = OpaqueByValueType('CFRange', 'CFRange')
|
2001-06-26 18:51:18 -03:00
|
|
|
CFOptionFlags = Type("CFOptionFlags", "l")
|
2001-06-27 19:00:55 -03:00
|
|
|
CFStringEncoding = Type("CFStringEncoding", "l")
|
2001-06-28 19:08:26 -03:00
|
|
|
CFComparisonResult = Type("CFComparisonResult", "l") # a bit dangerous, it's an enum
|
|
|
|
CFURLPathStyle = Type("CFURLPathStyle", "l") # a bit dangerous, it's an enum
|
2001-06-26 18:51:18 -03:00
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
char_ptr = stringptr
|
2004-07-18 03:16:08 -03:00
|
|
|
return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!!
|
2001-06-27 19:00:55 -03:00
|
|
|
|
|
|
|
CFAllocatorRef = FakeType("(CFAllocatorRef)NULL")
|
|
|
|
CFArrayCallBacks_ptr = FakeType("&kCFTypeArrayCallBacks")
|
|
|
|
CFDictionaryKeyCallBacks_ptr = FakeType("&kCFTypeDictionaryKeyCallBacks")
|
|
|
|
CFDictionaryValueCallBacks_ptr = FakeType("&kCFTypeDictionaryValueCallBacks")
|
2001-06-26 18:51:18 -03:00
|
|
|
# The real objects
|
|
|
|
CFTypeRef = OpaqueByValueType("CFTypeRef", "CFTypeRefObj")
|
2001-06-27 19:00:55 -03:00
|
|
|
CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")
|
|
|
|
CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")
|
|
|
|
CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")
|
|
|
|
CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")
|
|
|
|
CFDataRef = OpaqueByValueType("CFDataRef", "CFDataRefObj")
|
|
|
|
CFMutableDataRef = OpaqueByValueType("CFMutableDataRef", "CFMutableDataRefObj")
|
|
|
|
CFDictionaryRef = OpaqueByValueType("CFDictionaryRef", "CFDictionaryRefObj")
|
|
|
|
CFMutableDictionaryRef = OpaqueByValueType("CFMutableDictionaryRef", "CFMutableDictionaryRefObj")
|
2001-06-26 18:51:18 -03:00
|
|
|
CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")
|
2001-06-27 19:00:55 -03:00
|
|
|
CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
|
2001-06-28 19:08:26 -03:00
|
|
|
CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
|
|
|
|
OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
|
2002-05-10 19:51:58 -03:00
|
|
|
##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj")
|
2001-06-27 19:00:55 -03:00
|
|
|
# ADD object type here
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
# Our (opaque) objects
|
|
|
|
|
2004-07-15 10:42:06 -03:00
|
|
|
class MyGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
2005-07-03 17:59:44 -03:00
|
|
|
Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, %s_Convert, &itself))",
|
2004-07-18 03:16:08 -03:00
|
|
|
self.prefix)
|
|
|
|
OutLbrace()
|
2005-07-03 17:59:44 -03:00
|
|
|
Output("((%s *)_self)->ob_itself = itself;", self.objecttype)
|
2004-07-18 03:16:08 -03:00
|
|
|
Output("return 0;")
|
|
|
|
OutRbrace()
|
|
|
|
if self.prefix != 'CFTypeRefObj':
|
|
|
|
Output()
|
|
|
|
Output("/* Any CFTypeRef descendent is allowed as initializer too */")
|
2005-07-03 17:59:44 -03:00
|
|
|
Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, CFTypeRefObj_Convert, &itself))")
|
2004-07-18 03:16:08 -03:00
|
|
|
OutLbrace()
|
2005-07-03 17:59:44 -03:00
|
|
|
Output("((%s *)_self)->ob_itself = itself;", self.objecttype)
|
2004-07-18 03:16:08 -03:00
|
|
|
Output("return 0;")
|
|
|
|
OutRbrace()
|
|
|
|
Output("return -1;")
|
2004-07-15 10:42:06 -03:00
|
|
|
|
2001-06-26 18:51:18 -03:00
|
|
|
class CFTypeRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
pass
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
class CFArrayRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
2001-06-27 19:00:55 -03:00
|
|
|
|
2001-06-26 18:51:18 -03:00
|
|
|
class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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);
|
Merged revisions 58095-58132,58136-58148,58151-58197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58096 | brett.cannon | 2007-09-10 23:38:27 +0200 (Mon, 10 Sep 2007) | 4 lines
Fix a possible segfault from recursing too deep to get the repr of a list.
Closes issue #1096.
........
r58097 | bill.janssen | 2007-09-10 23:51:02 +0200 (Mon, 10 Sep 2007) | 33 lines
More work on SSL support.
* Much expanded test suite:
All protocols tested against all other protocols.
All protocols tested with all certificate options.
Tests for bad key and bad cert.
Test of STARTTLS functionality.
Test of RAND_* functions.
* Fixes for threading/malloc bug.
* Issue 1065 fixed:
sslsocket class renamed to SSLSocket.
sslerror class renamed to SSLError.
Function "wrap_socket" now used to wrap an existing socket.
* Issue 1583946 finally fixed:
Support for subjectAltName added.
Subject name now returned as proper DN list of RDNs.
* SSLError exported from socket as "sslerror".
* RAND_* functions properly exported from ssl.py.
* Documentation improved:
Example of how to create a self-signed certificate.
Better indexing.
........
r58098 | guido.van.rossum | 2007-09-11 00:02:25 +0200 (Tue, 11 Sep 2007) | 9 lines
Patch # 1140 (my code, approved by Effbot).
Make sure the type of the return value of re.sub(x, y, z) is the type
of y+x (i.e. unicode if either is unicode, str if they are both str)
even if there are no substitutions or if x==z (which triggered various
special cases in join_list()).
Could be backported to 2.5; no need to port to 3.0.
........
r58099 | guido.van.rossum | 2007-09-11 00:36:02 +0200 (Tue, 11 Sep 2007) | 8 lines
Patch # 1026 by Benjamin Aranguren (with Alex Martelli):
Backport abc.py and isinstance/issubclass overloading to 2.6.
I had to backport test_typechecks.py myself, and make one small change
to abc.py to avoid duplicate work when x.__class__ and type(x) are the
same.
........
r58100 | bill.janssen | 2007-09-11 01:41:24 +0200 (Tue, 11 Sep 2007) | 3 lines
A better way of finding an open port to test with.
........
r58101 | bill.janssen | 2007-09-11 03:09:19 +0200 (Tue, 11 Sep 2007) | 4 lines
Make sure test_ssl doesn't reference the ssl module in a
context where it can't be imported.
........
r58102 | bill.janssen | 2007-09-11 04:42:07 +0200 (Tue, 11 Sep 2007) | 3 lines
Fix some documentation bugs.
........
r58103 | nick.coghlan | 2007-09-11 16:01:18 +0200 (Tue, 11 Sep 2007) | 1 line
Always use the -E flag when spawning subprocesses in test_cmd_line (Issue 1056)
........
r58106 | thomas.heller | 2007-09-11 21:17:48 +0200 (Tue, 11 Sep 2007) | 3 lines
Disable some tests that fail on the 'ppc Debian unstable' buildbot to
find out if they cause the segfault on the 'alpha Debian' machine.
........
r58108 | brett.cannon | 2007-09-11 23:02:28 +0200 (Tue, 11 Sep 2007) | 6 lines
Generators had their throw() method allowing string exceptions. That's a
no-no.
Fixes issue #1147. Need to fix 2.5 to raise a proper warning if a string
exception is passed in.
........
r58112 | georg.brandl | 2007-09-12 20:03:51 +0200 (Wed, 12 Sep 2007) | 3 lines
New documentation page for the bdb module.
(This doesn't need to be merged to Py3k.)
........
r58114 | georg.brandl | 2007-09-12 20:05:57 +0200 (Wed, 12 Sep 2007) | 2 lines
Bug #1152: use non-deprecated name in example.
........
r58115 | georg.brandl | 2007-09-12 20:08:33 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1122: wrong return type documented for various _Size() functions.
........
r58117 | georg.brandl | 2007-09-12 20:10:56 +0200 (Wed, 12 Sep 2007) | 2 lines
Fix #1139: PyFile_Encoding really is PyFile_SetEncoding.
........
r58119 | georg.brandl | 2007-09-12 20:29:18 +0200 (Wed, 12 Sep 2007) | 2 lines
bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
........
r58121 | bill.janssen | 2007-09-12 20:52:05 +0200 (Wed, 12 Sep 2007) | 1 line
root certificate for https://svn.python.org/, used in test_ssl
........
r58122 | georg.brandl | 2007-09-12 21:00:07 +0200 (Wed, 12 Sep 2007) | 3 lines
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
........
r58125 | georg.brandl | 2007-09-12 21:29:28 +0200 (Wed, 12 Sep 2007) | 4 lines
#1120: put explicit version in the shebang lines of pydoc, idle
and smtpd.py scripts that are installed by setup.py. That way, they
work when only "make altinstall" is used.
........
r58139 | mark.summerfield | 2007-09-13 16:54:30 +0200 (Thu, 13 Sep 2007) | 9 lines
Replaced variable o with obj in operator.rst because o is easy to
confuse.
Added a note about Python 3's collections.Mapping etc., above section
that describes isMappingType() etc.
Added xrefs between os, os.path, fileinput, and open().
........
r58143 | facundo.batista | 2007-09-13 20:13:15 +0200 (Thu, 13 Sep 2007) | 7 lines
Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).
Thanks to Mark Dickinson for all his help during this process.
........
r58145 | facundo.batista | 2007-09-13 20:42:09 +0200 (Thu, 13 Sep 2007) | 7 lines
Put the parameter watchexp back in (changed watchexp from an int
to a bool). Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.
Thanks Mark Dickinson.
........
r58147 | andrew.kuchling | 2007-09-14 00:49:34 +0200 (Fri, 14 Sep 2007) | 1 line
Add various items
........
r58148 | andrew.kuchling | 2007-09-14 00:50:10 +0200 (Fri, 14 Sep 2007) | 1 line
Make target unique
........
r58154 | facundo.batista | 2007-09-14 20:58:34 +0200 (Fri, 14 Sep 2007) | 3 lines
Included the new functions, and new descriptions.
........
r58155 | thomas.heller | 2007-09-14 21:40:35 +0200 (Fri, 14 Sep 2007) | 2 lines
ctypes.util.find_library uses dump(1) instead of objdump(1) on Solaris.
Fixes issue #1777530; will backport to release25-maint.
........
r58159 | facundo.batista | 2007-09-14 23:29:52 +0200 (Fri, 14 Sep 2007) | 3 lines
Some additions (examples and a bit on the tutorial).
........
r58160 | georg.brandl | 2007-09-15 18:53:36 +0200 (Sat, 15 Sep 2007) | 2 lines
Remove bdb from the "undocumented modules" list.
........
r58164 | bill.janssen | 2007-09-17 00:06:00 +0200 (Mon, 17 Sep 2007) | 15 lines
Add support for asyncore server-side SSL support. This requires
adding the 'makefile' method to ssl.SSLSocket, and importing the
requisite fakefile class from socket.py, and making the appropriate
changes to it to make it use the SSL connection.
Added sample HTTPS server to test_ssl.py, and test that uses it.
Change SSL tests to use https://svn.python.org/, instead of
www.sf.net and pop.gmail.com.
Added utility function to ssl module, get_server_certificate,
to wrap up the several things to be done to pull a certificate
from a remote server.
........
r58173 | bill.janssen | 2007-09-17 01:16:46 +0200 (Mon, 17 Sep 2007) | 1 line
use binary mode when reading files for testAsyncore to make Windows happy
........
r58175 | raymond.hettinger | 2007-09-17 02:55:00 +0200 (Mon, 17 Sep 2007) | 7 lines
Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
........
r58176 | brett.cannon | 2007-09-17 05:28:34 +0200 (Mon, 17 Sep 2007) | 5 lines
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().
Closes issue #1164.
........
r58177 | sean.reifschneider | 2007-09-17 07:45:04 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1597011: Fix for bz2 module corner-case error due to error checking bug.
........
r58180 | facundo.batista | 2007-09-17 18:26:50 +0200 (Mon, 17 Sep 2007) | 3 lines
Decimal is updated, :)
........
r58181 | facundo.batista | 2007-09-17 19:30:13 +0200 (Mon, 17 Sep 2007) | 5 lines
The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
........
r58183 | sean.reifschneider | 2007-09-17 22:53:21 +0200 (Mon, 17 Sep 2007) | 2 lines
issue1082: Fixing platform and system for Vista.
........
r58185 | andrew.kuchling | 2007-09-18 03:36:16 +0200 (Tue, 18 Sep 2007) | 1 line
Add item; sort properly
........
r58186 | raymond.hettinger | 2007-09-18 05:33:19 +0200 (Tue, 18 Sep 2007) | 1 line
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
........
r58192 | georg.brandl | 2007-09-18 09:24:40 +0200 (Tue, 18 Sep 2007) | 2 lines
A bit of reordering, also show more subheadings in the lang ref index.
........
r58193 | facundo.batista | 2007-09-18 18:53:18 +0200 (Tue, 18 Sep 2007) | 4 lines
Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
........
r58197 | raymond.hettinger | 2007-09-19 00:18:02 +0200 (Wed, 19 Sep 2007) | 1 line
Cleanup docs for NamedTuple.
........
2007-09-19 00:06:30 -03:00
|
|
|
PyMem_Free(cStr);
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
2001-06-27 19:00:55 -03:00
|
|
|
|
|
|
|
class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
2001-06-28 19:08:26 -03:00
|
|
|
|
|
|
|
class CFURLRefObjectDefinition(MyGlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
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()
|
2001-06-27 19:00:55 -03:00
|
|
|
|
|
|
|
|
|
|
|
# ADD object class here
|
|
|
|
|
2001-06-26 18:51:18 -03:00
|
|
|
# From here on it's basically all boiler plate...
|
|
|
|
|
|
|
|
# Create the generator groups and link them
|
2002-05-13 18:21:49 -03:00
|
|
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
|
2001-06-26 18:51:18 -03:00
|
|
|
CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef')
|
2001-06-28 19:08:26 -03:00
|
|
|
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')
|
2001-06-27 19:00:55 -03:00
|
|
|
|
|
|
|
# ADD object here
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
module.addobject(CFTypeRef_object)
|
2001-06-27 19:00:55 -03:00
|
|
|
module.addobject(CFArrayRef_object)
|
|
|
|
module.addobject(CFMutableArrayRef_object)
|
|
|
|
module.addobject(CFDictionaryRef_object)
|
|
|
|
module.addobject(CFMutableDictionaryRef_object)
|
|
|
|
module.addobject(CFDataRef_object)
|
|
|
|
module.addobject(CFMutableDataRef_object)
|
2001-06-26 18:51:18 -03:00
|
|
|
module.addobject(CFStringRef_object)
|
2001-06-27 19:00:55 -03:00
|
|
|
module.addobject(CFMutableStringRef_object)
|
2001-06-28 19:08:26 -03:00
|
|
|
module.addobject(CFURLRef_object)
|
2001-06-27 19:00:55 -03:00
|
|
|
# ADD addobject call here
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
# Create the generator classes used to populate the lists
|
2001-07-01 19:04:02 -03:00
|
|
|
Function = OSErrWeakLinkFunctionGenerator
|
|
|
|
Method = OSErrWeakLinkMethodGenerator
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
# Create and populate the lists
|
|
|
|
functions = []
|
|
|
|
CFTypeRef_methods = []
|
2001-06-27 19:00:55 -03:00
|
|
|
CFArrayRef_methods = []
|
|
|
|
CFMutableArrayRef_methods = []
|
|
|
|
CFDictionaryRef_methods = []
|
|
|
|
CFMutableDictionaryRef_methods = []
|
|
|
|
CFDataRef_methods = []
|
|
|
|
CFMutableDataRef_methods = []
|
2001-06-26 18:51:18 -03:00
|
|
|
CFStringRef_methods = []
|
2001-06-27 19:00:55 -03:00
|
|
|
CFMutableStringRef_methods = []
|
2001-06-28 19:08:26 -03:00
|
|
|
CFURLRef_methods = []
|
2001-06-27 19:00:55 -03:00
|
|
|
|
|
|
|
# ADD _methods initializer here
|
2007-08-11 21:43:29 -03:00
|
|
|
exec(open(INPUTFILE).read())
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
|
|
|
|
# add the populated lists to the generator groups
|
|
|
|
# (in a different wordl the scan program would generate this)
|
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in CFTypeRef_methods: CFTypeRef_object.add(f)
|
2001-06-27 19:00:55 -03:00
|
|
|
for f in CFArrayRef_methods: CFArrayRef_object.add(f)
|
|
|
|
for f in CFMutableArrayRef_methods: CFMutableArrayRef_object.add(f)
|
|
|
|
for f in CFDictionaryRef_methods: CFDictionaryRef_object.add(f)
|
|
|
|
for f in CFMutableDictionaryRef_methods: CFMutableDictionaryRef_object.add(f)
|
|
|
|
for f in CFDataRef_methods: CFDataRef_object.add(f)
|
|
|
|
for f in CFMutableDataRef_methods: CFMutableDataRef_object.add(f)
|
2001-06-26 18:51:18 -03:00
|
|
|
for f in CFStringRef_methods: CFStringRef_object.add(f)
|
2001-06-27 19:00:55 -03:00
|
|
|
for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f)
|
2001-06-28 19:08:26 -03:00
|
|
|
for f in CFURLRef_methods: CFURLRef_object.add(f)
|
2001-06-27 19:00:55 -03:00
|
|
|
|
2001-07-01 19:04:02 -03:00
|
|
|
# Manual generators for getting data out of strings
|
|
|
|
|
|
|
|
getasstring_body = """
|
|
|
|
int size = CFStringGetLength(_self->ob_itself)+1;
|
|
|
|
char *data = malloc(size);
|
|
|
|
|
|
|
|
if( data == NULL ) return PyErr_NoMemory();
|
|
|
|
if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
|
2004-07-18 03:16:08 -03:00
|
|
|
_res = (PyObject *)PyString_FromString(data);
|
2001-07-01 19:04:02 -03:00
|
|
|
} else {
|
2004-07-18 03:16:08 -03:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
|
|
|
|
_res = NULL;
|
2001-07-01 19:04:02 -03:00
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
return _res;
|
|
|
|
"""
|
|
|
|
|
|
|
|
f = ManualGenerator("CFStringGetString", getasstring_body);
|
|
|
|
f.docstring = lambda: "() -> (string _rv)"
|
|
|
|
CFStringRef_object.add(f)
|
|
|
|
|
2001-07-04 19:38:52 -03:00
|
|
|
getasunicode_body = """
|
|
|
|
int size = CFStringGetLength(_self->ob_itself)+1;
|
|
|
|
Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
|
|
|
|
CFRange range;
|
|
|
|
|
|
|
|
range.location = 0;
|
|
|
|
range.length = size;
|
|
|
|
if( data == NULL ) return PyErr_NoMemory();
|
|
|
|
CFStringGetCharacters(_self->ob_itself, range, data);
|
2004-07-15 11:11:30 -03:00
|
|
|
_res = (PyObject *)PyUnicode_FromUnicode(data, size-1);
|
2001-07-04 19:38:52 -03:00
|
|
|
free(data);
|
|
|
|
return _res;
|
|
|
|
"""
|
|
|
|
|
|
|
|
f = ManualGenerator("CFStringGetUnicode", getasunicode_body);
|
|
|
|
f.docstring = lambda: "() -> (unicode _rv)"
|
|
|
|
CFStringRef_object.add(f)
|
|
|
|
|
2002-05-10 19:51:58 -03:00
|
|
|
# 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)
|
|
|
|
|
2002-05-12 19:04:14 -03:00
|
|
|
# Manual generator for CFPropertyListCreateFromXMLData because of funny error return
|
|
|
|
fromxml_body = """
|
|
|
|
CFTypeRef _rv;
|
|
|
|
CFOptionFlags mutabilityOption;
|
|
|
|
CFStringRef errorString;
|
|
|
|
if (!PyArg_ParseTuple(_args, "l",
|
|
|
|
&mutabilityOption))
|
2004-07-18 03:16:08 -03:00
|
|
|
return NULL;
|
2002-05-12 19:04:14 -03:00
|
|
|
_rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
|
|
|
|
_self->ob_itself,
|
|
|
|
mutabilityOption,
|
|
|
|
&errorString);
|
|
|
|
if (errorString)
|
2004-07-18 03:16:08 -03:00
|
|
|
CFRelease(errorString);
|
2002-05-12 19:04:14 -03:00
|
|
|
if (_rv == NULL) {
|
2004-07-18 03:16:08 -03:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
|
|
|
|
return NULL;
|
2002-05-12 19:04:14 -03:00
|
|
|
}
|
|
|
|
_res = Py_BuildValue("O&",
|
|
|
|
CFTypeRefObj_New, _rv);
|
|
|
|
return _res;
|
|
|
|
"""
|
|
|
|
f = ManualGenerator("CFPropertyListCreateFromXMLData", fromxml_body)
|
|
|
|
f.docstring = lambda: "(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)"
|
|
|
|
CFTypeRef_object.add(f)
|
2002-05-10 19:51:58 -03:00
|
|
|
|
2002-05-12 19:04:14 -03:00
|
|
|
# Convert CF objects to Python objects
|
|
|
|
toPython_body = """
|
2002-12-23 18:35:38 -04:00
|
|
|
_res = PyCF_CF2Python(_self->ob_itself);
|
|
|
|
return _res;
|
2002-05-12 19:04:14 -03:00
|
|
|
"""
|
2002-05-10 19:51:58 -03:00
|
|
|
|
2002-05-07 20:00:03 -03:00
|
|
|
f = ManualGenerator("toPython", toPython_body);
|
|
|
|
f.docstring = lambda: "() -> (python_object)"
|
|
|
|
CFTypeRef_object.add(f)
|
|
|
|
|
|
|
|
toCF_body = """
|
|
|
|
CFTypeRef rv;
|
|
|
|
CFTypeID typeid;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
|
2004-07-18 03:16:08 -03:00
|
|
|
return NULL;
|
2002-05-07 20:00:03 -03:00
|
|
|
typeid = CFGetTypeID(rv);
|
|
|
|
|
|
|
|
if (typeid == CFStringGetTypeID())
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("O&", CFStringRefObj_New, rv);
|
2002-05-07 20:00:03 -03:00
|
|
|
if (typeid == CFArrayGetTypeID())
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("O&", CFArrayRefObj_New, rv);
|
2002-05-07 20:00:03 -03:00
|
|
|
if (typeid == CFDictionaryGetTypeID())
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
|
2002-05-07 20:00:03 -03:00
|
|
|
if (typeid == CFURLGetTypeID())
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("O&", CFURLRefObj_New, rv);
|
2002-05-07 20:00:03 -03:00
|
|
|
|
2002-12-23 18:35:38 -04:00
|
|
|
_res = Py_BuildValue("O&", CFTypeRefObj_New, rv);
|
|
|
|
return _res;
|
2002-05-07 20:00:03 -03:00
|
|
|
"""
|
|
|
|
f = ManualGenerator("toCF", toCF_body);
|
|
|
|
f.docstring = lambda: "(python_object) -> (CF_object)"
|
|
|
|
module.add(f)
|
|
|
|
|
2001-06-27 19:00:55 -03:00
|
|
|
# ADD add forloop here
|
2001-06-26 18:51:18 -03:00
|
|
|
|
|
|
|
# generate output (open the output file as late as possible)
|
|
|
|
SetOutputFileName(OUTPUTFILE)
|
|
|
|
module.generate()
|