Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Utility function for wrapping objects. Centralising allows me to turn
  2. # debugging on and off for the entire package in a single spot.
  3. import os
  4. import sys
  5. import win32api
  6. import win32com.server.util
  7. import winerror
  8. from win32com.server.exception import Exception
  9. try:
  10. os.environ["DEBUG_AXDEBUG"]
  11. debugging = 1
  12. except KeyError:
  13. debugging = 0
  14. def trace(*args):
  15. if not debugging:
  16. return
  17. print(str(win32api.GetCurrentThreadId()) + ":", end=" ")
  18. for arg in args:
  19. print(arg, end=" ")
  20. print()
  21. # The AXDebugging implementation assumes that the returned COM pointers are in
  22. # some cases identical. Eg, from a C++ perspective:
  23. # p->GetSomeInterface( &p1 );
  24. # p->GetSomeInterface( &p2 );
  25. # p1==p2
  26. # By default, this is _not_ true for Python.
  27. # (Now this is only true for Document objects, and Python
  28. # now does ensure this.
  29. all_wrapped = {}
  30. def _wrap_nodebug(object, iid):
  31. return win32com.server.util.wrap(object, iid)
  32. def _wrap_debug(object, iid):
  33. import win32com.server.policy
  34. dispatcher = win32com.server.policy.DispatcherWin32trace
  35. return win32com.server.util.wrap(object, iid, useDispatcher=dispatcher)
  36. if debugging:
  37. _wrap = _wrap_debug
  38. else:
  39. _wrap = _wrap_nodebug
  40. def _wrap_remove(object, iid=None):
  41. # Old - no longer used or necessary!
  42. return
  43. def _dump_wrapped():
  44. from win32com.server.util import unwrap
  45. print("Wrapped items:")
  46. for key, items in all_wrapped.items():
  47. print(key, end=" ")
  48. try:
  49. ob = unwrap(key)
  50. print(ob, sys.getrefcount(ob))
  51. except:
  52. print("<error>")
  53. def RaiseNotImpl(who=None):
  54. if who is not None:
  55. print("********* Function %s Raising E_NOTIMPL ************" % (who))
  56. # Print a sort-of "traceback", dumping all the frames leading to here.
  57. try:
  58. 1 / 0
  59. except:
  60. frame = sys.exc_info()[2].tb_frame
  61. while frame:
  62. print("File: %s, Line: %d" % (frame.f_code.co_filename, frame.f_lineno))
  63. frame = frame.f_back
  64. # and raise the exception for COM
  65. raise Exception(scode=winerror.E_NOTIMPL)
  66. import win32com.server.policy
  67. class Dispatcher(win32com.server.policy.DispatcherWin32trace):
  68. def __init__(self, policyClass, object):
  69. win32com.server.policy.DispatcherTrace.__init__(self, policyClass, object)
  70. import win32traceutil # Sets up everything.
  71. # print "Object with win32trace dispatcher created (object=%s)" % `object`
  72. def _QueryInterface_(self, iid):
  73. rc = win32com.server.policy.DispatcherBase._QueryInterface_(self, iid)
  74. # if not rc:
  75. # self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid))
  76. return rc
  77. def _Invoke_(self, dispid, lcid, wFlags, args):
  78. print(
  79. "In Invoke with",
  80. dispid,
  81. lcid,
  82. wFlags,
  83. args,
  84. "with object",
  85. self.policy._obj_,
  86. )
  87. try:
  88. rc = win32com.server.policy.DispatcherBase._Invoke_(
  89. self, dispid, lcid, wFlags, args
  90. )
  91. # print "Invoke of", dispid, "returning", rc
  92. return rc
  93. except Exception:
  94. t, v, tb = sys.exc_info()
  95. tb = None # A cycle
  96. scode = v.scode
  97. try:
  98. desc = " (" + str(v.description) + ")"
  99. except AttributeError:
  100. desc = ""
  101. print(
  102. "*** Invoke of %s raised COM exception 0x%x%s" % (dispid, scode, desc)
  103. )
  104. except:
  105. print("*** Invoke of %s failed:" % dispid)
  106. typ, val, tb = sys.exc_info()
  107. import traceback
  108. traceback.print_exception(typ, val, tb)
  109. raise