<s> import sys <EOL> from ctypes import * <EOL> from comtypes import IUnknown , HRESULT , COMMETHOD , GUID , BSTR <EOL> from comtypes . hresult import * <EOL> LPCOLESTR = c_wchar_p <EOL> DWORD = c_ulong <EOL> class ICreateErrorInfo ( IUnknown ) : <EOL> _iid_ = GUID ( "<STR_LIT>" ) <EOL> _methods_ = [ <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( GUID ) , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , LPCOLESTR , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , LPCOLESTR , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , LPCOLESTR , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , DWORD , "<STR_LIT>" ) ) <EOL> ] <EOL> class IErrorInfo ( IUnknown ) : <EOL> _iid_ = GUID ( "<STR_LIT>" ) <EOL> _methods_ = [ <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( GUID ) , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( BSTR ) , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( BSTR ) , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( BSTR ) , "<STR_LIT>" ) ) , <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( DWORD ) , "<STR_LIT>" ) ) , <EOL> ] <EOL> class ISupportErrorInfo ( IUnknown ) : <EOL> _iid_ = GUID ( "<STR_LIT>" ) <EOL> _methods_ = [ <EOL> COMMETHOD ( [ ] , HRESULT , '<STR_LIT>' , <EOL> ( [ '<STR_LIT>' ] , POINTER ( GUID ) , '<STR_LIT>' ) ) <EOL> ] <EOL> _oleaut32 = oledll . oleaut32 <EOL> def CreateErrorInfo ( ) : <EOL> cei = POINTER ( ICreateErrorInfo ) ( ) <EOL> _oleaut32 . CreateErrorInfo ( byref ( cei ) ) <EOL> return cei <EOL> def GetErrorInfo ( ) : <EOL> """<STR_LIT>""" <EOL> errinfo = POINTER ( IErrorInfo ) ( ) <EOL> if S_OK == _oleaut32 . GetErrorInfo ( <NUM_LIT:0> , byref ( errinfo ) ) : <EOL> return errinfo <EOL> return None <EOL> def SetErrorInfo ( errinfo ) : <EOL> """<STR_LIT>""" <EOL> return _oleaut32 . SetErrorInfo ( <NUM_LIT:0> , errinfo ) <EOL> def ReportError ( text , iid , <EOL> clsid = None , helpfile = None , helpcontext = <NUM_LIT:0> , hresult = DISP_E_EXCEPTION ) : <EOL> """<STR_LIT>""" <EOL> ei = CreateErrorInfo ( ) <EOL> ei . SetDescription ( text ) <EOL> ei . SetGUID ( iid ) <EOL> if helpfile is not None : <EOL> ei . SetHelpFile ( helpfile ) <EOL> if helpcontext is not None : <EOL> ei . SetHelpContext ( helpcontext ) <EOL> if clsid is not None : <EOL> if isinstance ( clsid , basestring ) : <EOL> clsid = GUID ( clsid ) <EOL> try : <EOL> progid = clsid . as_progid ( ) <EOL> except WindowsError : <EOL> pass <EOL> else : <EOL> ei . SetSource ( progid ) <EOL> _oleaut32 . SetErrorInfo ( <NUM_LIT:0> , ei ) <EOL> return hresult <EOL> def ReportException ( hresult , iid , clsid = None , helpfile = None , helpcontext = None , <EOL> stacklevel = None ) : <EOL> """<STR_LIT>""" <EOL> typ , value , tb = sys . exc_info ( ) <EOL> if stacklevel is not None : <EOL> for _ in range ( stacklevel ) : <EOL> tb = tb . tb_next <EOL> line = tb . tb_frame . f_lineno <EOL> name = tb . tb_frame . f_globals [ "<STR_LIT>" ] <EOL> text = "<STR_LIT>" % ( typ , value , name , line ) <EOL> else : <EOL> text = "<STR_LIT>" % ( typ , value ) <EOL> return ReportError ( text , iid , <EOL> clsid = clsid , helpfile = helpfile , helpcontext = helpcontext , <EOL> hresult = hresult ) <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] </s>
