util.py :  » Windows » pyExcelerator » pywin32-214 » com » win32comext » axdebug » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » com » win32comext » axdebug » util.py
# Utility function for wrapping objects.  Centralising allows me to turn
# debugging on and off for the entire package in a single spot.

import sys
import win32com.server.util
from win32com.server.exception import Exception
import winerror
import win32api
import os

try:
    os.environ["DEBUG_AXDEBUG"]
    debugging = 1
except KeyError:
    debugging = 0

def trace(*args):
    if not debugging: return
    print str(win32api.GetCurrentThreadId()) + ":",
    for arg in args:
        print arg,
    print

# The AXDebugging implementation assumes that the returned COM pointers are in
# some cases identical.  Eg, from a C++ perspective:
# p->GetSomeInterface( &p1 );
# p->GetSomeInterface( &p2 );
# p1==p2
# By default, this is _not_ true for Python.
# (Now this is only true for Document objects, and Python
# now does ensure this.

all_wrapped = {}

def _wrap_nodebug(object, iid):
    return win32com.server.util.wrap(object, iid)

def _wrap_debug(object, iid):
    import win32com.server.policy
    dispatcher = win32com.server.policy.DispatcherWin32trace
    return win32com.server.util.wrap(object, iid, useDispatcher = dispatcher)

if debugging:
    _wrap = _wrap_debug
else:
    _wrap = _wrap_nodebug

def _wrap_remove(object, iid = None):
    # Old - no longer used or necessary!
    return

def _dump_wrapped():
    from win32com.server.util import unwrap
    print "Wrapped items:"
    for key, items in all_wrapped.iteritems():
        print key,
        try:
            ob = unwrap(key)
            print ob, sys.getrefcount(ob)
        except:
            print "<error>"


def RaiseNotImpl(who = None):
    if who is not None:
        print "********* Function %s Raising E_NOTIMPL  ************" % (who)

    # Print a sort-of "traceback", dumping all the frames leading to here.
    try:
        1/0
    except:
        frame = sys.exc_info()[2].tb_frame
    while frame:
        print "File: %s, Line: %d" % (frame.f_code.co_filename, frame.f_lineno)
        frame = frame.f_back

    # and raise the exception for COM
    raise Exception(scode=winerror.E_NOTIMPL)


import win32com.server.policy
class Dispatcher(win32com.server.policy.DispatcherWin32trace):
    def __init__(self, policyClass, object):
        win32com.server.policy.DispatcherTrace.__init__(self, policyClass, object)
        import win32traceutil # Sets up everything.
#               print "Object with win32trace dispatcher created (object=%s)" % `object`

    def _QueryInterface_(self, iid):
        rc = win32com.server.policy.DispatcherBase._QueryInterface_(self, iid)
#               if not rc:
#                       self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid))
        return rc

    def _Invoke_(self, dispid, lcid, wFlags, args):
        print "In Invoke with", dispid, lcid, wFlags, args, "with object",self.policy._obj_
        try:
            rc = win32com.server.policy.DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
#                       print "Invoke of", dispid, "returning", rc
            return rc
        except Exception:
            t, v, tb = sys.exc_info()
            tb = None # A cycle
            scode = v.scode
            try:
                desc = " (" + str(v.description) + ")"
            except AttributeError:
                desc = ""
            print "*** Invoke of %s raised COM exception 0x%x%s" % (dispid, scode, desc)
        except:
            print "*** Invoke of %s failed:" % dispid
            typ, val, tb = sys.exc_info()
            import traceback
            traceback.print_exception(typ, val, tb)
            raise
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.