1 | # Various utilities for working with nsISupportsPrimitive
|
---|
2 | from xpcom import components
|
---|
3 |
|
---|
4 | _primitives_map = {}
|
---|
5 |
|
---|
6 | def _build_map():
|
---|
7 | ifaces = components.interfaces
|
---|
8 | iface = ifaces.nsISupportsPrimitive
|
---|
9 | m = _primitives_map
|
---|
10 |
|
---|
11 | m[iface.TYPE_ID] = ifaces.nsISupportsID
|
---|
12 | m[iface.TYPE_CSTRING] = ifaces.nsISupportsCString
|
---|
13 | m[iface.TYPE_STRING] = ifaces.nsISupportsString
|
---|
14 | m[iface.TYPE_PRBOOL] = ifaces.nsISupportsPRBool
|
---|
15 | m[iface.TYPE_PRUINT8] = ifaces.nsISupportsPRUint8
|
---|
16 | m[iface.TYPE_PRUINT16] = ifaces.nsISupportsPRUint16
|
---|
17 | m[iface.TYPE_PRUINT32] = ifaces.nsISupportsPRUint32
|
---|
18 | m[iface.TYPE_PRUINT64] = ifaces.nsISupportsPRUint64
|
---|
19 | m[iface.TYPE_PRINT16] = ifaces.nsISupportsPRInt16
|
---|
20 | m[iface.TYPE_PRINT32] = ifaces.nsISupportsPRInt32
|
---|
21 | m[iface.TYPE_PRINT64] = ifaces.nsISupportsPRInt64
|
---|
22 | m[iface.TYPE_PRTIME] = ifaces.nsISupportsPRTime
|
---|
23 | m[iface.TYPE_CHAR] = ifaces.nsISupportsChar
|
---|
24 | m[iface.TYPE_FLOAT] = ifaces.nsISupportsFloat
|
---|
25 | m[iface.TYPE_DOUBLE] = ifaces.nsISupportsDouble
|
---|
26 | # Do interface pointer specially - it provides the IID.
|
---|
27 | #m[iface.TYPE_INTERFACE_POINTER] = ifaces.nsISupportsDouble
|
---|
28 |
|
---|
29 | def GetPrimitive(ob):
|
---|
30 | if len(_primitives_map)==0:
|
---|
31 | _build_map()
|
---|
32 |
|
---|
33 | prin = ob.QueryInterface(components.interfaces.nsISupportsPrimitive)
|
---|
34 | try:
|
---|
35 | better = _primitives_map[prin.type]
|
---|
36 | except KeyError:
|
---|
37 | raise ValueError, "This primitive type (%d) is not supported" % (prin.type,)
|
---|
38 | prin = prin.QueryInterface(better)
|
---|
39 | return prin.data
|
---|