home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / win32com / client / util.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  4.6 KB  |  108 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''General client side utilities.
  5.  
  6. This module contains utility functions, used primarily by advanced COM
  7. programmers, or other COM modules.
  8. '''
  9. import pythoncom
  10. from win32com.client import Dispatch
  11. PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
  12.  
  13. def WrapEnum(ob, resultCLSID = None):
  14.     '''Wrap an object in a VARIANT enumerator.  
  15.  
  16. \tAll VT_DISPATCHs returned by the enumerator are converted to wrapper objects
  17. \t(which may be either a class instance, or a dynamic.Dispatch type object).
  18.  
  19. \t'''
  20.     if type(ob) != pythoncom.TypeIIDs[pythoncom.IID_IEnumVARIANT]:
  21.         ob = ob.QueryInterface(pythoncom.IID_IEnumVARIANT)
  22.     
  23.     return EnumVARIANT(ob, resultCLSID)
  24.  
  25.  
  26. class Enumerator:
  27.     '''A class that provides indexed access into an Enumerator
  28.  
  29. \tBy wrapping a PyIEnum* object in this class, you can perform
  30. \tnatural looping and indexing into the Enumerator.
  31.  
  32. \tLooping is very efficient, but it should be noted that although random 
  33. \taccess is supported, the underlying object is still an enumerator, so 
  34. \tthis will force many reset-and-seek operations to find the requested index.
  35.  
  36. \t'''
  37.     
  38.     def __init__(self, enum):
  39.         self._oleobj_ = enum
  40.         self.index = -1
  41.  
  42.     
  43.     def __getitem__(self, index):
  44.         return self._Enumerator__GetIndex(index)
  45.  
  46.     
  47.     def __call__(self, index):
  48.         return self._Enumerator__GetIndex(index)
  49.  
  50.     
  51.     def __GetIndex(self, index):
  52.         if type(index) != type(0):
  53.             raise TypeError, 'Only integer indexes are supported for enumerators'
  54.         
  55.         if index != self.index + 1:
  56.             self._oleobj_.Reset()
  57.             if index:
  58.                 self._oleobj_.Skip(index)
  59.             
  60.         
  61.         self.index = index
  62.         result = self._oleobj_.Next(1)
  63.         if len(result):
  64.             return self._make_retval_(result[0])
  65.         
  66.         raise IndexError, 'list index out of range'
  67.  
  68.     
  69.     def Next(self, count = 1):
  70.         ret = self._oleobj_.Next(count)
  71.         if ret is None:
  72.             return None
  73.         
  74.         realRets = []
  75.         for r in ret:
  76.             realRets.append(self._make_retval_(r))
  77.         
  78.         return tuple(realRets)
  79.  
  80.     
  81.     def Reset(self):
  82.         return self._oleobj_.Reset()
  83.  
  84.     
  85.     def Clone(self):
  86.         return self.__class__(self._oleobj_.Clone(), self.resultCLSID)
  87.  
  88.     
  89.     def _make_retval_(self, result):
  90.         return result
  91.  
  92.  
  93.  
  94. class EnumVARIANT(Enumerator):
  95.     
  96.     def __init__(self, enum, resultCLSID = None):
  97.         self.resultCLSID = resultCLSID
  98.         Enumerator.__init__(self, enum)
  99.  
  100.     
  101.     def _make_retval_(self, result):
  102.         if type(result) == PyIDispatchType:
  103.             result = Dispatch(result, resultCLSID = self.resultCLSID)
  104.         
  105.         return result
  106.  
  107.  
  108.