home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2703 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  7.0 KB  |  209 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import pythoncom
  5. import policy
  6. import winerror
  7. from exception import COMException
  8.  
  9. def wrap(ob, iid = None, usePolicy = None, useDispatcher = None):
  10.     if usePolicy is None:
  11.         usePolicy = policy.DefaultPolicy
  12.     
  13.     if useDispatcher == 1:
  14.         import win32com.server.dispatcher as win32com
  15.         useDispatcher = win32com.server.dispatcher.DefaultDebugDispatcher
  16.     
  17.     if useDispatcher is None or useDispatcher == 0:
  18.         ob = usePolicy(ob)
  19.     else:
  20.         ob = useDispatcher(usePolicy, ob)
  21.     ob = pythoncom.WrapObject(ob)
  22.     if iid is not None:
  23.         ob = ob.QueryInterface(iid)
  24.     
  25.     return ob
  26.  
  27.  
  28. def unwrap(ob):
  29.     ob = pythoncom.UnwrapObject(ob)
  30.     if hasattr(ob, 'policy'):
  31.         ob = ob.policy
  32.     
  33.     return ob._obj_
  34.  
  35.  
  36. class ListEnumerator:
  37.     _public_methods_ = [
  38.         'Next',
  39.         'Skip',
  40.         'Reset',
  41.         'Clone']
  42.     
  43.     def __init__(self, data, index = 0, iid = pythoncom.IID_IEnumVARIANT):
  44.         self._list_ = data
  45.         self.index = index
  46.         self._iid_ = iid
  47.  
  48.     
  49.     def _query_interface_(self, iid):
  50.         if iid == self._iid_:
  51.             return 1
  52.  
  53.     
  54.     def Next(self, count):
  55.         result = self._list_[self.index:self.index + count]
  56.         self.Skip(count)
  57.         return result
  58.  
  59.     
  60.     def Skip(self, count):
  61.         end = self.index + count
  62.         if end > len(self._list_):
  63.             end = len(self._list_)
  64.         
  65.         self.index = end
  66.  
  67.     
  68.     def Reset(self):
  69.         self.index = 0
  70.  
  71.     
  72.     def Clone(self):
  73.         return self._wrap(self.__class__(self._list_, self.index))
  74.  
  75.     
  76.     def _wrap(self, ob):
  77.         return wrap(ob)
  78.  
  79.  
  80.  
  81. class ListEnumeratorGateway(ListEnumerator):
  82.     
  83.     def Next(self, count):
  84.         result = self._list_[self.index:self.index + count]
  85.         self.Skip(count)
  86.         return map(self._wrap, result)
  87.  
  88.  
  89.  
  90. def NewEnum(seq, cls = ListEnumerator, iid = pythoncom.IID_IEnumVARIANT, usePolicy = None, useDispatcher = None):
  91.     ob = cls(seq, iid = iid)
  92.     return wrap(ob, iid, usePolicy = usePolicy, useDispatcher = useDispatcher)
  93.  
  94.  
  95. class Collection:
  96.     _public_methods_ = [
  97.         'Item',
  98.         'Count',
  99.         'Add',
  100.         'Remove',
  101.         'Insert']
  102.     
  103.     def __init__(self, data = None, readOnly = 0):
  104.         if data is None:
  105.             data = []
  106.         
  107.         self.data = data
  108.         if readOnly:
  109.             self._public_methods_ = [
  110.                 'Item',
  111.                 'Count']
  112.         
  113.  
  114.     
  115.     def Item(self, *args):
  116.         if len(args) != 1:
  117.             raise COMException(scode = winerror.DISP_E_BADPARAMCOUNT)
  118.         len(args) != 1
  119.         
  120.         try:
  121.             return self.data[args[0]]
  122.         except IndexError:
  123.             desc = None
  124.             raise COMException(scode = winerror.DISP_E_BADINDEX, desc = str(desc))
  125.  
  126.  
  127.     _value_ = Item
  128.     
  129.     def Count(self):
  130.         return len(self.data)
  131.  
  132.     
  133.     def Add(self, value):
  134.         self.data.append(value)
  135.  
  136.     
  137.     def Remove(self, index):
  138.         
  139.         try:
  140.             del self.data[index]
  141.         except IndexError:
  142.             desc = None
  143.             raise COMException(scode = winerror.DISP_E_BADINDEX, desc = str(desc))
  144.  
  145.  
  146.     
  147.     def Insert(self, index, value):
  148.         
  149.         try:
  150.             index = int(index)
  151.         except (ValueError, TypeError):
  152.             raise COMException(scode = winerror.DISP_E_TYPEMISMATCH)
  153.  
  154.         self.data.insert(index, value)
  155.  
  156.     
  157.     def _NewEnum(self):
  158.         return NewEnum(self.data)
  159.  
  160.  
  161.  
  162. def NewCollection(seq, cls = Collection):
  163.     return pythoncom.WrapObject(policy.DefaultPolicy(cls(seq)), pythoncom.IID_IDispatch, pythoncom.IID_IDispatch)
  164.  
  165.  
  166. class FileStream:
  167.     _public_methods_ = [
  168.         'Read',
  169.         'Write',
  170.         'Clone',
  171.         'CopyTo',
  172.         'Seek']
  173.     _com_interfaces_ = [
  174.         pythoncom.IID_IStream]
  175.     
  176.     def __init__(self, file):
  177.         self.file = file
  178.  
  179.     
  180.     def Read(self, amount):
  181.         return self.file.read(amount)
  182.  
  183.     
  184.     def Write(self, data):
  185.         self.file.write(data)
  186.         return len(data)
  187.  
  188.     
  189.     def Clone(self):
  190.         return self._wrap(self.__class__(self.file))
  191.  
  192.     
  193.     def CopyTo(self, dest, cb):
  194.         data = self.file.read(cb)
  195.         cbread = len(data)
  196.         dest.Write(data)
  197.         return (cbread, cbread)
  198.  
  199.     
  200.     def Seek(self, offset, origin):
  201.         self.file.seek(offset, origin)
  202.         return self.file.tell()
  203.  
  204.     
  205.     def _wrap(self, ob):
  206.         return wrap(ob)
  207.  
  208.  
  209.