PyXR

c:\python24\lib\site-packages\win32 \ com \ test \ pippo_server.py



0001 # A little test server, complete with typelib, we can use for testing.
0002 # Originally submitted with bug:
0003 # [ 753154 ] memory leak wrapping object having _typelib_guid_ attribute
0004 # but modified by mhammond for use as part of the test suite.
0005 import sys, os
0006 import pythoncom
0007 import win32com
0008 import winerror
0009 from win32com.server.util import wrap
0010 
0011 try:
0012     __file__ # 2.3 only for __main__
0013 except NameError:
0014     __file__ = sys.argv[0]
0015 
0016 class CPippo:
0017     #
0018     # COM declarations    
0019     #
0020     _reg_clsid_ = "{05AC1CCE-3F9B-4d9a-B0B5-DFE8BE45AFA8}"
0021     _reg_desc_ = "Pippo Python test object"
0022     _reg_progid_ = "Python.Test.Pippo"
0023     #_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER    
0024     ###
0025     ### Link to typelib
0026     _typelib_guid_ = '{41059C57-975F-4B36-8FF3-C5117426647A}'
0027     _typelib_version_ = 1, 0
0028     _com_interfaces_ = ['IPippo']
0029 
0030     def __init__(self):
0031         self.MyProp1 = 10
0032 
0033     def Method1(self):
0034         return wrap(CPippo())
0035 
0036 def BuildTypelib():
0037     from distutils.dep_util import newer
0038     this_dir = os.path.dirname(__file__)
0039     idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
0040     tlb=os.path.splitext(idl)[0] + '.tlb'
0041     if newer(idl, tlb):
0042         print "Compiling %s" % (idl,)
0043         rc = os.system ('midl "%s"' % (idl,))
0044         if rc:
0045             raise RuntimeError, "Compiling MIDL failed!"
0046         # Can't work out how to prevent MIDL from generating the stubs.
0047         # just nuke them
0048         for fname in "dlldata.c pippo_i.c pippo_p.c pippo.h".split():
0049             os.remove(os.path.join(this_dir, fname))
0050     
0051     print "Registering %s" % (tlb,)
0052     tli=pythoncom.LoadTypeLib(tlb)
0053     pythoncom.RegisterTypeLib(tli,tlb)
0054 
0055 def UnregisterTypelib():
0056     k = CPippo
0057     try:
0058         pythoncom.UnRegisterTypeLib(k._typelib_guid_, 
0059                                     k._typelib_version_[0], 
0060                                     k._typelib_version_[1], 
0061                                     0, 
0062                                     pythoncom.SYS_WIN32)
0063         print "Unregistered typelib"
0064     except pythoncom.error, details:
0065         if details[0]==winerror.TYPE_E_REGISTRYACCESS:
0066             pass
0067         else:
0068             raise
0069 
0070 def main(argv=None):
0071     if argv is None: argv = sys.argv[1:]
0072     if '--unregister' in argv:
0073         # Unregister the type-libraries.
0074         UnregisterTypelib()
0075     else:
0076         # Build and register the type-libraries.
0077         BuildTypelib()
0078     import win32com.server.register 
0079     win32com.server.register.UseCommandLine(CPippo)
0080 
0081 if __name__=='__main__':
0082     main(sys.argv)
0083 

Generated by PyXR 0.9.4
SourceForge.net Logo