Guest User

Untitled

a guest
Jul 19th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  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 sys, os
  6. import pythoncom
  7. import win32com
  8. import winerror
  9. from win32com.server.util import wrap
  10.  
  11. try:
  12.     __file__ # 2.3 only for __main__
  13. except NameError:
  14.     __file__ = sys.argv[0]
  15.  
  16. class CPippo:
  17.     #
  18.     # COM declarations    
  19.     #
  20.     _reg_clsid_ = "{05AC1CCE-3F9B-4d9a-B0B5-DFE8BE45AFA9}"
  21.     _reg_desc_ = "Pippo Python test object 5"
  22.     _reg_progid_ = "Python.Test.Pippo.5"
  23.     #_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER    
  24.     ### Link to typelib
  25.     _typelib_guid_ = '{1728B2B9-B2EE-4657-8181-AB7B38AB847A}'
  26.     _typelib_version_ = 1, 1
  27.     _com_interfaces_ = ['IPippo']
  28.  
  29.     def __init__(self):
  30.         self.MyProp1 = 10
  31.  
  32.     def Method1(self):
  33.         return wrap(CPippo())
  34.  
  35. def BuildTypelib():
  36.     from distutils.dep_util import newer
  37.     this_dir = os.path.dirname(__file__)
  38.     idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
  39.     tlb=os.path.splitext(idl)[0] + '.tlb'
  40.     print "Registering %s" % (tlb,)
  41.     tli=pythoncom.LoadTypeLib(tlb)
  42.     pythoncom.RegisterTypeLib(tli,tlb)
  43.  
  44. def UnregisterTypelib():
  45.     k = CPippo
  46.     try:
  47.         pythoncom.UnRegisterTypeLib(k._typelib_guid_,
  48.                                     k._typelib_version_[0],
  49.                                     k._typelib_version_[1],
  50.                                     0,
  51.                                     pythoncom.SYS_WIN32)
  52.         print "Unregistered typelib"
  53.     except pythoncom.error, details:
  54.         if details[0]==winerror.TYPE_E_REGISTRYACCESS:
  55.             pass
  56.         else:
  57.             raise
  58.  
  59. def main(argv=None):
  60.     if argv is None: argv = sys.argv[1:]
  61.     if '--unregister' in argv:
  62.         # Unregister the type-libraries.
  63.         UnregisterTypelib()
  64.     else:
  65.         # Build and register the type-libraries.
  66.         BuildTypelib()
  67.     import win32com.server.register
  68.     win32com.server.register.UseCommandLine(CPippo)
  69.  
  70. if __name__=='__main__':
  71.     main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment