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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  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, _get_good_object_
  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.     return EnumVARIANT(ob, resultCLSID)
  23.  
  24.  
  25. class Enumerator:
  26.     '''A class that provides indexed access into an Enumerator
  27.  
  28. \tBy wrapping a PyIEnum* object in this class, you can perform
  29. \tnatural looping and indexing into the Enumerator.
  30.  
  31. \tLooping is very efficient, but it should be noted that although random 
  32. \taccess is supported, the underlying object is still an enumerator, so 
  33. \tthis will force many reset-and-seek operations to find the requested index.
  34.  
  35. \t'''
  36.     
  37.     def __init__(self, enum):
  38.         self._oleobj_ = enum
  39.         self.index = -1
  40.  
  41.     
  42.     def __getitem__(self, index):
  43.         return self._Enumerator__GetIndex(index)
  44.  
  45.     
  46.     def __call__(self, index):
  47.         return self._Enumerator__GetIndex(index)
  48.  
  49.     
  50.     def __GetIndex(self, index):
  51.         if type(index) != type(0):
  52.             raise TypeError('Only integer indexes are supported for enumerators')
  53.         if index != self.index + 1:
  54.             self._oleobj_.Reset()
  55.             if index:
  56.                 self._oleobj_.Skip(index)
  57.             
  58.         self.index = index
  59.         result = self._oleobj_.Next(1)
  60.         if len(result):
  61.             return self._make_retval_(result[0])
  62.         raise None('list index out of range')
  63.  
  64.     
  65.     def Next(self, count = 1):
  66.         ret = self._oleobj_.Next(count)
  67.         realRets = []
  68.         for r in ret:
  69.             realRets.append(self._make_retval_(r))
  70.         
  71.         return tuple(realRets)
  72.  
  73.     
  74.     def Reset(self):
  75.         return self._oleobj_.Reset()
  76.  
  77.     
  78.     def Clone(self):
  79.         return self.__class__(self._oleobj_.Clone(), self.resultCLSID)
  80.  
  81.     
  82.     def _make_retval_(self, result):
  83.         return result
  84.  
  85.  
  86.  
  87. class EnumVARIANT(Enumerator):
  88.     
  89.     def __init__(self, enum, resultCLSID = None):
  90.         self.resultCLSID = resultCLSID
  91.         Enumerator.__init__(self, enum)
  92.  
  93.     
  94.     def _make_retval_(self, result):
  95.         return _get_good_object_(result, resultCLSID = self.resultCLSID)
  96.  
  97.  
  98.  
  99. class Iterator:
  100.     
  101.     def __init__(self, enum, resultCLSID = None):
  102.         self.resultCLSID = resultCLSID
  103.         self._iter_ = iter(enum.QueryInterface(pythoncom.IID_IEnumVARIANT))
  104.  
  105.     
  106.     def __iter__(self):
  107.         return self
  108.  
  109.     
  110.     def next(self):
  111.         return _get_good_object_(self._iter_.next(), resultCLSID = self.resultCLSID)
  112.  
  113.  
  114.