1'''
2Python mapping for the CoreFoundation framework.
3
4This module does not contain docstrings for the wrapped code, check Apple's
5documentation for details on how to use these functions and classes.
6'''
7
8import objc as _objc
9
10import  CoreFoundation._inlines
11
12__bundle__ = _objc.initFrameworkWrapper("CoreFoundation",
13    frameworkIdentifier="com.apple.CoreFoundation",
14    frameworkPath=_objc.pathForFramework(
15        "/System/Library/Frameworks/CoreFoundation.framework"),
16    globals=globals(),
17    scan_classes=False)
18
19#from CoreFoundation._CFArray import *
20from CoreFoundation._CFBag import *
21from CoreFoundation._CFBinaryHeap import *
22from CoreFoundation._CFBitVector import *
23
24from CoreFoundation._CFCalendar import *
25from CoreFoundation._CFDictionary import *
26from CoreFoundation._CFTree import *
27from CoreFoundation._CFFileDescriptor import *
28from CoreFoundation._CFMachPort import *
29from CoreFoundation._CFMessagePort import *
30from CoreFoundation._CFNumber import *
31from CoreFoundation._CFReadStream import *
32from CoreFoundation._CFRunLoopObserver import *
33from CoreFoundation._CFRunLoopTimer import *
34from CoreFoundation._CFWriteStream import *
35from CoreFoundation._CFRunLoopObserver import *
36from CoreFoundation._CFRunLoopSource import *
37from CoreFoundation._CFRunLoopTimer import *
38from CoreFoundation._CFSet import *
39from CoreFoundation._CFSocket import *
40
41#
42# 'Emulation' for CFArray contructors
43#
44def _setup():
45    NSArray = objc.lookUpClass('NSArray')
46    NSMutableArray = objc.lookUpClass('NSMutableArray')
47
48    def CFArrayCreate(allocator, values, numvalues, callbacks):
49        assert callbacks is None
50        return NSArray.alloc().initWithArray_(values[:numvalues])
51
52    def CFArrayCreateMutable(allocator, capacity, callbacks):
53        assert callbacks is None
54        return NSMutableArray.alloc().init()
55
56    return CFArrayCreate, CFArrayCreateMutable
57
58
59CFArrayCreate, CFArrayCreateMutable = _setup()
60
61
62# CFDictionary emulation functions
63
64def _setup():
65    NSDictionary = objc.lookUpClass('NSDictionary')
66    NSMutableDictionary = objc.lookUpClass('NSMutableDictionary')
67    def CFDictionaryCreate(allocator, keys, values, numValues,
68            keyCallbacks, valueCallbacks):
69        assert keyCallbacks is None
70        assert valueCallbacks is None
71
72        keys = list(keys)[:numValues]
73        values = list(values)[:numValues]
74
75        return NSDictionary.dictionaryWithDictionary_(dict(zip(keys, values)))
76
77    def CFDictionaryCreateMutable(allocator, capacity, keyCallbacks, valueCallbacks):
78        assert keyCallbacks is None
79        assert valueCallbacks is None
80
81        return NSMutableDictionary.dictionary()
82
83    return CFDictionaryCreate, CFDictionaryCreateMutable
84
85CFDictionaryCreate, CFDictionaryCreateMutable = _setup()
86
87
88
89# CFSet emulation functions
90
91def _setup():
92    NSSet = objc.lookUpClass('NSSet')
93    NSMutableSet = objc.lookUpClass('NSMutableSet')
94
95    def CFSetCreate(allocator, values, numvalues, callbacks):
96        assert callbacks is None
97        return NSSet.alloc().initWithArray_(values[:numvalues])
98
99    def CFSetCreateMutable(allocator, capacity, callbacks):
100        assert callbacks is None
101        return NSMutableSet.alloc().init()
102
103    return CFSetCreate, CFSetCreateMutable
104
105CFSetCreate, CFSetCreateMutable = _setup()
106
107kCFTypeArrayCallBacks = None
108kCFTypeDictionaryKeyCallBacks  = None
109kCFTypeDictionaryValueCallBacks = None
110kCFTypeSetCallBacks = None
111
112
113#
114# Implementation of a number of macro's in the CFBundle API
115#
116
117def CFCopyLocalizedString(key, comment):
118    return CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), None)
119
120def CFCopyLocalizedStringFromTable(key, tbl, comment):
121    return CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), (tbl))
122
123def CFCopyLocalizedStringFromTableInBundle(key, tbl, bundle, comment):
124    return CFBundleCopyLocalizedString((bundle), (key), (key), (tbl))
125
126def CFCopyLocalizedStringWithDefaultValue(key, tbl, bundle, value, comment):
127    return CFBundleCopyLocalizedString((bundle), (key), (value), (tbl))
128
129
130
131def CFSTR(strval):
132    return objc.lookUpClass('NSString').stringWithString_(strval)
133