diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-05-10 22:51:58 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-05-10 22:51:58 (GMT) |
commit | 6d207c09aa7c9b5e155f4e779133c638fdfdd787 (patch) | |
tree | 72bd0560d440bd8025a142f94413e1484374ed1d /Mac/Modules/cf | |
parent | e037665f999c2ab5637fd9c2f4ac5c24e44e48f0 (diff) | |
download | cpython-6d207c09aa7c9b5e155f4e779133c638fdfdd787.zip cpython-6d207c09aa7c9b5e155f4e779133c638fdfdd787.tar.gz cpython-6d207c09aa7c9b5e155f4e779133c638fdfdd787.tar.bz2 |
- Get data from CFData objects as Python strings and vv.
- Started on supporting CFPropertyLists.
Diffstat (limited to 'Mac/Modules/cf')
-rw-r--r-- | Mac/Modules/cf/cfscan.py | 6 | ||||
-rw-r--r-- | Mac/Modules/cf/cfsupport.py | 29 |
2 files changed, 34 insertions, 1 deletions
diff --git a/Mac/Modules/cf/cfscan.py b/Mac/Modules/cf/cfscan.py index be11dba..d6613ae 100644 --- a/Mac/Modules/cf/cfscan.py +++ b/Mac/Modules/cf/cfscan.py @@ -15,6 +15,7 @@ OBJECTS = ("CFTypeRef", "CFDictionaryRef", "CFMutableDictionaryRef", "CFStringRef", "CFMutableStringRef", "CFURLRef", +## "CFPropertyListRef", ) # ADD object typenames here @@ -31,7 +32,7 @@ def main(): ## "CFNumber.h", ## "CFPlugIn.h", ## "CFPreferences.h", -## "CFPropertyList.h", + "CFPropertyList.h", ## "CFSet.h", "CFString.h", ## "CFStringEncodingExt.h", @@ -130,6 +131,9 @@ class MyScanner(Scanner_OSX): ([("CFURLRef", "baseURL", "InMode")], [("OptionalCFURLRef", "*", "*")]), + # We handle CFPropertyListRef objects as plain CFTypeRef + ([("CFPropertyListRef", "*", "*")], + [("CFTypeRef", "*", "*")]), ] if __name__ == "__main__": diff --git a/Mac/Modules/cf/cfsupport.py b/Mac/Modules/cf/cfsupport.py index d690441..b2ff3e1 100644 --- a/Mac/Modules/cf/cfsupport.py +++ b/Mac/Modules/cf/cfsupport.py @@ -49,6 +49,7 @@ includestuff = includestuff + """ #include <CFDictionary.h> #include <CFString.h> #include <CFURL.h> +#include <CFPropertyList.h> #else #include <CoreServices/CoreServices.h> #endif @@ -195,6 +196,7 @@ CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj") CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj") CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj") OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj") +##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj") # ADD object type here # Our (opaque) objects @@ -301,6 +303,18 @@ class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition): class CFDataRefObjectDefinition(MyGlobalObjectDefinition): 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() Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) @@ -491,6 +505,21 @@ toPython_body = """ 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); f.docstring = lambda: "() -> (python_object)" CFTypeRef_object.add(f) |