1 #Copyright (c) 2009 Vincent Povirk
3 #Permission is hereby granted, free of charge, to any person
4 #obtaining a copy of this software and associated documentation
5 #files (the "Software"), to deal in the Software without
6 #restriction, including without limitation the rights to use,
7 #copy, modify, merge, publish, distribute, sublicense, and/or sell
8 #copies of the Software, and to permit persons to whom the
9 #Software is furnished to do so, subject to the following
12 #The above copyright notice and this permission notice shall be
13 #included in all copies or substantial portions of the Software.
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 #OTHER DEALINGS IN THE SOFTWARE.
24 # variant and related types
26 from ctypes
import Structure
, c_void_p
, windll
, POINTER
, HRESULT
, byref
27 from windef
import USHORT
, WORD
28 from winliteutils
import get_symbols
70 VT_STREAMED_OBJECT
= 68
75 VT_VERSIONED_STREAM
= 73
82 VT_ILLEGALMASKED
= 0x0fff
85 _oleaut32
= windll
.oleaut32
86 get_symbols(globals(), _oleaut32
, ['VariantClear', 'VariantInit'])
88 class _VARIANT_VAL(Structure
):
89 _fields_
= [('p1', c_void_p
),
93 class VARIANT(Structure
):
94 _fields_
= [('vt', VARTYPE
),
98 ('_value', _VARIANT_VAL
),
102 VariantInit(byref(self
))
104 def _set_value(self
, value
):
106 setter
= value
.__setvariant
__
107 except AttributeError:
109 setter
= _variant_setters
[type(value
)]
111 raise TypeError("variable of type %s cannot be converted to variant" % str(type(value
)))
113 setter
[0](self
, value
, *setter
[1:])
117 def _get_value(self
):
119 getter
= _variant_getters
[self
.vt
]
121 raise TypeError("getting variant type %s not supported" % self
.vt
)
123 return getter
[0](self
, *getter
[1:])
125 value
= property(_get_value
, _set_value
)
128 VariantClear(byref(self
))
131 LPVARIANTARG
= LPVARIANT
= POINTER(VARIANT
)
133 VariantClear
.argtypes
= [LPVARIANTARG
]
134 VariantClear
.restype
= HRESULT
136 VariantInit
.argtypes
= [LPVARIANTARG
]
137 VariantInit
.restype
= None
139 def _get_empty(variant
):
142 def _set_empty(variant
, value
):
143 VariantClear(byref(var
))
145 class _SQL_NULL(object):
146 def __setvariant__(self
, var
):
147 VariantClear(byref(var
))
150 sql_null
= _SQL_NULL()
152 def _get_null(variant
):
156 VT_EMPTY
: (_get_empty
,),
157 VT_NULL
: (_get_null
,),
161 type(None): (_set_empty
,),