Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d207c0

Browse files
committed
- Get data from CFData objects as Python strings and vv.
- Started on supporting CFPropertyLists.
1 parent e037665 commit 6d207c0

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

Mac/Modules/cf/cfscan.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"CFDictionaryRef", "CFMutableDictionaryRef",
1616
"CFStringRef", "CFMutableStringRef",
1717
"CFURLRef",
18+
## "CFPropertyListRef",
1819
)
1920
# ADD object typenames here
2021

@@ -31,7 +32,7 @@ def main():
3132
## "CFNumber.h",
3233
## "CFPlugIn.h",
3334
## "CFPreferences.h",
34-
## "CFPropertyList.h",
35+
"CFPropertyList.h",
3536
## "CFSet.h",
3637
"CFString.h",
3738
## "CFStringEncodingExt.h",
@@ -130,6 +131,9 @@ def makerepairinstructions(self):
130131
([("CFURLRef", "baseURL", "InMode")],
131132
[("OptionalCFURLRef", "*", "*")]),
132133

134+
# We handle CFPropertyListRef objects as plain CFTypeRef
135+
([("CFPropertyListRef", "*", "*")],
136+
[("CFTypeRef", "*", "*")]),
133137
]
134138

135139
if __name__ == "__main__":

Mac/Modules/cf/cfsupport.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def parseArgumentList(self, args):
4949
#include <CFDictionary.h>
5050
#include <CFString.h>
5151
#include <CFURL.h>
52+
#include <CFPropertyList.h>
5253
#else
5354
#include <CoreServices/CoreServices.h>
5455
#endif
@@ -195,6 +196,7 @@ def parseArgumentList(self, args):
195196
CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
196197
CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
197198
OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
199+
##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj")
198200
# ADD object type here
199201

200202
# Our (opaque) objects
@@ -301,6 +303,18 @@ def outputRepr(self):
301303
class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
302304
basechain = "&CFTypeRefObj_chain"
303305

306+
def outputCheckConvertArg(self):
307+
Out("""
308+
if (v == Py_None) { *p_itself = NULL; return 1; }
309+
if (PyString_Check(v)) {
310+
char *cStr;
311+
int cLen;
312+
if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
313+
*p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
314+
return 1;
315+
}
316+
""")
317+
304318
def outputRepr(self):
305319
Output()
306320
Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
@@ -491,6 +505,21 @@ def outputRepr(self):
491505
return PyCF_CF2Python(_self->ob_itself);
492506
"""
493507

508+
# Get data from CFDataRef
509+
getasdata_body = """
510+
int size = CFDataGetLength(_self->ob_itself);
511+
char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
512+
513+
_res = (PyObject *)PyString_FromStringAndSize(data, size);
514+
return _res;
515+
"""
516+
517+
f = ManualGenerator("CFDataGetData", getasdata_body);
518+
f.docstring = lambda: "() -> (string _rv)"
519+
CFDataRef_object.add(f)
520+
521+
522+
494523
f = ManualGenerator("toPython", toPython_body);
495524
f.docstring = lambda: "() -> (python_object)"
496525
CFTypeRef_object.add(f)

0 commit comments

Comments
 (0)