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.

pippo_server.py 2.6KB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # A little test server, complete with typelib, we can use for testing.
  2. # Originally submitted with bug:
  3. # [ 753154 ] memory leak wrapping object having _typelib_guid_ attribute
  4. # but modified by mhammond for use as part of the test suite.
  5. import os
  6. import sys
  7. import pythoncom
  8. import win32com
  9. import winerror
  10. from win32com.server.util import wrap
  11. class CPippo:
  12. #
  13. # COM declarations
  14. #
  15. _reg_clsid_ = "{1F0F75D6-BD63-41B9-9F88-2D9D2E1AA5C3}"
  16. _reg_desc_ = "Pippo Python test object"
  17. _reg_progid_ = "Python.Test.Pippo"
  18. # _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
  19. ###
  20. ### Link to typelib
  21. _typelib_guid_ = "{7783054E-9A20-4584-8C62-6ED2A08F6AC6}"
  22. _typelib_version_ = 1, 0
  23. _com_interfaces_ = ["IPippo"]
  24. def __init__(self):
  25. self.MyProp1 = 10
  26. def Method1(self):
  27. return wrap(CPippo())
  28. def Method2(self, in1, inout1):
  29. return in1, inout1 * 2
  30. def Method3(self, in1):
  31. # in1 will be a tuple, not a list.
  32. # Yet, we are not allowed to return a tuple, but need to convert it to a list first. (Bug?)
  33. return list(in1)
  34. def BuildTypelib():
  35. from distutils.dep_util import newer
  36. this_dir = os.path.dirname(__file__)
  37. idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
  38. tlb = os.path.splitext(idl)[0] + ".tlb"
  39. if newer(idl, tlb):
  40. print("Compiling %s" % (idl,))
  41. rc = os.system('midl "%s"' % (idl,))
  42. if rc:
  43. raise RuntimeError("Compiling MIDL failed!")
  44. # Can't work out how to prevent MIDL from generating the stubs.
  45. # just nuke them
  46. for fname in "dlldata.c pippo_i.c pippo_p.c pippo.h".split():
  47. os.remove(os.path.join(this_dir, fname))
  48. print("Registering %s" % (tlb,))
  49. tli = pythoncom.LoadTypeLib(tlb)
  50. pythoncom.RegisterTypeLib(tli, tlb)
  51. def UnregisterTypelib():
  52. k = CPippo
  53. try:
  54. pythoncom.UnRegisterTypeLib(
  55. k._typelib_guid_,
  56. k._typelib_version_[0],
  57. k._typelib_version_[1],
  58. 0,
  59. pythoncom.SYS_WIN32,
  60. )
  61. print("Unregistered typelib")
  62. except pythoncom.error as details:
  63. if details[0] == winerror.TYPE_E_REGISTRYACCESS:
  64. pass
  65. else:
  66. raise
  67. def main(argv=None):
  68. if argv is None:
  69. argv = sys.argv[1:]
  70. if "--unregister" in argv:
  71. # Unregister the type-libraries.
  72. UnregisterTypelib()
  73. else:
  74. # Build and register the type-libraries.
  75. BuildTypelib()
  76. import win32com.server.register
  77. win32com.server.register.UseCommandLine(CPippo)
  78. if __name__ == "__main__":
  79. main(sys.argv)