home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / win32com / server / dispatcher.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  13.5 KB  |  302 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''Dispatcher
  5.  
  6. Please see policy.py for a discussion on dispatchers and policies
  7. '''
  8. import pythoncom
  9. import traceback
  10. import win32api
  11. from sys import exc_info
  12. from win32com.server.exception import IsCOMServerException
  13. from win32com.util import IIDToInterfaceName
  14.  
  15. class DispatcherBase:
  16.     ''' The base class for all Dispatchers.  
  17.  
  18.       This dispatcher supports wrapping all operations in exception handlers, 
  19.       and all the necessary delegation to the policy.
  20.  
  21.       This base class supports the printing of "unexpected" exceptions.  Note, however,
  22.       that exactly where the output of print goes may not be useful!  A derived class may
  23.       provide additional semantics for this.
  24.   '''
  25.     
  26.     def __init__(self, policyClass, object):
  27.         self.policy = policyClass(object)
  28.  
  29.     
  30.     def _CreateInstance_(self, clsid, reqIID):
  31.         
  32.         try:
  33.             self.policy._CreateInstance_(clsid, reqIID)
  34.             return pythoncom.WrapObject(self, reqIID)
  35.         except:
  36.             self._HandleException_()
  37.  
  38.  
  39.     
  40.     def _QueryInterface_(self, iid):
  41.         
  42.         try:
  43.             return self.policy._QueryInterface_(iid)
  44.         except:
  45.             self._HandleException_()
  46.  
  47.  
  48.     
  49.     def _Invoke_(self, dispid, lcid, wFlags, args):
  50.         
  51.         try:
  52.             return self.policy._Invoke_(dispid, lcid, wFlags, args)
  53.         except:
  54.             self._HandleException_()
  55.  
  56.  
  57.     
  58.     def _GetIDsOfNames_(self, names, lcid):
  59.         
  60.         try:
  61.             return self.policy._GetIDsOfNames_(names, lcid)
  62.         except:
  63.             self._HandleException_()
  64.  
  65.  
  66.     
  67.     def _GetDispID_(self, name, fdex):
  68.         
  69.         try:
  70.             return self.policy._GetDispID_(name, fdex)
  71.         except:
  72.             self._HandleException_()
  73.  
  74.  
  75.     
  76.     def _InvokeEx_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider):
  77.         
  78.         try:
  79.             return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider)
  80.         except:
  81.             self._HandleException_()
  82.  
  83.  
  84.     
  85.     def _DeleteMemberByName_(self, name, fdex):
  86.         
  87.         try:
  88.             return self.policy._DeleteMemberByName_(name, fdex)
  89.         except:
  90.             self._HandleException_()
  91.  
  92.  
  93.     
  94.     def _DeleteMemberByDispID_(self, id):
  95.         
  96.         try:
  97.             return self.policy._DeleteMemberByDispID_(id)
  98.         except:
  99.             self._HandleException_()
  100.  
  101.  
  102.     
  103.     def _GetMemberProperties_(self, id, fdex):
  104.         
  105.         try:
  106.             return self.policy._GetMemberProperties_(id, fdex)
  107.         except:
  108.             self._HandleException_()
  109.  
  110.  
  111.     
  112.     def _GetMemberName_(self, dispid):
  113.         
  114.         try:
  115.             return self.policy._GetMemberName_(dispid)
  116.         except:
  117.             self._HandleException_()
  118.  
  119.  
  120.     
  121.     def _GetNextDispID_(self, fdex, flags):
  122.         
  123.         try:
  124.             return self.policy._GetNextDispID_(fdex, flags)
  125.         except:
  126.             self._HandleException_()
  127.  
  128.  
  129.     
  130.     def _GetNameSpaceParent_(self):
  131.         
  132.         try:
  133.             return self.policy._GetNameSpaceParent_()
  134.         except:
  135.             self._HandleException_()
  136.  
  137.  
  138.     
  139.     def _HandleException_(self):
  140.         '''Called whenever an exception is raised.
  141.  
  142.        Default behaviour is to print the exception.
  143.     '''
  144.         if not IsCOMServerException():
  145.             traceback.print_exc()
  146.         
  147.         reraise()
  148.  
  149.     
  150.     def _trace_(self, *args):
  151.         for arg in args[:-1]:
  152.             print arg,
  153.         
  154.         print args[-1]
  155.  
  156.  
  157.  
  158. class DispatcherTrace(DispatcherBase):
  159.     """A dispatcher, which causes a 'print' line for each COM function called.
  160.   """
  161.     
  162.     def _QueryInterface_(self, iid):
  163.         rc = DispatcherBase._QueryInterface_(self, iid)
  164.         if not rc:
  165.             self._trace_('in %s._QueryInterface_ with unsupported IID %s (%s)\n' % (`self.policy._obj_`, IIDToInterfaceName(iid), iid))
  166.         
  167.         return rc
  168.  
  169.     
  170.     def _GetIDsOfNames_(self, names, lcid):
  171.         self._trace_("in _GetIDsOfNames_ with '%s' and '%d'\n" % (names, lcid))
  172.         return DispatcherBase._GetIDsOfNames_(self, names, lcid)
  173.  
  174.     
  175.     def _Invoke_(self, dispid, lcid, wFlags, args):
  176.         self._trace_('in _Invoke_ with', dispid, lcid, wFlags, args)
  177.         return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
  178.  
  179.     
  180.     def _GetDispID_(self, name, fdex):
  181.         self._trace_('in _GetDispID_ with', name, fdex)
  182.         return DispatcherBase._GetDispID_(self, name, fdex)
  183.  
  184.     
  185.     def _InvokeEx_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider):
  186.         self._trace_('in _InvokeEx_ with', dispid, lcid, wFlags, args, kwargs, serviceProvider)
  187.         return DispatcherBase._InvokeEx_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider)
  188.  
  189.     
  190.     def _DeleteMemberByName_(self, name, fdex):
  191.         self._trace_('in _DeleteMemberByName_ with', name, fdex)
  192.         return DispatcherBase._DeleteMemberByName_(self, name, fdex)
  193.  
  194.     
  195.     def _DeleteMemberByDispID_(self, id):
  196.         self._trace_('in _DeleteMemberByDispID_ with', id)
  197.         return DispatcherBase._DeleteMemberByDispID_(self, id)
  198.  
  199.     
  200.     def _GetMemberProperties_(self, id, fdex):
  201.         self._trace_('in _GetMemberProperties_ with', id, fdex)
  202.         return DispatcherBase._GetMemberProperties_(self, id, fdex)
  203.  
  204.     
  205.     def _GetMemberName_(self, dispid):
  206.         self._trace_('in _GetMemberName_ with', dispid)
  207.         return DispatcherBase._GetMemberName_(self, dispid)
  208.  
  209.     
  210.     def _GetNextDispID_(self, fdex, flags):
  211.         self._trace_('in _GetNextDispID_ with', fdex, flags)
  212.         return DispatcherBase._GetNextDispID_(self, fdex, flags)
  213.  
  214.     
  215.     def _GetNameSpaceParent_(self):
  216.         self._trace_('in _GetNameSpaceParent_')
  217.         return DispatcherBase._GetNameSpaceParent_(self)
  218.  
  219.  
  220.  
  221. class DispatcherWin32trace(DispatcherTrace):
  222.     '''A tracing dispatcher that sends its output to the win32trace remote collector.
  223.   
  224.   '''
  225.     
  226.     def __init__(self, policyClass, object):
  227.         DispatcherTrace.__init__(self, policyClass, object)
  228.         import win32traceutil
  229.         print 'Object with win32trace dispatcher created (object=%s)' % `object`
  230.  
  231.  
  232.  
  233. class DispatcherOutputDebugString(DispatcherTrace):
  234.     '''A tracing dispatcher that sends its output to win32api.OutputDebugString
  235.   
  236.   '''
  237.     
  238.     def _trace_(self, *args):
  239.         for arg in args[:-1]:
  240.             win32api.OutputDebugString(str(arg) + ' ')
  241.         
  242.         win32api.OutputDebugString(str(args[-1]) + '\n')
  243.  
  244.  
  245.  
  246. class DispatcherWin32dbg(DispatcherBase):
  247.     '''A source-level debugger dispatcher
  248.  
  249.   A dispatcher which invokes the debugger as an object is instantiated, or 
  250.   when an unexpected exception occurs.
  251.  
  252.   Requires the win32dbg package.
  253.   '''
  254.     
  255.     def __init__(self, policyClass, ob):
  256.         import win32dbg
  257.         win32dbg.brk()
  258.         DispatcherBase.__init__(self, policyClass, ob)
  259.  
  260.     
  261.     def _HandleException_(self):
  262.         ''' Invoke the win32dbg post mortem capability '''
  263.         (typ, val, tb) = exc_info()
  264.         import win32dbg
  265.         import win32dbg.dbgcon as win32dbg
  266.         debug = 0
  267.         
  268.         try:
  269.             raise typ, val
  270.         except Exception:
  271.             debug = win32dbg.GetDebugger().get_option(win32dbg.dbgcon.OPT_STOP_EXCEPTIONS)
  272.         except:
  273.             debug = 1
  274.  
  275.         if debug:
  276.             
  277.             try:
  278.                 win32dbg.post_mortem(tb, typ, val)
  279.             except:
  280.                 traceback.print_exc()
  281.  
  282.         
  283.         del tb
  284.         reraise()
  285.  
  286.  
  287.  
  288. def reraise():
  289.     """Handy function for re-raising errors.
  290.  
  291.   Note: storing a traceback in a local variable can introduce reference
  292.   loops if you aren't careful.  Specifically, that local variable should
  293.   not be within an execution context contained with the traceback.
  294.  
  295.   By using a utility function, we ensure that our local variable holding
  296.   the traceback is not referenced by the traceback itself.
  297.   """
  298.     (t, v, tb) = exc_info()
  299.     raise t, v, tb
  300.  
  301. DefaultDebugDispatcher = DispatcherWin32trace
  302.