mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
- Get data from CFData objects as Python strings and vv.
- Started on supporting CFPropertyLists.
This commit is contained in:
parent
e037665f99
commit
6d207c09aa
2 changed files with 34 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ OBJECTS = ("CFTypeRef",
|
||||||
"CFDictionaryRef", "CFMutableDictionaryRef",
|
"CFDictionaryRef", "CFMutableDictionaryRef",
|
||||||
"CFStringRef", "CFMutableStringRef",
|
"CFStringRef", "CFMutableStringRef",
|
||||||
"CFURLRef",
|
"CFURLRef",
|
||||||
|
## "CFPropertyListRef",
|
||||||
)
|
)
|
||||||
# ADD object typenames here
|
# ADD object typenames here
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ def main():
|
||||||
## "CFNumber.h",
|
## "CFNumber.h",
|
||||||
## "CFPlugIn.h",
|
## "CFPlugIn.h",
|
||||||
## "CFPreferences.h",
|
## "CFPreferences.h",
|
||||||
## "CFPropertyList.h",
|
"CFPropertyList.h",
|
||||||
## "CFSet.h",
|
## "CFSet.h",
|
||||||
"CFString.h",
|
"CFString.h",
|
||||||
## "CFStringEncodingExt.h",
|
## "CFStringEncodingExt.h",
|
||||||
|
|
@ -130,6 +131,9 @@ class MyScanner(Scanner_OSX):
|
||||||
([("CFURLRef", "baseURL", "InMode")],
|
([("CFURLRef", "baseURL", "InMode")],
|
||||||
[("OptionalCFURLRef", "*", "*")]),
|
[("OptionalCFURLRef", "*", "*")]),
|
||||||
|
|
||||||
|
# We handle CFPropertyListRef objects as plain CFTypeRef
|
||||||
|
([("CFPropertyListRef", "*", "*")],
|
||||||
|
[("CFTypeRef", "*", "*")]),
|
||||||
]
|
]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ includestuff = includestuff + """
|
||||||
#include <CFDictionary.h>
|
#include <CFDictionary.h>
|
||||||
#include <CFString.h>
|
#include <CFString.h>
|
||||||
#include <CFURL.h>
|
#include <CFURL.h>
|
||||||
|
#include <CFPropertyList.h>
|
||||||
#else
|
#else
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -195,6 +196,7 @@ CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")
|
||||||
CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
|
CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
|
||||||
CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
|
CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
|
||||||
OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
|
OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
|
||||||
|
##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj")
|
||||||
# ADD object type here
|
# ADD object type here
|
||||||
|
|
||||||
# Our (opaque) objects
|
# Our (opaque) objects
|
||||||
|
|
@ -301,6 +303,18 @@ class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
|
||||||
class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
|
class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
|
||||||
basechain = "&CFTypeRefObj_chain"
|
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):
|
def outputRepr(self):
|
||||||
Output()
|
Output()
|
||||||
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
|
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
|
||||||
|
|
@ -491,6 +505,21 @@ toPython_body = """
|
||||||
return PyCF_CF2Python(_self->ob_itself);
|
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 = ManualGenerator("toPython", toPython_body);
|
||||||
f.docstring = lambda: "() -> (python_object)"
|
f.docstring = lambda: "() -> (python_object)"
|
||||||
CFTypeRef_object.add(f)
|
CFTypeRef_object.add(f)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue