home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / Bureautique / gImageReader / gimagereader_0.9-1_win32.exe / bin / win32com / client / genpy.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2011-03-24  |  35KB  |  1,110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''genpy.py - The worker for makepy.  See makepy.py for more details
  5.  
  6. This code was moved simply to speed Python in normal circumstances.  As the makepy.py
  7. is normally run from the command line, it reparses the code each time.  Now makepy
  8. is nothing more than the command line handler and public interface.
  9.  
  10. The makepy command line etc handling is also getting large enough in its own right!
  11. '''
  12. import os
  13. import sys
  14. import time
  15. import win32com
  16. import pythoncom
  17. import build
  18. error = 'makepy.error'
  19. makepy_version = '0.5.00'
  20. GEN_FULL = 'full'
  21. GEN_DEMAND_BASE = 'demand(base)'
  22. GEN_DEMAND_CHILD = 'demand(child)'
  23. mapVTToTypeString = {
  24.     pythoncom.VT_I2: 'types.IntType',
  25.     pythoncom.VT_I4: 'types.IntType',
  26.     pythoncom.VT_R4: 'types.FloatType',
  27.     pythoncom.VT_R8: 'types.FloatType',
  28.     pythoncom.VT_BSTR: 'types.StringType',
  29.     pythoncom.VT_BOOL: 'types.IntType',
  30.     pythoncom.VT_VARIANT: 'types.TypeType',
  31.     pythoncom.VT_I1: 'types.IntType',
  32.     pythoncom.VT_UI1: 'types.IntType',
  33.     pythoncom.VT_UI2: 'types.IntType',
  34.     pythoncom.VT_UI4: 'types.IntType',
  35.     pythoncom.VT_I8: 'types.LongType',
  36.     pythoncom.VT_UI8: 'types.LongType',
  37.     pythoncom.VT_INT: 'types.IntType',
  38.     pythoncom.VT_DATE: 'pythoncom.PyTimeType',
  39.     pythoncom.VT_UINT: 'types.IntType' }
  40.  
  41. def MakeDefaultArgsForPropertyPut(argsDesc):
  42.     ret = []
  43.     for desc in argsDesc[1:]:
  44.         default = build.MakeDefaultArgRepr(desc)
  45.         if default is None:
  46.             break
  47.         ret.append(default)
  48.     
  49.     return tuple(ret)
  50.  
  51.  
  52. def MakeMapLineEntry(dispid, wFlags, retType, argTypes, user, resultCLSID):
  53.     argTypes = tuple([ what[:2] for what in argTypes ])
  54.     return '(%s, %d, %s, %s, "%s", %s)' % (dispid, wFlags, retType[:2], argTypes, user, resultCLSID)
  55.  
  56.  
  57. def MakeEventMethodName(eventName):
  58.     if eventName[:2] == 'On':
  59.         return eventName
  60.     return None + eventName
  61.  
  62.  
  63. def WriteSinkEventMap(obj, stream):
  64.     print >>stream, '\t_dispid_to_func_ = {'
  65.     for name, entry in obj.propMapGet.items() + obj.propMapPut.items() + obj.mapFuncs.items():
  66.         fdesc = entry.desc
  67.         print >>stream, '\t\t%9d : "%s",' % (entry.desc[0], MakeEventMethodName(entry.names[0]))
  68.     
  69.     print >>stream, '\t\t}'
  70.  
  71.  
  72. class WritableItem:
  73.     
  74.     def __cmp__(self, other):
  75.         '''Compare for sorting'''
  76.         ret = cmp(self.order, other.order)
  77.         if ret == 0 and self.doc:
  78.             ret = cmp(self.doc[0], other.doc[0])
  79.         return ret
  80.  
  81.     
  82.     def __lt__(self, other):
  83.         if self.order == other.order:
  84.             return self.doc < other.doc
  85.         return None.order < other.order
  86.  
  87.     
  88.     def __repr__(self):
  89.         return 'OleItem: doc=%s, order=%d' % (repr(self.doc), self.order)
  90.  
  91.  
  92.  
  93. class RecordItem(build.OleItem, WritableItem):
  94.     order = 9
  95.     typename = 'RECORD'
  96.     
  97.     def __init__(self, typeInfo, typeAttr, doc = None, bForUser = 1):
  98.         build.OleItem.__init__(self, doc)
  99.         self.clsid = typeAttr[0]
  100.  
  101.     
  102.     def WriteClass(self, generator):
  103.         pass
  104.  
  105.  
  106.  
  107. def WriteAliasesForItem(item, aliasItems, stream):
  108.     for alias in aliasItems.itervalues():
  109.         if item.doc and alias.aliasDoc and alias.aliasDoc[0] == item.doc[0]:
  110.             alias.WriteAliasItem(aliasItems, stream)
  111.             continue
  112.  
  113.  
  114. class AliasItem(build.OleItem, WritableItem):
  115.     order = 2
  116.     typename = 'ALIAS'
  117.     
  118.     def __init__(self, typeinfo, attr, doc = None, bForUser = 1):
  119.         build.OleItem.__init__(self, doc)
  120.         ai = attr[14]
  121.         self.attr = attr
  122.         if type(ai) == type(()) and type(ai[1]) == type(0):
  123.             href = ai[1]
  124.             alinfo = typeinfo.GetRefTypeInfo(href)
  125.             self.aliasDoc = alinfo.GetDocumentation(-1)
  126.             self.aliasAttr = alinfo.GetTypeAttr()
  127.         else:
  128.             self.aliasDoc = None
  129.             self.aliasAttr = None
  130.  
  131.     
  132.     def WriteAliasItem(self, aliasDict, stream):
  133.         if self.bWritten:
  134.             return None
  135.         if None.aliasDoc:
  136.             depName = self.aliasDoc[0]
  137.             if depName in aliasDict:
  138.                 aliasDict[depName].WriteAliasItem(aliasDict, stream)
  139.             print >>stream, self.doc[0] + ' = ' + depName
  140.         else:
  141.             ai = self.attr[14]
  142.             if type(ai) == type(0):
  143.                 
  144.                 try:
  145.                     typeStr = mapVTToTypeString[ai]
  146.                     print >>stream, '# %s=%s' % (self.doc[0], typeStr)
  147.                 except KeyError:
  148.                     print >>stream, self.doc[0] + " = None # Can't convert alias info " + str(ai)
  149.                 
  150.  
  151.         print >>stream
  152.         self.bWritten = 1
  153.  
  154.  
  155.  
  156. class EnumerationItem(build.OleItem, WritableItem):
  157.     order = 1
  158.     typename = 'ENUMERATION'
  159.     
  160.     def __init__(self, typeinfo, attr, doc = None, bForUser = 1):
  161.         build.OleItem.__init__(self, doc)
  162.         self.clsid = attr[0]
  163.         self.mapVars = { }
  164.         typeFlags = attr[11]
  165.         if not typeFlags & pythoncom.TYPEFLAG_FHIDDEN:
  166.             pass
  167.         self.hidden = typeFlags & pythoncom.TYPEFLAG_FRESTRICTED
  168.         for j in range(attr[7]):
  169.             vdesc = typeinfo.GetVarDesc(j)
  170.             name = typeinfo.GetNames(vdesc[0])[0]
  171.             self.mapVars[name] = build.MapEntry(vdesc)
  172.         
  173.  
  174.     
  175.     def WriteEnumerationItems(self, stream):
  176.         num = 0
  177.         enumName = self.doc[0]
  178.         names = list(self.mapVars.keys())
  179.         names.sort()
  180.         for name in names:
  181.             entry = self.mapVars[name]
  182.             vdesc = entry.desc
  183.             if vdesc[4] == pythoncom.VAR_CONST:
  184.                 val = vdesc[1]
  185.                 if sys.version_info <= (2, 4):
  186.                     if isinstance(val, int) or isinstance(val, long):
  187.                         if val == 0x80000000L:
  188.                             use = '0x80000000L'
  189.                         elif val > 0x80000000L or val < 0:
  190.                             use = long(val)
  191.                         else:
  192.                             use = hex(val)
  193.                     else:
  194.                         use = repr(val)
  195.             print >>stream, '\t%-30s=%-10s # from enum %s' % (build.MakePublicAttributeName(name, True), use, enumName)
  196.             num += 1
  197.             continue
  198.         
  199.         return num
  200.  
  201.  
  202.  
  203. class VTableItem(build.VTableItem, WritableItem):
  204.     order = 4
  205.     
  206.     def WriteClass(self, generator):
  207.         self.WriteVTableMap(generator)
  208.         self.bWritten = 1
  209.  
  210.     
  211.     def WriteVTableMap(self, generator):
  212.         stream = generator.file
  213.         print >>stream, '%s_vtables_dispatch_ = %d' % (self.python_name, self.bIsDispatch)
  214.         print >>stream, '%s_vtables_ = [' % (self.python_name,)
  215.         for v in self.vtableFuncs:
  216.             (names, dispid, desc) = v
  217.             arg_desc = desc[2]
  218.             arg_reprs = []
  219.             item_num = 0
  220.             print >>stream, '\t((',
  221.             for name in names:
  222.                 print >>stream, repr(name), ',',
  223.                 item_num = item_num + 1
  224.                 if item_num % 5 == 0:
  225.                     print >>stream, '\n\t\t\t',
  226.                     continue
  227.             print >>stream, '), %d, (%r, %r, [' % (dispid, desc[0], desc[1]),
  228.             for arg in arg_desc:
  229.                 item_num = item_num + 1
  230.                 if item_num % 5 == 0:
  231.                     print >>stream, '\n\t\t\t',
  232.                 defval = build.MakeDefaultArgRepr(arg)
  233.                 if arg[3] is None:
  234.                     arg3_repr = None
  235.                 else:
  236.                     arg3_repr = repr(arg[3])
  237.                 print >>stream, repr((arg[0], arg[1], defval, arg3_repr)), ',',
  238.             
  239.             print >>stream, '],',
  240.             for d in desc[3:]:
  241.                 print >>stream, repr(d), ',',
  242.             
  243.             print >>stream, ')),'
  244.         
  245.         print >>stream, ']'
  246.         print >>stream
  247.  
  248.  
  249.  
  250. class DispatchItem(build.DispatchItem, WritableItem):
  251.     order = 3
  252.     
  253.     def __init__(self, typeinfo, attr, doc = None):
  254.         build.DispatchItem.__init__(self, typeinfo, attr, doc)
  255.         self.type_attr = attr
  256.         self.coclass_clsid = None
  257.  
  258.     
  259.     def WriteClass(self, generator):
  260.         if not (self.bIsDispatch) and not (self.type_attr.typekind == pythoncom.TKIND_DISPATCH):
  261.             return None
  262.         if None.bIsSink:
  263.             self.WriteEventSinkClassHeader(generator)
  264.             self.WriteCallbackClassBody(generator)
  265.         else:
  266.             self.WriteClassHeader(generator)
  267.             self.WriteClassBody(generator)
  268.         print >>generator.file
  269.         self.bWritten = 1
  270.  
  271.     
  272.     def WriteClassHeader(self, generator):
  273.         generator.checkWriteDispatchBaseClass()
  274.         doc = self.doc
  275.         stream = generator.file
  276.         print >>stream, 'class ' + self.python_name + '(DispatchBaseClass):'
  277.         if doc[1]:
  278.             print >>stream, '\t' + build._safeQuotedString(doc[1])
  279.         
  280.         try:
  281.             progId = pythoncom.ProgIDFromCLSID(self.clsid)
  282.             print >>stream, "\t# This class is creatable by the name '%s'" % progId
  283.         except pythoncom.com_error:
  284.             pass
  285.  
  286.         print >>stream, '\tCLSID = ' + repr(self.clsid)
  287.         if self.coclass_clsid is None:
  288.             print >>stream, '\tcoclass_clsid = None'
  289.         else:
  290.             print >>stream, '\tcoclass_clsid = ' + repr(self.coclass_clsid)
  291.         print >>stream
  292.         self.bWritten = 1
  293.  
  294.     
  295.     def WriteEventSinkClassHeader(self, generator):
  296.         generator.checkWriteEventBaseClass()
  297.         doc = self.doc
  298.         stream = generator.file
  299.         print >>stream, 'class ' + self.python_name + ':'
  300.         if doc[1]:
  301.             print >>stream, '\t' + build._safeQuotedString(doc[1])
  302.         
  303.         try:
  304.             progId = pythoncom.ProgIDFromCLSID(self.clsid)
  305.             print >>stream, "\t# This class is creatable by the name '%s'" % progId
  306.         except pythoncom.com_error:
  307.             pass
  308.  
  309.         print >>stream, '\tCLSID = CLSID_Sink = ' + repr(self.clsid)
  310.         if self.coclass_clsid is None:
  311.             print >>stream, '\tcoclass_clsid = None'
  312.         else:
  313.             print >>stream, '\tcoclass_clsid = ' + repr(self.coclass_clsid)
  314.         print >>stream, '\t_public_methods_ = [] # For COM Server support'
  315.         WriteSinkEventMap(self, stream)
  316.         print >>stream
  317.         print >>stream, '\tdef __init__(self, oobj = None):'
  318.         print >>stream, '\t\tif oobj is None:'
  319.         print >>stream, '\t\t\tself._olecp = None'
  320.         print >>stream, '\t\telse:'
  321.         print >>stream, '\t\t\timport win32com.server.util'
  322.         print >>stream, '\t\t\tfrom win32com.server.policy import EventHandlerPolicy'
  323.         print >>stream, '\t\t\tcpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)'
  324.         print >>stream, '\t\t\tcp=cpc.FindConnectionPoint(self.CLSID_Sink)'
  325.         print >>stream, '\t\t\tcookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy))'
  326.         print >>stream, '\t\t\tself._olecp,self._olecp_cookie = cp,cookie'
  327.         print >>stream, '\tdef __del__(self):'
  328.         print >>stream, '\t\ttry:'
  329.         print >>stream, '\t\t\tself.close()'
  330.         print >>stream, '\t\texcept pythoncom.com_error:'
  331.         print >>stream, '\t\t\tpass'
  332.         print >>stream, '\tdef close(self):'
  333.         print >>stream, '\t\tif self._olecp is not None:'
  334.         print >>stream, '\t\t\tcp,cookie,self._olecp,self._olecp_cookie = self._olecp,self._olecp_cookie,None,None'
  335.         print >>stream, '\t\t\tcp.Unadvise(cookie)'
  336.         print >>stream, '\tdef _query_interface_(self, iid):'
  337.         print >>stream, '\t\timport win32com.server.util'
  338.         print >>stream, '\t\tif iid==self.CLSID_Sink: return win32com.server.util.wrap(self)'
  339.         print >>stream
  340.         self.bWritten = 1
  341.  
  342.     
  343.     def WriteCallbackClassBody(self, generator):
  344.         stream = generator.file
  345.         print >>stream, '\t# Event Handlers'
  346.         print >>stream, '\t# If you create handlers, they should have the following prototypes:'
  347.         for name, entry in self.propMapGet.items() + self.propMapPut.items() + self.mapFuncs.items():
  348.             fdesc = entry.desc
  349.             methName = MakeEventMethodName(entry.names[0])
  350.             print >>stream, '#\tdef ' + methName + '(self' + build.BuildCallList(fdesc, entry.names, 'defaultNamedOptArg', 'defaultNamedNotOptArg', 'defaultUnnamedArg', 'pythoncom.Missing', is_comment = True) + '):'
  351.             if entry.doc and entry.doc[1]:
  352.                 print >>stream, '#\t\t' + build._safeQuotedString(entry.doc[1])
  353.                 continue
  354.         print >>stream
  355.         self.bWritten = 1
  356.  
  357.     
  358.     def WriteClassBody(self, generator):
  359.         stream = generator.file
  360.         names = list(self.mapFuncs.keys())
  361.         names.sort()
  362.         specialItems = {
  363.             'count': None,
  364.             'item': None,
  365.             'value': None,
  366.             '_newenum': None }
  367.         itemCount = None
  368.         for name in names:
  369.             entry = self.mapFuncs[name]
  370.             dispid = entry.desc[0]
  371.             if entry.desc[9] & pythoncom.FUNCFLAG_FRESTRICTED and dispid != pythoncom.DISPID_NEWENUM:
  372.                 continue
  373.             if entry.desc[3] != pythoncom.FUNC_DISPATCH:
  374.                 continue
  375.             if dispid == pythoncom.DISPID_VALUE:
  376.                 lkey = 'value'
  377.             elif dispid == pythoncom.DISPID_NEWENUM:
  378.                 specialItems['_newenum'] = (entry, entry.desc[4], None)
  379.                 continue
  380.             else:
  381.                 lkey = name.lower()
  382.             if lkey in specialItems and specialItems[lkey] is None:
  383.                 specialItems[lkey] = (entry, entry.desc[4], None)
  384.             if not generator.bBuildHidden:
  385.                 if not (entry.hidden) or entry.GetResultName():
  386.                     print >>stream, '\t# Result is of type ' + entry.GetResultName()
  387.                 if entry.wasProperty:
  388.                     print >>stream, '\t# The method %s is actually a property, but must be used as a method to correctly pass the arguments' % name
  389.                 ret = self.MakeFuncMethod(entry, build.MakePublicAttributeName(name))
  390.                 for line in ret:
  391.                     print >>stream, line
  392.                 
  393.         print >>stream, '\t_prop_map_get_ = {'
  394.         names = self.propMap.keys()
  395.         names.sort()
  396.         for key in names:
  397.             entry = self.propMap[key]
  398.             if not generator.bBuildHidden:
  399.                 if not (entry.hidden):
  400.                     resultName = entry.GetResultName()
  401.                     if resultName:
  402.                         print >>stream, "\t\t# Property '%s' is an object of type '%s'" % (key, resultName)
  403.                     lkey = key.lower()
  404.                     details = entry.desc
  405.                     resultDesc = details[2]
  406.                     argDesc = ()
  407.                     mapEntry = MakeMapLineEntry(details[0], pythoncom.DISPATCH_PROPERTYGET, resultDesc, argDesc, key, entry.GetResultCLSIDStr())
  408.                     if entry.desc[0] == pythoncom.DISPID_VALUE:
  409.                         lkey = 'value'
  410.                     elif entry.desc[0] == pythoncom.DISPID_NEWENUM:
  411.                         lkey = '_newenum'
  412.                     else:
  413.                         lkey = key.lower()
  414.             if lkey in specialItems and specialItems[lkey] is None:
  415.                 specialItems[lkey] = (entry, pythoncom.DISPATCH_PROPERTYGET, mapEntry)
  416.                 if entry.desc[0] == pythoncom.DISPID_NEWENUM:
  417.                     continue
  418.                 
  419.             print >>stream, '\t\t"%s": %s,' % (build.MakePublicAttributeName(key), mapEntry)
  420.             continue
  421.         
  422.         names = self.propMapGet.keys()
  423.         names.sort()
  424.         for key in names:
  425.             entry = self.propMapGet[key]
  426.             if not generator.bBuildHidden:
  427.                 if not (entry.hidden) or entry.GetResultName():
  428.                     print >>stream, "\t\t# Method '%s' returns object of type '%s'" % (key, entry.GetResultName())
  429.                 details = entry.desc
  430.                 lkey = key.lower()
  431.                 argDesc = details[2]
  432.                 resultDesc = details[8]
  433.                 mapEntry = MakeMapLineEntry(details[0], pythoncom.DISPATCH_PROPERTYGET, resultDesc, argDesc, key, entry.GetResultCLSIDStr())
  434.                 if entry.desc[0] == pythoncom.DISPID_VALUE:
  435.                     lkey = 'value'
  436.                 elif entry.desc[0] == pythoncom.DISPID_NEWENUM:
  437.                     lkey = '_newenum'
  438.                 else:
  439.                     lkey = key.lower()
  440.             if lkey in specialItems and specialItems[lkey] is None:
  441.                 specialItems[lkey] = (entry, pythoncom.DISPATCH_PROPERTYGET, mapEntry)
  442.                 if entry.desc[0] == pythoncom.DISPID_NEWENUM:
  443.                     continue
  444.                 
  445.             print >>stream, '\t\t"%s": %s,' % (build.MakePublicAttributeName(key), mapEntry)
  446.             continue
  447.         
  448.         print >>stream, '\t}'
  449.         print >>stream, '\t_prop_map_put_ = {'
  450.         names = list(self.propMap.keys())
  451.         names.sort()
  452.         for key in names:
  453.             entry = self.propMap[key]
  454.             if not generator.bBuildHidden:
  455.                 if not (entry.hidden):
  456.                     lkey = key.lower()
  457.                     details = entry.desc
  458.                     defArgDesc = build.MakeDefaultArgRepr(details[2])
  459.                     if defArgDesc is None:
  460.                         defArgDesc = ''
  461.                     else:
  462.                         defArgDesc = defArgDesc + ','
  463.             print >>stream, '\t\t"%s" : ((%s, LCID, %d, 0),(%s)),' % (build.MakePublicAttributeName(key), details[0], pythoncom.DISPATCH_PROPERTYPUT, defArgDesc)
  464.             continue
  465.         
  466.         names = list(self.propMapPut.keys())
  467.         names.sort()
  468.         for key in names:
  469.             entry = self.propMapPut[key]
  470.             if not generator.bBuildHidden:
  471.                 if not (entry.hidden):
  472.                     details = entry.desc
  473.                     defArgDesc = MakeDefaultArgsForPropertyPut(details[2])
  474.                     print >>stream, '\t\t"%s": ((%s, LCID, %d, 0),%s),' % (build.MakePublicAttributeName(key), details[0], details[4], defArgDesc)
  475.                     continue
  476.                 print >>stream, '\t}'
  477.                 if specialItems['value']:
  478.                     (entry, invoketype, propArgs) = specialItems['value']
  479.                     if propArgs is None:
  480.                         typename = 'method'
  481.                         ret = self.MakeFuncMethod(entry, '__call__')
  482.                     else:
  483.                         typename = 'property'
  484.                         ret = [
  485.                             '\tdef __call__(self):\n\t\treturn self._ApplyTypes_(*%s)' % propArgs]
  486.                     print >>stream, "\t# Default %s for this class is '%s'" % (typename, entry.names[0])
  487.                     for line in ret:
  488.                         print >>stream, line
  489.                     
  490.                     if sys.version_info > (3, 0):
  491.                         print >>stream, '\tdef __str__(self, *args):'
  492.                         print >>stream, '\t\treturn str(self.__call__(*args))'
  493.                     else:
  494.                         print >>stream, '\tdef __unicode__(self, *args):'
  495.                         print >>stream, '\t\ttry:'
  496.                         print >>stream, '\t\t\treturn unicode(self.__call__(*args))'
  497.                         print >>stream, '\t\texcept pythoncom.com_error:'
  498.                         print >>stream, '\t\t\treturn repr(self)'
  499.                         print >>stream, '\tdef __str__(self, *args):'
  500.                         print >>stream, '\t\treturn str(self.__unicode__(*args))'
  501.                     print >>stream, '\tdef __int__(self, *args):'
  502.                     print >>stream, '\t\treturn int(self.__call__(*args))'
  503.                 if specialItems['_newenum']:
  504.                     (enumEntry, invoketype, propArgs) = specialItems['_newenum']
  505.                     resultCLSID = enumEntry.GetResultCLSIDStr()
  506.                     if resultCLSID == 'None' and 'Item' in self.mapFuncs:
  507.                         resultCLSID = self.mapFuncs['Item'].GetResultCLSIDStr()
  508.                     print >>stream, '\tdef __iter__(self):'
  509.                     print >>stream, '\t\t"Return a Python iterator for this object"'
  510.                     print >>stream, '\t\tob = self._oleobj_.InvokeTypes(%d,LCID,%d,(13, 10),())' % (pythoncom.DISPID_NEWENUM, enumEntry.desc[4])
  511.                     print >>stream, '\t\treturn win32com.client.util.Iterator(ob, %s)' % resultCLSID
  512.                     print >>stream, '\tdef _NewEnum(self):'
  513.                     print >>stream, '\t\t"Create an enumerator from this object"'
  514.                     print >>stream, '\t\treturn win32com.client.util.WrapEnum(self._oleobj_.InvokeTypes(%d,LCID,%d,(13, 10),()),%s)' % (pythoncom.DISPID_NEWENUM, enumEntry.desc[4], resultCLSID)
  515.                     print >>stream, '\tdef __getitem__(self, index):'
  516.                     print >>stream, '\t\t"Allow this class to be accessed as a collection"'
  517.                     print >>stream, "\t\tif '_enum_' not in self.__dict__:"
  518.                     print >>stream, "\t\t\tself.__dict__['_enum_'] = self._NewEnum()"
  519.                     print >>stream, '\t\treturn self._enum_.__getitem__(index)'
  520.                 elif specialItems['item']:
  521.                     (entry, invoketype, propArgs) = specialItems['item']
  522.                     print >>stream, '\t#This class has Item property/method which may take args - allow indexed access'
  523.                     print >>stream, '\tdef __getitem__(self, item):'
  524.                     print >>stream, '\t\treturn self._get_good_object_(self._oleobj_.Invoke(*(%d, LCID, %d, 1, item)), "Item")' % (entry.desc[0], invoketype)
  525.                 if specialItems['count']:
  526.                     (entry, invoketype, propArgs) = specialItems['count']
  527.                     if propArgs is None:
  528.                         typename = 'method'
  529.                         ret = self.MakeFuncMethod(entry, '__len__')
  530.                     else:
  531.                         typename = 'property'
  532.                         ret = [
  533.                             '\tdef __len__(self):\n\t\treturn self._ApplyTypes_(*%s)' % propArgs]
  534.                     print >>stream, '\t#This class has Count() %s - allow len(ob) to provide this' % typename
  535.                     for line in ret:
  536.                         print >>stream, line
  537.                     
  538.                     print >>stream, "\t#This class has a __len__ - this is needed so 'if object:' always returns TRUE."
  539.                     print >>stream, '\tdef __nonzero__(self):'
  540.                     print >>stream, '\t\treturn True'
  541.                 return None
  542.  
  543.  
  544.  
  545. class CoClassItem(build.OleItem, WritableItem):
  546.     order = 5
  547.     typename = 'COCLASS'
  548.     
  549.     def __init__(self, typeinfo, attr, doc = None, sources = [], interfaces = [], bForUser = 1):
  550.         build.OleItem.__init__(self, doc)
  551.         self.clsid = attr[0]
  552.         self.sources = sources
  553.         self.interfaces = interfaces
  554.         self.bIsDispatch = 1
  555.  
  556.     
  557.     def WriteClass(self, generator):
  558.         generator.checkWriteCoClassBaseClass()
  559.         doc = self.doc
  560.         stream = generator.file
  561.         if generator.generate_type == GEN_DEMAND_CHILD:
  562.             referenced_items = []
  563.             for ref, flag in self.sources:
  564.                 referenced_items.append(ref)
  565.             
  566.             for ref, flag in self.interfaces:
  567.                 referenced_items.append(ref)
  568.             
  569.             print >>stream, 'import sys'
  570.             for ref in referenced_items:
  571.                 print >>stream, "__import__('%s.%s')" % (generator.base_mod_name, ref.python_name)
  572.                 print >>stream, "%s = sys.modules['%s.%s'].%s" % (ref.python_name, generator.base_mod_name, ref.python_name, ref.python_name)
  573.                 ref.bWritten = 1
  574.             
  575.         
  576.         try:
  577.             progId = pythoncom.ProgIDFromCLSID(self.clsid)
  578.             print >>stream, "# This CoClass is known by the name '%s'" % progId
  579.         except pythoncom.com_error:
  580.             pass
  581.  
  582.         print >>stream, 'class %s(CoClassBaseClass): # A CoClass' % self.python_name
  583.         if doc and doc[1]:
  584.             print >>stream, '\t# ' + doc[1]
  585.         print >>stream, '\tCLSID = %r' % (self.clsid,)
  586.         print >>stream, '\tcoclass_sources = ['
  587.         defItem = None
  588.         for item, flag in self.sources:
  589.             if flag & pythoncom.IMPLTYPEFLAG_FDEFAULT:
  590.                 defItem = item
  591.             if item.bWritten:
  592.                 key = item.python_name
  593.             else:
  594.                 key = repr(str(item.clsid))
  595.             print >>stream, '\t\t%s,' % key
  596.         
  597.         print >>stream, '\t]'
  598.         if defItem:
  599.             if defItem.bWritten:
  600.                 defName = defItem.python_name
  601.             else:
  602.                 defName = repr(str(defItem.clsid))
  603.             print >>stream, '\tdefault_source = %s' % (defName,)
  604.         print >>stream, '\tcoclass_interfaces = ['
  605.         defItem = None
  606.         for item, flag in self.interfaces:
  607.             if flag & pythoncom.IMPLTYPEFLAG_FDEFAULT:
  608.                 defItem = item
  609.             if item.bWritten:
  610.                 key = item.python_name
  611.             else:
  612.                 key = repr(str(item.clsid))
  613.             print >>stream, '\t\t%s,' % (key,)
  614.         
  615.         print >>stream, '\t]'
  616.         if defItem:
  617.             if defItem.bWritten:
  618.                 defName = defItem.python_name
  619.             else:
  620.                 defName = repr(str(defItem.clsid))
  621.             print >>stream, '\tdefault_interface = %s' % (defName,)
  622.         self.bWritten = 1
  623.         print >>stream
  624.  
  625.  
  626.  
  627. class GeneratorProgress:
  628.     
  629.     def __init__(self):
  630.         pass
  631.  
  632.     
  633.     def Starting(self, tlb_desc):
  634.         '''Called when the process starts.
  635.         '''
  636.         self.tlb_desc = tlb_desc
  637.  
  638.     
  639.     def Finished(self):
  640.         '''Called when the process is complete.
  641.         '''
  642.         pass
  643.  
  644.     
  645.     def SetDescription(self, desc, maxticks = None):
  646.         '''We are entering a major step.  If maxticks, then this
  647.         is how many ticks we expect to make until finished
  648.         '''
  649.         pass
  650.  
  651.     
  652.     def Tick(self, desc = None):
  653.         '''Minor progress step.  Can provide new description if necessary
  654.         '''
  655.         pass
  656.  
  657.     
  658.     def VerboseProgress(self, desc):
  659.         '''Verbose/Debugging output.
  660.         '''
  661.         pass
  662.  
  663.     
  664.     def LogWarning(self, desc):
  665.         '''If a warning is generated
  666.         '''
  667.         pass
  668.  
  669.     
  670.     def LogBeginGenerate(self, filename):
  671.         pass
  672.  
  673.     
  674.     def Close(self):
  675.         pass
  676.  
  677.  
  678.  
  679. class Generator:
  680.     
  681.     def __init__(self, typelib, sourceFilename, progressObject, bBuildHidden = 1, bUnicodeToString = None):
  682.         if not bUnicodeToString is None:
  683.             raise AssertionError, 'this is deprecated and will go away'
  684.         self.bHaveWrittenDispatchBaseClass = None
  685.         self.bHaveWrittenCoClassBaseClass = 0
  686.         self.bHaveWrittenEventBaseClass = 0
  687.         self.typelib = typelib
  688.         self.sourceFilename = sourceFilename
  689.         self.bBuildHidden = bBuildHidden
  690.         self.progress = progressObject
  691.         self.file = None
  692.  
  693.     
  694.     def CollectOleItemInfosFromType(self):
  695.         ret = []
  696.         for i in xrange(self.typelib.GetTypeInfoCount()):
  697.             info = self.typelib.GetTypeInfo(i)
  698.             infotype = self.typelib.GetTypeInfoType(i)
  699.             doc = self.typelib.GetDocumentation(i)
  700.             attr = info.GetTypeAttr()
  701.             ret.append((info, infotype, doc, attr))
  702.         
  703.         return ret
  704.  
  705.     
  706.     def _Build_CoClass(self, type_info_tuple):
  707.         (info, infotype, doc, attr) = type_info_tuple
  708.         child_infos = []
  709.         for j in range(attr[8]):
  710.             flags = info.GetImplTypeFlags(j)
  711.             
  712.             try:
  713.                 refType = info.GetRefTypeInfo(info.GetRefTypeOfImplType(j))
  714.             except pythoncom.com_error:
  715.                 continue
  716.  
  717.             refAttr = refType.GetTypeAttr()
  718.             child_infos.append((info, refAttr.typekind, refType, refType.GetDocumentation(-1), refAttr, flags))
  719.         
  720.         newItem = CoClassItem(info, attr, doc)
  721.         return (newItem, child_infos)
  722.  
  723.     
  724.     def _Build_CoClassChildren(self, coclass, coclass_info, oleItems, vtableItems):
  725.         sources = { }
  726.         interfaces = { }
  727.         for info, info_type, refType, doc, refAttr, flags in coclass_info:
  728.             if not refAttr.typekind == pythoncom.TKIND_DISPATCH:
  729.                 if refAttr.typekind == pythoncom.TKIND_INTERFACE and refAttr[11] & pythoncom.TYPEFLAG_FDISPATCHABLE:
  730.                     clsid = refAttr[0]
  731.                     if clsid in oleItems:
  732.                         dispItem = oleItems[clsid]
  733.                     else:
  734.                         dispItem = DispatchItem(refType, refAttr, doc)
  735.                         oleItems[dispItem.clsid] = dispItem
  736.             dispItem.coclass_clsid = coclass.clsid
  737.             if flags & pythoncom.IMPLTYPEFLAG_FSOURCE:
  738.                 dispItem.bIsSink = 1
  739.                 sources[dispItem.clsid] = (dispItem, flags)
  740.             else:
  741.                 interfaces[dispItem.clsid] = (dispItem, flags)
  742.             if clsid not in vtableItems and refAttr[11] & pythoncom.TYPEFLAG_FDUAL:
  743.                 refType = refType.GetRefTypeInfo(refType.GetRefTypeOfImplType(-1))
  744.                 refAttr = refType.GetTypeAttr()
  745.                 if not refAttr.typekind == pythoncom.TKIND_INTERFACE:
  746.                     raise AssertionError, 'must be interface bynow!'
  747.                 vtableItem = None(refType, refAttr, doc)
  748.                 vtableItems[clsid] = vtableItem
  749.             
  750.         
  751.         coclass.sources = list(sources.values())
  752.         coclass.interfaces = list(interfaces.values())
  753.  
  754.     
  755.     def _Build_Interface(self, type_info_tuple):
  756.         (info, infotype, doc, attr) = type_info_tuple
  757.         oleItem = None
  758.         vtableItem = None
  759.         if (infotype == pythoncom.TKIND_DISPATCH or infotype == pythoncom.TKIND_INTERFACE) and attr[11] & pythoncom.TYPEFLAG_FDISPATCHABLE:
  760.             oleItem = DispatchItem(info, attr, doc)
  761.             if attr.wTypeFlags & pythoncom.TYPEFLAG_FDUAL:
  762.                 refhtype = info.GetRefTypeOfImplType(-1)
  763.                 info = info.GetRefTypeInfo(refhtype)
  764.                 attr = info.GetTypeAttr()
  765.                 infotype = pythoncom.TKIND_INTERFACE
  766.             else:
  767.                 infotype = None
  768.         if not infotype in [
  769.             None,
  770.             pythoncom.TKIND_INTERFACE]:
  771.             raise AssertionError, 'Must be a real interface at this point'
  772.         if None == pythoncom.TKIND_INTERFACE:
  773.             vtableItem = VTableItem(info, attr, doc)
  774.         return (oleItem, vtableItem)
  775.  
  776.     
  777.     def BuildOleItemsFromType(self):
  778.         if not self.bBuildHidden:
  779.             raise AssertionError, 'This code doesnt look at the hidden flag - I thought everyone set it true!?!?!'
  780.         oleItems = None
  781.         enumItems = { }
  782.         recordItems = { }
  783.         vtableItems = { }
  784.         for type_info_tuple in self.CollectOleItemInfosFromType():
  785.             (info, infotype, doc, attr) = type_info_tuple
  786.             clsid = attr[0]
  787.             if infotype == pythoncom.TKIND_ENUM or infotype == pythoncom.TKIND_MODULE:
  788.                 newItem = EnumerationItem(info, attr, doc)
  789.                 enumItems[newItem.doc[0]] = newItem
  790.                 continue
  791.             if infotype in [
  792.                 pythoncom.TKIND_DISPATCH,
  793.                 pythoncom.TKIND_INTERFACE] or clsid not in oleItems:
  794.                 (oleItem, vtableItem) = self._Build_Interface(type_info_tuple)
  795.                 oleItems[clsid] = oleItem
  796.                 if vtableItem is not None:
  797.                     vtableItems[clsid] = vtableItem
  798.                 
  799.             
  800.             if infotype == pythoncom.TKIND_RECORD or infotype == pythoncom.TKIND_UNION:
  801.                 newItem = RecordItem(info, attr, doc)
  802.                 recordItems[newItem.clsid] = newItem
  803.                 continue
  804.             if infotype == pythoncom.TKIND_ALIAS:
  805.                 continue
  806.                 continue
  807.             if infotype == pythoncom.TKIND_COCLASS:
  808.                 (newItem, child_infos) = self._Build_CoClass(type_info_tuple)
  809.                 self._Build_CoClassChildren(newItem, child_infos, oleItems, vtableItems)
  810.                 oleItems[newItem.clsid] = newItem
  811.                 continue
  812.             self.progress.LogWarning('Unknown TKIND found: %d' % infotype)
  813.         
  814.         return (oleItems, enumItems, recordItems, vtableItems)
  815.  
  816.     
  817.     def open_writer(self, filename, encoding = 'mbcs'):
  818.         
  819.         try:
  820.             os.unlink(filename)
  821.         except os.error:
  822.             pass
  823.  
  824.         filename = filename + '.temp'
  825.         if sys.version_info > (3, 0):
  826.             ret = open(filename, 'wt', encoding = encoding)
  827.         else:
  828.             import codecs as codecs
  829.             ret = codecs.open(filename, 'w', encoding)
  830.         return ret
  831.  
  832.     
  833.     def finish_writer(self, filename, f, worked):
  834.         f.close()
  835.         if worked:
  836.             os.rename(filename + '.temp', filename)
  837.         else:
  838.             os.unlink(filename + '.temp')
  839.  
  840.     
  841.     def generate(self, file, is_for_demand = 0):
  842.         if is_for_demand:
  843.             self.generate_type = GEN_DEMAND_BASE
  844.         else:
  845.             self.generate_type = GEN_FULL
  846.         self.file = file
  847.         self.do_generate()
  848.         self.file = None
  849.         self.progress.Finished()
  850.  
  851.     
  852.     def do_gen_file_header(self):
  853.         la = self.typelib.GetLibAttr()
  854.         moduleDoc = self.typelib.GetDocumentation(-1)
  855.         docDesc = ''
  856.         if moduleDoc[1]:
  857.             docDesc = moduleDoc[1]
  858.         self.bHaveWrittenDispatchBaseClass = 0
  859.         self.bHaveWrittenCoClassBaseClass = 0
  860.         self.bHaveWrittenEventBaseClass = 0
  861.         if not self.file.encoding:
  862.             raise AssertionError, self.file
  863.         encoding = None.file.encoding
  864.         print >>self.file, '# -*- coding: %s -*-' % (encoding,)
  865.         print >>self.file, '# Created by makepy.py version %s' % (makepy_version,)
  866.         print >>self.file, '# By python version %s' % (sys.version.replace('\n', '-'),)
  867.         if self.sourceFilename:
  868.             print >>self.file, "# From type library '%s'" % (os.path.split(self.sourceFilename)[1],)
  869.         print >>self.file, '# On %s' % time.ctime(time.time())
  870.         print >>self.file, '"""' + docDesc + '"""'
  871.         print >>self.file, 'makepy_version =', repr(makepy_version)
  872.         print >>self.file, 'python_version = 0x%x' % (sys.hexversion,)
  873.         print >>self.file
  874.         print >>self.file, 'import win32com.client.CLSIDToClass, pythoncom, pywintypes'
  875.         print >>self.file, 'import win32com.client.util'
  876.         print >>self.file, 'from pywintypes import IID'
  877.         print >>self.file, 'from win32com.client import Dispatch'
  878.         print >>self.file
  879.         print >>self.file, '# The following 3 lines may need tweaking for the particular server'
  880.         print >>self.file, '# Candidates are pythoncom.Missing, .Empty and .ArgNotFound'
  881.         print >>self.file, 'defaultNamedOptArg=pythoncom.Empty'
  882.         print >>self.file, 'defaultNamedNotOptArg=pythoncom.Empty'
  883.         print >>self.file, 'defaultUnnamedArg=pythoncom.Empty'
  884.         print >>self.file
  885.         print >>self.file, 'CLSID = ' + repr(la[0])
  886.         print >>self.file, 'MajorVersion = ' + str(la[3])
  887.         print >>self.file, 'MinorVersion = ' + str(la[4])
  888.         print >>self.file, 'LibraryFlags = ' + str(la[5])
  889.         print >>self.file, 'LCID = ' + hex(la[1])
  890.         print >>self.file
  891.  
  892.     
  893.     def do_generate(self):
  894.         moduleDoc = self.typelib.GetDocumentation(-1)
  895.         stream = self.file
  896.         docDesc = ''
  897.         if moduleDoc[1]:
  898.             docDesc = moduleDoc[1]
  899.         self.progress.Starting(docDesc)
  900.         self.progress.SetDescription('Building definitions from type library...')
  901.         self.do_gen_file_header()
  902.         (oleItems, enumItems, recordItems, vtableItems) = self.BuildOleItemsFromType()
  903.         self.progress.SetDescription('Generating...', len(oleItems) + len(enumItems) + len(vtableItems))
  904.         if enumItems:
  905.             print >>stream, 'class constants:'
  906.             items = enumItems.values()
  907.             items.sort()
  908.             num_written = 0
  909.             for oleitem in items:
  910.                 num_written += oleitem.WriteEnumerationItems(stream)
  911.                 self.progress.Tick()
  912.             
  913.             if not num_written:
  914.                 print >>stream, '\tpass'
  915.             print >>stream
  916.         if self.generate_type == GEN_FULL:
  917.             items = [ l for l in oleItems.itervalues() if l is not None ]
  918.             items.sort()
  919.             for oleitem in items:
  920.                 self.progress.Tick()
  921.                 oleitem.WriteClass(self)
  922.             
  923.             items = vtableItems.values()
  924.             items.sort()
  925.             for oleitem in items:
  926.                 self.progress.Tick()
  927.                 oleitem.WriteClass(self)
  928.             
  929.         else:
  930.             self.progress.Tick(len(oleItems) + len(vtableItems))
  931.         print >>stream, 'RecordMap = {'
  932.         for record in recordItems.itervalues():
  933.             if str(record.clsid) == pythoncom.IID_NULL:
  934.                 print >>stream, "\t###%s: %s, # Typedef disabled because it doesn't have a non-null GUID" % (repr(record.doc[0]), repr(str(record.clsid)))
  935.                 continue
  936.             print >>stream, '\t%s: %s,' % (repr(record.doc[0]), repr(str(record.clsid)))
  937.         
  938.         print >>stream, '}'
  939.         print >>stream
  940.         if self.generate_type == GEN_FULL:
  941.             print >>stream, 'CLSIDToClassMap = {'
  942.             for item in oleItems.itervalues():
  943.                 if item is not None and item.bWritten:
  944.                     print >>stream, "\t'%s' : %s," % (str(item.clsid), item.python_name)
  945.                     continue
  946.             print >>stream, '}'
  947.             print >>stream, 'CLSIDToPackageMap = {}'
  948.             print >>stream, 'win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap )'
  949.             print >>stream, 'VTablesToPackageMap = {}'
  950.             print >>stream, 'VTablesToClassMap = {'
  951.             for item in vtableItems.itervalues():
  952.                 print >>stream, "\t'%s' : '%s'," % (item.clsid, item.python_name)
  953.             
  954.             print >>stream, '}'
  955.             print >>stream
  956.         else:
  957.             print >>stream, 'CLSIDToClassMap = {}'
  958.             print >>stream, 'CLSIDToPackageMap = {'
  959.             for item in oleItems.itervalues():
  960.                 if item is not None:
  961.                     print >>stream, "\t'%s' : %s," % (str(item.clsid), repr(item.python_name))
  962.                     continue
  963.             print >>stream, '}'
  964.             print >>stream, 'VTablesToClassMap = {}'
  965.             print >>stream, 'VTablesToPackageMap = {'
  966.             for item in vtableItems.itervalues():
  967.                 print >>stream, "\t'%s' : '%s'," % (item.clsid, item.python_name)
  968.             
  969.             print >>stream, '}'
  970.             print >>stream
  971.         print >>stream
  972.         map = { }
  973.         for item in oleItems.itervalues():
  974.             if item is not None and not isinstance(item, CoClassItem):
  975.                 map[item.python_name] = item.clsid
  976.                 continue
  977.         for item in vtableItems.itervalues():
  978.             map[item.python_name] = item.clsid
  979.         
  980.         print >>stream, 'NamesToIIDMap = {'
  981.         for name, iid in map.iteritems():
  982.             print >>stream, "\t'%s' : '%s'," % (name, iid)
  983.         
  984.         print >>stream, '}'
  985.         print >>stream
  986.         if enumItems:
  987.             print >>stream, 'win32com.client.constants.__dicts__.append(constants.__dict__)'
  988.         print >>stream
  989.  
  990.     
  991.     def generate_child(self, child, dir):
  992.         '''Generate a single child.  May force a few children to be built as we generate deps'''
  993.         self.generate_type = GEN_DEMAND_CHILD
  994.         la = self.typelib.GetLibAttr()
  995.         lcid = la[1]
  996.         clsid = la[0]
  997.         major = la[3]
  998.         minor = la[4]
  999.         self.base_mod_name = 'win32com.gen_py.' + str(clsid)[1:-1] + 'x%sx%sx%s' % (lcid, major, minor)
  1000.         
  1001.         try:
  1002.             oleItems = { }
  1003.             vtableItems = { }
  1004.             infos = self.CollectOleItemInfosFromType()
  1005.             found = 0
  1006.             for type_info_tuple in infos:
  1007.                 (info, infotype, doc, attr) = type_info_tuple
  1008.                 if infotype == pythoncom.TKIND_COCLASS:
  1009.                     (coClassItem, child_infos) = self._Build_CoClass(type_info_tuple)
  1010.                     found = build.MakePublicAttributeName(doc[0]) == child
  1011.                     if not found:
  1012.                         for info, info_type, refType, doc, refAttr, flags in child_infos:
  1013.                             if build.MakePublicAttributeName(doc[0]) == child:
  1014.                                 found = 1
  1015.                                 break
  1016.                                 continue
  1017.                 if found:
  1018.                     oleItems[coClassItem.clsid] = coClassItem
  1019.                     self._Build_CoClassChildren(coClassItem, child_infos, oleItems, vtableItems)
  1020.                     break
  1021.                 
  1022.             
  1023.             if not found:
  1024.                 for type_info_tuple in infos:
  1025.                     (info, infotype, doc, attr) = type_info_tuple
  1026.                     if infotype in [
  1027.                         pythoncom.TKIND_INTERFACE,
  1028.                         pythoncom.TKIND_DISPATCH] or build.MakePublicAttributeName(doc[0]) == child:
  1029.                         found = 1
  1030.                         (oleItem, vtableItem) = self._Build_Interface(type_info_tuple)
  1031.                         oleItems[clsid] = oleItem
  1032.                         if vtableItem is not None:
  1033.                             vtableItems[clsid] = vtableItem
  1034.                         
  1035.                     
  1036.                 
  1037.             if not found:
  1038.                 raise AssertionError, "Cant find the '%s' interface in the CoClasses, or the interfaces" % (child,)
  1039.             items = None
  1040.             for key, value in oleItems.iteritems():
  1041.                 items[key] = (value, None)
  1042.             
  1043.             for key, value in vtableItems.iteritems():
  1044.                 existing = items.get(key, None)
  1045.                 if existing is not None:
  1046.                     new_val = (existing[0], value)
  1047.                 else:
  1048.                     new_val = (None, value)
  1049.                 items[key] = new_val
  1050.             
  1051.             self.progress.SetDescription('Generating...', len(items))
  1052.             for oleitem, vtableitem in items.itervalues():
  1053.                 if not oleitem:
  1054.                     pass
  1055.                 an_item = vtableitem
  1056.                 if not not (self.file):
  1057.                     raise AssertionError, 'already have a file?'
  1058.                 out_name = None.path.join(dir, an_item.python_name) + '.py'
  1059.                 worked = False
  1060.                 self.file = self.open_writer(out_name)
  1061.                 
  1062.                 try:
  1063.                     if oleitem is not None:
  1064.                         self.do_gen_child_item(oleitem)
  1065.                     if vtableitem is not None:
  1066.                         self.do_gen_child_item(vtableitem)
  1067.                     self.progress.Tick()
  1068.                     worked = True
  1069.                 finally:
  1070.                     self.finish_writer(out_name, self.file, worked)
  1071.                     self.file = None
  1072.  
  1073.         finally:
  1074.             self.progress.Finished()
  1075.  
  1076.  
  1077.     
  1078.     def do_gen_child_item(self, oleitem):
  1079.         moduleDoc = self.typelib.GetDocumentation(-1)
  1080.         docDesc = ''
  1081.         if moduleDoc[1]:
  1082.             docDesc = moduleDoc[1]
  1083.         self.progress.Starting(docDesc)
  1084.         self.progress.SetDescription('Building definitions from type library...')
  1085.         self.do_gen_file_header()
  1086.         oleitem.WriteClass(self)
  1087.         if oleitem.bWritten:
  1088.             print >>self.file, 'win32com.client.CLSIDToClass.RegisterCLSID( "%s", %s )' % (oleitem.clsid, oleitem.python_name)
  1089.  
  1090.     
  1091.     def checkWriteDispatchBaseClass(self):
  1092.         if not self.bHaveWrittenDispatchBaseClass:
  1093.             print >>self.file, 'from win32com.client import DispatchBaseClass'
  1094.             self.bHaveWrittenDispatchBaseClass = 1
  1095.  
  1096.     
  1097.     def checkWriteCoClassBaseClass(self):
  1098.         if not self.bHaveWrittenCoClassBaseClass:
  1099.             print >>self.file, 'from win32com.client import CoClassBaseClass'
  1100.             self.bHaveWrittenCoClassBaseClass = 1
  1101.  
  1102.     
  1103.     def checkWriteEventBaseClass(self):
  1104.         if not self.bHaveWrittenEventBaseClass:
  1105.             self.bHaveWrittenEventBaseClass = 1
  1106.  
  1107.  
  1108. if __name__ == '__main__':
  1109.     print 'This is a worker module.  Please use makepy to generate Python files.'
  1110.