<s> import array <EOL> import datetime <EOL> import decimal <EOL> from ctypes import * <EOL> from ctypes import _Pointer <EOL> from _ctypes import CopyComPointer <EOL> from comtypes import IUnknown , GUID , IID , STDMETHOD , BSTR , COMMETHOD , COMError <EOL> from comtypes . hresult import * <EOL> from comtypes . patcher import Patch <EOL> from comtypes import npsupport <EOL> try : <EOL> from comtypes import _safearray <EOL> except ( ImportError , AttributeError ) : <EOL> class _safearray ( object ) : <EOL> tagSAFEARRAY = None <EOL> from ctypes . wintypes import DWORD , LONG , UINT , VARIANT_BOOL , WCHAR , WORD <EOL> LCID = DWORD <EOL> DISPID = LONG <EOL> SCODE = LONG <EOL> VARTYPE = c_ushort <EOL> DISPATCH_METHOD = <NUM_LIT:1> <EOL> DISPATCH_PROPERTYGET = <NUM_LIT:2> <EOL> DISPATCH_PROPERTYPUT = <NUM_LIT:4> <EOL> DISPATCH_PROPERTYPUTREF = <NUM_LIT:8> <EOL> tagINVOKEKIND = c_int <EOL> INVOKE_FUNC = DISPATCH_METHOD <EOL> INVOKE_PROPERTYGET = DISPATCH_PROPERTYGET <EOL> INVOKE_PROPERTYPUT = DISPATCH_PROPERTYPUT <EOL> INVOKE_PROPERTYPUTREF = DISPATCH_PROPERTYPUTREF <EOL> INVOKEKIND = tagINVOKEKIND <EOL> IID_NULL = GUID ( ) <EOL> riid_null = byref ( IID_NULL ) <EOL> _byref_type = type ( byref ( c_int ( ) ) ) <EOL> _com_null_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:30> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> VARENUM = c_int <EOL> VT_EMPTY = <NUM_LIT:0> <EOL> VT_NULL = <NUM_LIT:1> <EOL> VT_I2 = <NUM_LIT:2> <EOL> VT_I4 = <NUM_LIT:3> <EOL> VT_R4 = <NUM_LIT:4> <EOL> VT_R8 = <NUM_LIT:5> <EOL> VT_CY = <NUM_LIT:6> <EOL> VT_DATE = <NUM_LIT:7> <EOL> VT_BSTR = <NUM_LIT:8> <EOL> VT_DISPATCH = <NUM_LIT:9> <EOL> VT_ERROR = <NUM_LIT:10> <EOL> VT_BOOL = <NUM_LIT:11> <EOL> VT_VARIANT = <NUM_LIT:12> <EOL> VT_UNKNOWN = <NUM_LIT> <EOL> VT_DECIMAL = <NUM_LIT> <EOL> VT_I1 = <NUM_LIT:16> <EOL> VT_UI1 = <NUM_LIT> <EOL> VT_UI2 = <NUM_LIT> <EOL> VT_UI4 = <NUM_LIT> <EOL> VT_I8 = <NUM_LIT:20> <EOL> VT_UI8 = <NUM_LIT> <EOL> VT_INT = <NUM_LIT> <EOL> VT_UINT = <NUM_LIT> <EOL> VT_VOID = <NUM_LIT> <EOL> VT_HRESULT = <NUM_LIT> <EOL> VT_PTR = <NUM_LIT> <EOL> VT_SAFEARRAY = <NUM_LIT> <EOL> VT_CARRAY = <NUM_LIT> <EOL> VT_USERDEFINED = <NUM_LIT> <EOL> VT_LPSTR = <NUM_LIT:30> <EOL> VT_LPWSTR = <NUM_LIT> <EOL> VT_RECORD = <NUM_LIT> <EOL> VT_INT_PTR = <NUM_LIT> <EOL> VT_UINT_PTR = <NUM_LIT> <EOL> VT_FILETIME = <NUM_LIT:64> <EOL> VT_BLOB = <NUM_LIT> <EOL> VT_STREAM = <NUM_LIT> <EOL> VT_STORAGE = <NUM_LIT> <EOL> VT_STREAMED_OBJECT = <NUM_LIT> <EOL> VT_STORED_OBJECT = <NUM_LIT> <EOL> VT_BLOB_OBJECT = <NUM_LIT> <EOL> VT_CF = <NUM_LIT> <EOL> VT_CLSID = <NUM_LIT> <EOL> VT_VERSIONED_STREAM = <NUM_LIT> <EOL> VT_BSTR_BLOB = <NUM_LIT> <EOL> VT_VECTOR = <NUM_LIT> <EOL> VT_ARRAY = <NUM_LIT> <EOL> VT_BYREF = <NUM_LIT> <EOL> VT_RESERVED = <NUM_LIT> <EOL> VT_ILLEGAL = <NUM_LIT> <EOL> VT_ILLEGALMASKED = <NUM_LIT> <EOL> VT_TYPEMASK = <NUM_LIT> <EOL> class tagCY ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , c_longlong ) ] <EOL> CY = tagCY <EOL> CURRENCY = CY <EOL> class tagDEC ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , c_ushort ) , <EOL> ( "<STR_LIT>" , c_ubyte ) , <EOL> ( "<STR_LIT>" , c_ubyte ) , <EOL> ( "<STR_LIT>" , c_ulong ) , <EOL> ( "<STR_LIT>" , c_ulonglong ) ] <EOL> def as_decimal ( self ) : <EOL> """<STR_LIT>""" <EOL> digits = ( self . Hi32 << <NUM_LIT:64> ) + self . Lo64 <EOL> decimal_str = "<STR_LIT>" . format ( <EOL> '<STR_LIT:->' if self . sign else '<STR_LIT>' , <EOL> digits , <EOL> self . scale , <EOL> ) <EOL> return decimal . Decimal ( decimal_str ) <EOL> DECIMAL = tagDEC <EOL> class tagVARIANT ( Structure ) : <EOL> class U_VARIANT1 ( Union ) : <EOL> class __tagVARIANT ( Structure ) : <EOL> class U_VARIANT2 ( Union ) : <EOL> class _tagBRECORD ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , POINTER ( IUnknown ) ) ] <EOL> _fields_ = [ <EOL> ( "<STR_LIT>" , VARIANT_BOOL ) , <EOL> ( "<STR_LIT>" , c_byte ) , <EOL> ( "<STR_LIT>" , c_short ) , <EOL> ( "<STR_LIT>" , c_long ) , <EOL> ( "<STR_LIT>" , c_longlong ) , <EOL> ( "<STR_LIT>" , c_int ) , <EOL> ( "<STR_LIT>" , c_ubyte ) , <EOL> ( "<STR_LIT>" , c_ushort ) , <EOL> ( "<STR_LIT>" , c_ulong ) , <EOL> ( "<STR_LIT>" , c_ulonglong ) , <EOL> ( "<STR_LIT>" , c_uint ) , <EOL> ( "<STR_LIT>" , c_float ) , <EOL> ( "<STR_LIT>" , c_double ) , <EOL> ( "<STR_LIT>" , c_longlong ) , <EOL> ( "<STR_LIT>" , c_wchar_p ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , POINTER ( POINTER ( _safearray . tagSAFEARRAY ) ) ) , <EOL> ( "<STR_LIT>" , BSTR ) , <EOL> ( "<STR_LIT>" , _tagBRECORD ) , <EOL> ] <EOL> _anonymous_ = [ "<STR_LIT>" ] <EOL> _fields_ = [ ( "<STR_LIT>" , VARTYPE ) , <EOL> ( "<STR_LIT>" , c_ushort ) , <EOL> ( "<STR_LIT>" , c_ushort ) , <EOL> ( "<STR_LIT>" , c_ushort ) , <EOL> ( "<STR_LIT:_>" , U_VARIANT2 ) <EOL> ] <EOL> _fields_ = [ ( "<STR_LIT>" , __tagVARIANT ) , <EOL> ( "<STR_LIT>" , DECIMAL ) ] <EOL> _anonymous_ = [ "<STR_LIT>" ] <EOL> _fields_ = [ ( "<STR_LIT>" , U_VARIANT1 ) ] <EOL> _anonymous_ = [ "<STR_LIT>" ] <EOL> def __init__ ( self , * args ) : <EOL> if args : <EOL> self . value = args [ <NUM_LIT:0> ] <EOL> def __del__ ( self ) : <EOL> if self . _b_needsfree_ : <EOL> _VariantClear ( self ) <EOL> def __repr__ ( self ) : <EOL> if self . vt & VT_BYREF : <EOL> return "<STR_LIT>" % ( self . vt , self [ <NUM_LIT:0> ] ) <EOL> return "<STR_LIT>" % ( self . vt , self . value ) <EOL> def from_param ( cls , value ) : <EOL> if isinstance ( value , cls ) : <EOL> return value <EOL> return cls ( value ) <EOL> from_param = classmethod ( from_param ) <EOL> def __setitem__ ( self , index , value ) : <EOL> if index != <NUM_LIT:0> : <EOL> raise IndexError ( index ) <EOL> if not self . vt & VT_BYREF : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> typ = _vartype_to_ctype [ self . vt & ~ VT_BYREF ] <EOL> cast ( self . _ . c_void_p , POINTER ( typ ) ) [ <NUM_LIT:0> ] = value <EOL> def _set_value ( self , value ) : <EOL> _VariantClear ( self ) <EOL> if value is None : <EOL> self . vt = VT_NULL <EOL> elif ( hasattr ( value , '<STR_LIT>' ) and len ( value ) == <NUM_LIT:0> <EOL> and not isinstance ( value , basestring ) ) : <EOL> self . vt = VT_NULL <EOL> elif isinstance ( value , bool ) : <EOL> self . vt = VT_BOOL <EOL> self . _ . VT_BOOL = value <EOL> elif isinstance ( value , ( int , c_int ) ) : <EOL> self . vt = VT_I4 <EOL> self . _ . VT_I4 = value <EOL> elif isinstance ( value , long ) : <EOL> u = self . _ <EOL> u . VT_I4 = value <EOL> if u . VT_I4 == value : <EOL> self . vt = VT_I4 <EOL> return <EOL> if value >= <NUM_LIT:0> : <EOL> u . VT_UI4 = value <EOL> if u . VT_UI4 == value : <EOL> self . vt = VT_UI4 <EOL> return <EOL> if value >= <NUM_LIT:0> : <EOL> u . VT_I8 = value <EOL> if u . VT_I8 == value : <EOL> self . vt = VT_I8 <EOL> return <EOL> if value >= <NUM_LIT:0> : <EOL> u . VT_UI8 = value <EOL> if u . VT_UI8 == value : <EOL> self . vt = VT_UI8 <EOL> return <EOL> self . vt = VT_R8 <EOL> u . VT_R8 = float ( value ) <EOL> elif isinstance ( value , ( float , c_double ) ) : <EOL> self . vt = VT_R8 <EOL> self . _ . VT_R8 = value <EOL> elif isinstance ( value , ( str , unicode ) ) : <EOL> self . vt = VT_BSTR <EOL> self . _ . c_void_p = _SysAllocStringLen ( value , len ( value ) ) <EOL> elif isinstance ( value , datetime . datetime ) : <EOL> delta = value - _com_null_date <EOL> com_days = delta . days + ( delta . seconds + delta . microseconds * <NUM_LIT> ) / <NUM_LIT> <EOL> self . vt = VT_DATE <EOL> self . _ . VT_R8 = com_days <EOL> elif npsupport . isdatetime64 ( value ) : <EOL> com_days = value - npsupport . com_null_date64 <EOL> com_days /= npsupport . numpy . timedelta64 ( <NUM_LIT:1> , '<STR_LIT:D>' ) <EOL> self . vt = VT_DATE <EOL> self . _ . VT_R8 = com_days <EOL> elif decimal is not None and isinstance ( value , decimal . Decimal ) : <EOL> self . _ . VT_CY = int ( round ( value * <NUM_LIT> ) ) <EOL> self . vt = VT_CY <EOL> elif isinstance ( value , POINTER ( IDispatch ) ) : <EOL> CopyComPointer ( value , byref ( self . _ ) ) <EOL> self . vt = VT_DISPATCH <EOL> elif isinstance ( value , POINTER ( IUnknown ) ) : <EOL> CopyComPointer ( value , byref ( self . _ ) ) <EOL> self . vt = VT_UNKNOWN <EOL> elif isinstance ( value , ( list , tuple ) ) : <EOL> obj = _midlSAFEARRAY ( VARIANT ) . create ( value ) <EOL> memmove ( byref ( self . _ ) , byref ( obj ) , sizeof ( obj ) ) <EOL> self . vt = VT_ARRAY | obj . _vartype_ <EOL> elif isinstance ( value , array . array ) : <EOL> vartype = _arraycode_to_vartype [ value . typecode ] <EOL> typ = _vartype_to_ctype [ vartype ] <EOL> obj = _midlSAFEARRAY ( typ ) . create ( value ) <EOL> memmove ( byref ( self . _ ) , byref ( obj ) , sizeof ( obj ) ) <EOL> self . vt = VT_ARRAY | obj . _vartype_ <EOL> elif npsupport . isndarray ( value ) : <EOL> descr = value . dtype . descr [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> typ = npsupport . numpy . ctypeslib . _typecodes . get ( descr ) <EOL> if typ is None : <EOL> obj = _midlSAFEARRAY ( VARIANT ) . create ( value ) <EOL> else : <EOL> obj = _midlSAFEARRAY ( typ ) . create ( value ) <EOL> memmove ( byref ( self . _ ) , byref ( obj ) , sizeof ( obj ) ) <EOL> self . vt = VT_ARRAY | obj . _vartype_ <EOL> elif isinstance ( value , Structure ) and hasattr ( value , "<STR_LIT>" ) : <EOL> guids = value . _recordinfo_ <EOL> from comtypes . typeinfo import GetRecordInfoFromGuids <EOL> ri = GetRecordInfoFromGuids ( * guids ) <EOL> self . vt = VT_RECORD <EOL> ri . AddRef ( ) <EOL> self . _ . pRecInfo = ri <EOL> self . _ . pvRecord = ri . RecordCreateCopy ( byref ( value ) ) <EOL> elif isinstance ( getattr ( value , "<STR_LIT>" , None ) , POINTER ( IDispatch ) ) : <EOL> CopyComPointer ( value . _comobj , byref ( self . _ ) ) <EOL> self . vt = VT_DISPATCH <EOL> elif isinstance ( value , VARIANT ) : <EOL> _VariantCopy ( self , value ) <EOL> elif isinstance ( value , c_ubyte ) : <EOL> self . _ . VT_UI1 = value <EOL> self . vt = VT_UI1 <EOL> elif isinstance ( value , c_char ) : <EOL> self . _ . VT_UI1 = ord ( value . value ) <EOL> self . vt = VT_UI1 <EOL> elif isinstance ( value , c_byte ) : <EOL> self . _ . VT_I1 = value <EOL> self . vt = VT_I1 <EOL> elif isinstance ( value , c_ushort ) : <EOL> self . _ . VT_UI2 = value <EOL> self . vt = VT_UI2 <EOL> elif isinstance ( value , c_short ) : <EOL> self . _ . VT_I2 = value <EOL> self . vt = VT_I2 <EOL> elif isinstance ( value , c_uint ) : <EOL> self . vt = VT_UI4 <EOL> self . _ . VT_UI4 = value <EOL> elif isinstance ( value , c_float ) : <EOL> self . vt = VT_R4 <EOL> self . _ . VT_R4 = value <EOL> elif isinstance ( value , c_int64 ) : <EOL> self . vt = VT_I8 <EOL> self . _ . VT_I8 = value <EOL> elif isinstance ( value , c_uint64 ) : <EOL> self . vt = VT_UI8 <EOL> self . _ . VT_UI8 = value <EOL> elif isinstance ( value , _byref_type ) : <EOL> ref = value . _obj <EOL> self . _ . c_void_p = addressof ( ref ) <EOL> self . __keepref = value <EOL> self . vt = _ctype_to_vartype [ type ( ref ) ] | VT_BYREF <EOL> elif isinstance ( value , _Pointer ) : <EOL> ref = value . contents <EOL> self . _ . c_void_p = addressof ( ref ) <EOL> self . __keepref = value <EOL> self . vt = _ctype_to_vartype [ type ( ref ) ] | VT_BYREF <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % value ) <EOL> def _get_value ( self , dynamic = False ) : <EOL> vt = self . vt <EOL> if vt in ( VT_EMPTY , VT_NULL ) : <EOL> return None <EOL> elif vt == VT_I1 : <EOL> return self . _ . VT_I1 <EOL> elif vt == VT_I2 : <EOL> return self . _ . VT_I2 <EOL> elif vt == VT_I4 : <EOL> return self . _ . VT_I4 <EOL> elif vt == VT_I8 : <EOL> return self . _ . VT_I8 <EOL> elif vt == VT_UI8 : <EOL> return self . _ . VT_UI8 <EOL> elif vt == VT_INT : <EOL> return self . _ . VT_INT <EOL> elif vt == VT_UI1 : <EOL> return self . _ . VT_UI1 <EOL> elif vt == VT_UI2 : <EOL> return self . _ . VT_UI2 <EOL> elif vt == VT_UI4 : <EOL> return self . _ . VT_UI4 <EOL> elif vt == VT_UINT : <EOL> return self . _ . VT_UINT <EOL> elif vt == VT_R4 : <EOL> return self . _ . VT_R4 <EOL> elif vt == VT_R8 : <EOL> return self . _ . VT_R8 <EOL> elif vt == VT_BOOL : <EOL> return self . _ . VT_BOOL <EOL> elif vt == VT_BSTR : <EOL> return self . _ . bstrVal <EOL> elif vt == VT_DATE : <EOL> days = self . _ . VT_R8 <EOL> return datetime . timedelta ( days = days ) + _com_null_date <EOL> elif vt == VT_CY : <EOL> return self . _ . VT_CY / decimal . Decimal ( "<STR_LIT>" ) <EOL> elif vt == VT_UNKNOWN : <EOL> val = self . _ . c_void_p <EOL> if not val : <EOL> return None <EOL> ptr = cast ( val , POINTER ( IUnknown ) ) <EOL> ptr . AddRef ( ) <EOL> return ptr . __ctypes_from_outparam__ ( ) <EOL> elif vt == VT_DECIMAL : <EOL> return self . decVal . as_decimal ( ) <EOL> elif vt == VT_DISPATCH : <EOL> val = self . _ . c_void_p <EOL> if not val : <EOL> return None <EOL> ptr = cast ( val , POINTER ( IDispatch ) ) <EOL> ptr . AddRef ( ) <EOL> if not dynamic : <EOL> return ptr . __ctypes_from_outparam__ ( ) <EOL> else : <EOL> from comtypes . client . dynamic import Dispatch <EOL> return Dispatch ( ptr ) <EOL> elif self . vt & VT_BYREF : <EOL> return self <EOL> elif vt == VT_RECORD : <EOL> from comtypes . client import GetModule <EOL> from comtypes . typeinfo import IRecordInfo <EOL> punk = self . _ . pRecInfo <EOL> punk . AddRef ( ) <EOL> ri = punk . QueryInterface ( IRecordInfo ) <EOL> tlib = ri . GetTypeInfo ( ) . GetContainingTypeLib ( ) [ <NUM_LIT:0> ] <EOL> mod = GetModule ( tlib ) <EOL> value = getattr ( mod , ri . GetName ( ) ) ( ) <EOL> ri . RecordCopy ( self . _ . pvRecord , byref ( value ) ) <EOL> return value <EOL> elif self . vt & VT_ARRAY : <EOL> typ = _vartype_to_ctype [ self . vt & ~ VT_ARRAY ] <EOL> return cast ( self . _ . pparray , _midlSAFEARRAY ( typ ) ) . unpack ( ) <EOL> else : <EOL> raise NotImplementedError ( "<STR_LIT>" % ( vt , vt ) ) <EOL> def __getitem__ ( self , index ) : <EOL> if index != <NUM_LIT:0> : <EOL> raise IndexError ( index ) <EOL> if self . vt == VT_BYREF | VT_VARIANT : <EOL> v = VARIANT ( ) <EOL> v = cast ( self . _ . c_void_p , POINTER ( VARIANT ) ) [ <NUM_LIT:0> ] <EOL> return v . value <EOL> else : <EOL> v = VARIANT ( ) <EOL> _VariantCopyInd ( v , self ) <EOL> return v . value <EOL> value = property ( _get_value , _set_value ) <EOL> def __ctypes_from_outparam__ ( self ) : <EOL> result = self . value <EOL> self . value = None <EOL> return result <EOL> def ChangeType ( self , typecode ) : <EOL> _VariantChangeType ( self , <EOL> self , <EOL> <NUM_LIT:0> , <EOL> typecode ) <EOL> VARIANT = tagVARIANT <EOL> VARIANTARG = VARIANT <EOL> _oleaut32 = OleDLL ( "<STR_LIT>" ) <EOL> _VariantChangeType = _oleaut32 . VariantChangeType <EOL> _VariantChangeType . argtypes = ( POINTER ( VARIANT ) , POINTER ( VARIANT ) , c_ushort , VARTYPE ) <EOL> _VariantClear = _oleaut32 . VariantClear <EOL> _VariantClear . argtypes = ( POINTER ( VARIANT ) , ) <EOL> _SysAllocStringLen = windll . oleaut32 . SysAllocStringLen <EOL> _SysAllocStringLen . argtypes = c_wchar_p , c_uint <EOL> _SysAllocStringLen . restype = c_void_p <EOL> _VariantCopy = _oleaut32 . VariantCopy <EOL> _VariantCopy . argtypes = POINTER ( VARIANT ) , POINTER ( VARIANT ) <EOL> _VariantCopyInd = _oleaut32 . VariantCopyInd <EOL> _VariantCopyInd . argtypes = POINTER ( VARIANT ) , POINTER ( VARIANT ) <EOL> VARIANT . null = VARIANT ( None ) <EOL> VARIANT . empty = VARIANT ( ) <EOL> VARIANT . missing = v = VARIANT ( ) <EOL> v . vt = VT_ERROR <EOL> v . _ . VT_I4 = <NUM_LIT> L <EOL> del v <EOL> _carg_obj = type ( byref ( c_int ( ) ) ) <EOL> from _ctypes import Array as _CArrayType <EOL> @ Patch ( POINTER ( VARIANT ) ) <EOL> class _ ( object ) : <EOL> def from_param ( cls , arg ) : <EOL> if isinstance ( arg , POINTER ( VARIANT ) ) : <EOL> return arg <EOL> if isinstance ( arg , _carg_obj ) and isinstance ( arg . _obj , VARIANT ) : <EOL> return arg <EOL> if isinstance ( arg , VARIANT ) : <EOL> return byref ( arg ) <EOL> if isinstance ( arg , _CArrayType ) and arg . _type_ is VARIANT : <EOL> return arg <EOL> return byref ( VARIANT ( arg ) ) <EOL> from_param = classmethod ( from_param ) <EOL> def __setitem__ ( self , index , value ) : <EOL> self [ index ] . value = value <EOL> class IEnumVARIANT ( IUnknown ) : <EOL> _iid_ = GUID ( '<STR_LIT>' ) <EOL> _idlflags_ = [ '<STR_LIT>' ] <EOL> _dynamic = False <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> item , fetched = self . Next ( <NUM_LIT:1> ) <EOL> if fetched : <EOL> return item <EOL> raise StopIteration <EOL> def __getitem__ ( self , index ) : <EOL> self . Reset ( ) <EOL> self . Skip ( index ) <EOL> item , fetched = self . Next ( <NUM_LIT:1> ) <EOL> if fetched : <EOL> return item <EOL> raise IndexError <EOL> def Next ( self , celt ) : <EOL> fetched = c_ulong ( ) <EOL> if celt == <NUM_LIT:1> : <EOL> v = VARIANT ( ) <EOL> self . __com_Next ( celt , v , fetched ) <EOL> return v . _get_value ( dynamic = self . _dynamic ) , fetched . value <EOL> array = ( VARIANT * celt ) ( ) <EOL> self . __com_Next ( celt , array , fetched ) <EOL> result = [ v . _get_value ( dynamic = self . _dynamic ) for v in array [ : fetched . value ] ] <EOL> for v in array : <EOL> v . value = None <EOL> return result <EOL> IEnumVARIANT . _methods_ = [ <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , c_ulong , '<STR_LIT>' ) , <EOL> ( [ '<STR_LIT>' ] , POINTER ( VARIANT ) , '<STR_LIT>' ) , <EOL> ( [ '<STR_LIT>' ] , POINTER ( c_ulong ) , '<STR_LIT>' ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , c_ulong , '<STR_LIT>' ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( POINTER ( IEnumVARIANT ) ) , '<STR_LIT>' ) ) , <EOL> ] <EOL> class tagEXCEPINFO ( Structure ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( ( self . wCode , self . bstrSource , self . bstrDescription , self . bstrHelpFile , self . dwHelpContext , <EOL> self . pfnDeferredFillIn , self . scode ) , ) <EOL> tagEXCEPINFO . _fields_ = [ <EOL> ( '<STR_LIT>' , WORD ) , <EOL> ( '<STR_LIT>' , WORD ) , <EOL> ( '<STR_LIT>' , BSTR ) , <EOL> ( '<STR_LIT>' , BSTR ) , <EOL> ( '<STR_LIT>' , BSTR ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , SCODE ) , <EOL> ] <EOL> EXCEPINFO = tagEXCEPINFO <EOL> class tagDISPPARAMS ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , POINTER ( VARIANTARG ) ) , <EOL> ( '<STR_LIT>' , POINTER ( DISPID ) ) , <EOL> ( '<STR_LIT>' , UINT ) , <EOL> ( '<STR_LIT>' , UINT ) , <EOL> ] <EOL> def __del__ ( self ) : <EOL> if self . _b_needsfree_ : <EOL> for i in range ( self . cArgs ) : <EOL> self . rgvarg [ i ] . value = None <EOL> DISPPARAMS = tagDISPPARAMS <EOL> DISPID_VALUE = <NUM_LIT:0> <EOL> DISPID_UNKNOWN = - <NUM_LIT:1> <EOL> DISPID_PROPERTYPUT = - <NUM_LIT:3> <EOL> DISPID_NEWENUM = - <NUM_LIT:4> <EOL> DISPID_EVALUATE = - <NUM_LIT:5> <EOL> DISPID_CONSTRUCTOR = - <NUM_LIT:6> <EOL> DISPID_DESTRUCTOR = - <NUM_LIT:7> <EOL> DISPID_COLLECT = - <NUM_LIT:8> <EOL> class IDispatch ( IUnknown ) : <EOL> _iid_ = GUID ( "<STR_LIT>" ) <EOL> _methods_ = [ <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( UINT ) ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , UINT , '<STR_LIT:index>' ) , <EOL> ( [ '<STR_LIT>' ] , LCID , '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( [ '<STR_LIT>' ] , POINTER ( POINTER ( IUnknown ) ) ) ) , <EOL> STDMETHOD ( HRESULT , '<STR_LIT>' , [ POINTER ( IID ) , POINTER ( c_wchar_p ) , <EOL> UINT , LCID , POINTER ( DISPID ) ] ) , <EOL> STDMETHOD ( HRESULT , '<STR_LIT>' , [ DISPID , POINTER ( IID ) , LCID , WORD , <EOL> POINTER ( DISPPARAMS ) , POINTER ( VARIANT ) , <EOL> POINTER ( EXCEPINFO ) , POINTER ( UINT ) ] ) , <EOL> ] <EOL> def GetTypeInfo ( self , index , lcid = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> import comtypes . typeinfo <EOL> result = self . _GetTypeInfo ( index , lcid ) <EOL> return result . QueryInterface ( comtypes . typeinfo . ITypeInfo ) <EOL> def GetIDsOfNames ( self , * names , ** kw ) : <EOL> """<STR_LIT>""" <EOL> lcid = kw . pop ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> assert not kw <EOL> arr = ( c_wchar_p * len ( names ) ) ( * names ) <EOL> ids = ( DISPID * len ( names ) ) ( ) <EOL> self . __com_GetIDsOfNames ( riid_null , arr , len ( names ) , lcid , ids ) <EOL> return ids [ : ] <EOL> def _invoke ( self , memid , invkind , lcid , * args ) : <EOL> var = VARIANT ( ) <EOL> argerr = c_uint ( ) <EOL> dp = DISPPARAMS ( ) <EOL> if args : <EOL> array = ( VARIANT * len ( args ) ) ( ) <EOL> for i , a in enumerate ( args [ : : - <NUM_LIT:1> ] ) : <EOL> array [ i ] . value = a <EOL> dp . cArgs = len ( args ) <EOL> if invkind in ( DISPATCH_PROPERTYPUT , DISPATCH_PROPERTYPUTREF ) : <EOL> dp . cNamedArgs = <NUM_LIT:1> <EOL> dp . rgdispidNamedArgs = pointer ( DISPID ( DISPID_PROPERTYPUT ) ) <EOL> dp . rgvarg = array <EOL> self . __com_Invoke ( memid , riid_null , lcid , invkind , <EOL> dp , var , None , argerr ) <EOL> return var . _get_value ( dynamic = True ) <EOL> def Invoke ( self , dispid , * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> _invkind = kw . pop ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> _lcid = kw . pop ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> if kw : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> result = VARIANT ( ) <EOL> excepinfo = EXCEPINFO ( ) <EOL> argerr = c_uint ( ) <EOL> if _invkind in ( DISPATCH_PROPERTYPUT , DISPATCH_PROPERTYPUTREF ) : <EOL> array = ( VARIANT * len ( args ) ) ( ) <EOL> for i , a in enumerate ( args [ : : - <NUM_LIT:1> ] ) : <EOL> array [ i ] . value = a <EOL> dp = DISPPARAMS ( ) <EOL> dp . cArgs = len ( args ) <EOL> dp . cNamedArgs = <NUM_LIT:1> <EOL> dp . rgvarg = array <EOL> dp . rgdispidNamedArgs = pointer ( DISPID ( DISPID_PROPERTYPUT ) ) <EOL> else : <EOL> array = ( VARIANT * len ( args ) ) ( ) <EOL> for i , a in enumerate ( args [ : : - <NUM_LIT:1> ] ) : <EOL> array [ i ] . value = a <EOL> dp = DISPPARAMS ( ) <EOL> dp . cArgs = len ( args ) <EOL> dp . cNamedArgs = <NUM_LIT:0> <EOL> dp . rgvarg = array <EOL> try : <EOL> self . __com_Invoke ( dispid , riid_null , _lcid , _invkind , byref ( dp ) , <EOL> byref ( result ) , byref ( excepinfo ) , byref ( argerr ) ) <EOL> except COMError , err : <EOL> ( hresult , text , details ) = err . args <EOL> if hresult == DISP_E_EXCEPTION : <EOL> details = ( excepinfo . bstrDescription , excepinfo . bstrSource , <EOL> excepinfo . bstrHelpFile , excepinfo . dwHelpContext , <EOL> excepinfo . scode ) <EOL> raise COMError ( hresult , text , details ) <EOL> elif hresult == DISP_E_PARAMNOTFOUND : <EOL> raise COMError ( hresult , text , argerr . value ) <EOL> elif hresult == DISP_E_TYPEMISMATCH : <EOL> raise COMError ( hresult , text , <EOL> ( "<STR_LIT>" % ( argerr . value + <NUM_LIT:1> ) , <EOL> args ) ) <EOL> raise <EOL> return result . _get_value ( dynamic = True ) <EOL> _arraycode_to_vartype = { <EOL> "<STR_LIT:d>" : VT_R8 , <EOL> "<STR_LIT:f>" : VT_R4 , <EOL> "<STR_LIT:l>" : VT_I4 , <EOL> "<STR_LIT:i>" : VT_INT , <EOL> "<STR_LIT:h>" : VT_I2 , <EOL> "<STR_LIT:b>" : VT_I1 , <EOL> "<STR_LIT:I>" : VT_UINT , <EOL> "<STR_LIT:L>" : VT_UI4 , <EOL> "<STR_LIT:H>" : VT_UI2 , <EOL> "<STR_LIT:B>" : VT_UI1 , <EOL> } <EOL> _ctype_to_vartype = { <EOL> c_byte : VT_I1 , <EOL> c_ubyte : VT_UI1 , <EOL> c_short : VT_I2 , <EOL> c_ushort : VT_UI2 , <EOL> c_long : VT_I4 , <EOL> c_ulong : VT_UI4 , <EOL> c_float : VT_R4 , <EOL> c_double : VT_R8 , <EOL> c_longlong : VT_I8 , <EOL> c_ulonglong : VT_UI8 , <EOL> VARIANT_BOOL : VT_BOOL , <EOL> BSTR : VT_BSTR , <EOL> VARIANT : VT_VARIANT , <EOL> POINTER ( VARIANT ) : VT_BYREF | VT_VARIANT , <EOL> POINTER ( BSTR ) : VT_BYREF | VT_BSTR , <EOL> } <EOL> _vartype_to_ctype = { } <EOL> for c , v in _ctype_to_vartype . iteritems ( ) : <EOL> _vartype_to_ctype [ v ] = c <EOL> _vartype_to_ctype [ VT_INT ] = _vartype_to_ctype [ VT_I4 ] <EOL> _vartype_to_ctype [ VT_UINT ] = _vartype_to_ctype [ VT_UI4 ] <EOL> _ctype_to_vartype [ c_char ] = VT_UI1 <EOL> try : <EOL> from comtypes . safearray import _midlSAFEARRAY <EOL> except ( ImportError , AttributeError ) : <EOL> pass </s>
