コード例 #1
0
    def call_without_this(this, *args):
        # Method implementations could check for and return E_POINTER
        # themselves.  Or an error will be raised when
        # 'outargs[i][0] = value' is executed.
##        for a in outargs:
##            if not a:
##                return E_POINTER

        #make argument list for handler by index array built above
        inargs = []
        for a in args_in_idx:
            inargs.append(args[a])
        try:
            result = mth(*inargs)
            if args_out == 1:
                args[args_out_idx[0]][0] = result
            elif args_out != 0:
                if len(result) != args_out:
                    msg = "Method should have returned a %s-tuple" % args_out
                    raise ValueError(msg)
                for i, value in enumerate(result):
                    args[args_out_idx[i]][0] = value
        except ReturnHRESULT as err:
            (hresult, text) = err.args
            return ReportError(text, iid=interface._iid_, clsid=clsid,
                               hresult=hresult)
        except COMError as err:
            (hr, text, details) = err.args
            _error("Exception in %s.%s implementation:", interface.__name__,
                   mthname, exc_info=True)
            try:
                descr, source, helpfile, helpcontext, progid = details
            except (ValueError, TypeError):
                msg = str(details)
            else:
                msg = "%s: %s" % (source, descr)
            hr = HRESULT_FROM_WIN32(hr)
            return ReportError(msg, iid=interface._iid_, clsid=clsid,
                               hresult=hr)
        except WindowsError as details:
            _error("Exception in %s.%s implementation:", interface.__name__,
                   mthname, exc_info=True)
            hr = HRESULT_FROM_WIN32(winerror(details))
            return ReportException(hr, interface._iid_, clsid=clsid)
        except E_NotImplemented:
            _warning("Unimplemented method %s.%s called", interface.__name__,
                     mthname)
            return E_NOTIMPL
        except:
            _error("Exception in %s.%s implementation:", interface.__name__,
                   mthname, exc_info=True)
            return ReportException(E_FAIL, interface._iid_, clsid=clsid)
        return S_OK
コード例 #2
0
ファイル: _comobject.py プロジェクト: Lzm0010/dashboard
 def call_with_this(*args, **kw):
     try:
         result = mth(*args, **kw)
     except ReturnHRESULT as err:
         (hresult, text) = err.args
         return ReportError(text,
                            iid=interface._iid_,
                            clsid=clsid,
                            hresult=hresult)
     except (COMError, WindowsError) as details:
         _error("Exception in %s.%s implementation:",
                interface.__name__,
                mthname,
                exc_info=True)
         return HRESULT_FROM_WIN32(winerror(details))
     except E_NotImplemented:
         _warning("Unimplemented method %s.%s called", interface.__name__,
                  mthname)
         return E_NOTIMPL
     except:
         _error("Exception in %s.%s implementation:",
                interface.__name__,
                mthname,
                exc_info=True)
         return ReportException(E_FAIL, interface._iid_, clsid=clsid)
     if result is None:
         return S_OK
     return result
コード例 #3
0
ファイル: _comobject.py プロジェクト: wshunvx/comtypes
 def call_with_this(*args, **kw):
     try:
         result = mth(*args, **kw)
     except ReturnHRESULT, err:
         (hresult, text) = err.args
         return ReportError(text, iid=interface._iid_, clsid=clsid,
                            hresult=hresult)
コード例 #4
0
ファイル: _comobject.py プロジェクト: wshunvx/comtypes
    def call_without_this(this, *args):
        # Method implementations could check for and return E_POINTER
        # themselves.  Or an error will be raised when
        # 'outargs[i][0] = value' is executed.
##        for a in outargs:
##            if not a:
##                return E_POINTER

        #make argument list for handler by index array built above
        inargs = []
        for a in args_in_idx:
            inargs.append(args[a])
        try:
            result = mth(*inargs)
            if args_out == 1:
                args[args_out_idx[0]][0] = result
            elif args_out != 0:
                if len(result) != args_out:
                    msg = "Method should have returned a %s-tuple" % args_out
                    raise ValueError(msg)
                for i, value in enumerate(result):
                    args[args_out_idx[i]][0] = value
        except ReturnHRESULT, err:
            (hresult, text) = err.args
            return ReportError(text, iid=interface._iid_, clsid=clsid,
                               hresult=hresult)
コード例 #5
0
def hack(inst, mth, paramflags, interface, mthname):
    if paramflags is None:
        return catch_errors(inst, mth, paramflags, interface, mthname)
    code = mth.func_code
    if code.co_varnames[1:2] == ("this",):
        return catch_errors(inst, mth, paramflags, interface, mthname)
    dirflags = [f[0] for f in paramflags]
    # An argument is an input arg either if flags are NOT set in the
    # idl file, or if the flags contain 'in'. In other words, the
    # direction flag is either exactly '0' or has the '1' bit set:
    # Output arguments have flag '2'

    args_out_idx=[]
    args_in_idx=[]
    for i,a in enumerate(dirflags):
        if a&2:
            args_out_idx.append(i)
        if a&1 or a==0:
            args_in_idx.append(i)
    args_out = len(args_out_idx)

    ## XXX Remove this:
##    if args_in != code.co_argcount - 1:
##        return catch_errors(inst, mth, interface, mthname)

    clsid = getattr(inst, "_reg_clsid_", None)
    def call_without_this(this, *args):
        # Method implementations could check for and return E_POINTER
        # themselves.  Or an error will be raised when
        # 'outargs[i][0] = value' is executed.
##        for a in outargs:
##            if not a:
##                return E_POINTER

        #make argument list for handler by index array built above
        inargs=[]
        for a in args_in_idx:
            inargs.append(args[a])
        try:
            result = mth(*inargs)
            if args_out == 1:
                args[args_out_idx[0]][0] = result
            elif args_out != 0:
                if len(result) != args_out:
                    raise ValueError("Method should have returned a %s-tuple" % args_out)
                for i, value in enumerate(result):
                    args[args_out_idx[i]][0] = value
        except ReturnHRESULT, err:
            (hresult, text) = err.args
            return ReportError(text, iid=interface._iid_, clsid=clsid, hresult=hresult)
        except COMError, err:
            (hr, text, details) = err.args
            _error("Exception in %s.%s implementation:", interface.__name__, mthname, exc_info=True)
            try:
                descr, source, helpfile, helpcontext, progid = details
            except (ValueError, TypeError):
                msg = str(details)
            else:
                msg = "%s: %s" % (source, descr)
            hr = HRESULT_FROM_WIN32(hr)
            return ReportError(msg, iid=interface._iid_, clsid=clsid, hresult=hr)