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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import __builtin__
  5. NeedUnicodeConversions = not hasattr(__builtin__, 'unicode')
  6. import dynamic
  7. import gencache
  8. import pythoncom
  9. import sys
  10. import pywintypes
  11. from types import TupleType
  12. from pywintypes import UnicodeType
  13. _PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
  14.  
  15. def __WrapDispatch(dispatch, userName = None, resultCLSID = None, typeinfo = None, UnicodeToString = NeedUnicodeConversions, clsctx = pythoncom.CLSCTX_SERVER, WrapperClass = None):
  16.     if resultCLSID is None:
  17.         
  18.         try:
  19.             typeinfo = dispatch.GetTypeInfo()
  20.             if typeinfo is not None:
  21.                 resultCLSID = str(typeinfo.GetTypeAttr()[0])
  22.         except (pythoncom.com_error, AttributeError):
  23.             pass
  24.         except:
  25.             None<EXCEPTION MATCH>(pythoncom.com_error, AttributeError)
  26.         
  27.  
  28.     None<EXCEPTION MATCH>(pythoncom.com_error, AttributeError)
  29.     if resultCLSID is not None:
  30.         import gencache
  31.         klass = gencache.GetClassForCLSID(resultCLSID)
  32.         if klass is not None:
  33.             return klass(dispatch)
  34.     
  35.     if WrapperClass is None:
  36.         WrapperClass = CDispatch
  37.     
  38.     return dynamic.Dispatch(dispatch, userName, WrapperClass, typeinfo, UnicodeToString = UnicodeToString, clsctx = clsctx)
  39.  
  40.  
  41. def GetObject(Pathname = None, Class = None, clsctx = None):
  42.     if clsctx is None:
  43.         clsctx = pythoncom.CLSCTX_ALL
  44.     
  45.     if (Pathname is None or Class is None or Pathname is not None) and Class is not None:
  46.         raise ValueError, 'You must specify a value for Pathname or Class, but not both.'
  47.     Class is not None
  48.     if Class is not None:
  49.         return GetActiveObject(Class, clsctx)
  50.     return Moniker(Pathname, clsctx)
  51.  
  52.  
  53. def GetActiveObject(Class, clsctx = pythoncom.CLSCTX_ALL):
  54.     resultCLSID = pywintypes.IID(Class)
  55.     dispatch = pythoncom.GetActiveObject(resultCLSID)
  56.     dispatch = dispatch.QueryInterface(pythoncom.IID_IDispatch)
  57.     return __WrapDispatch(dispatch, Class, resultCLSID = resultCLSID, clsctx = clsctx)
  58.  
  59.  
  60. def Moniker(Pathname, clsctx = pythoncom.CLSCTX_ALL):
  61.     (moniker, i, bindCtx) = pythoncom.MkParseDisplayName(Pathname)
  62.     dispatch = moniker.BindToObject(bindCtx, None, pythoncom.IID_IDispatch)
  63.     return __WrapDispatch(dispatch, Pathname, clsctx = clsctx)
  64.  
  65.  
  66. def Dispatch(dispatch, userName = None, resultCLSID = None, typeinfo = None, UnicodeToString = NeedUnicodeConversions, clsctx = pythoncom.CLSCTX_SERVER):
  67.     (dispatch, userName) = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
  68.     return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx)
  69.  
  70.  
  71. def DispatchEx(clsid, machine = None, userName = None, resultCLSID = None, typeinfo = None, UnicodeToString = NeedUnicodeConversions, clsctx = None):
  72.     if clsctx is None:
  73.         clsctx = pythoncom.CLSCTX_SERVER
  74.         if machine is not None:
  75.             clsctx = clsctx & ~(pythoncom.CLSCTX_INPROC)
  76.         
  77.     
  78.     if machine is None:
  79.         serverInfo = None
  80.     else:
  81.         serverInfo = (machine,)
  82.     if userName is None:
  83.         userName = clsid
  84.     
  85.     dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx, serverInfo, (pythoncom.IID_IDispatch,))[0]
  86.     return Dispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString = UnicodeToString, clsctx = clsctx)
  87.  
  88.  
  89. class CDispatch(dynamic.CDispatch):
  90.     
  91.     def _wrap_dispatch_(self, ob, userName = None, returnCLSID = None, UnicodeToString = NeedUnicodeConversions):
  92.         return Dispatch(ob, userName, returnCLSID, None, UnicodeToString)
  93.  
  94.  
  95.  
  96. def CastTo(ob, target):
  97.     if hasattr(target, 'index'):
  98.         if not ob.__class__.__dict__.has_key('CLSID'):
  99.             ob = gencache.EnsureDispatch(ob)
  100.         
  101.         if not ob.__class__.__dict__.has_key('CLSID'):
  102.             raise ValueError, 'Must be a makepy-able object for this to work'
  103.         ob.__class__.__dict__.has_key('CLSID')
  104.         clsid = ob.CLSID
  105.         mod = gencache.GetModuleForCLSID(clsid)
  106.         mod = gencache.GetModuleForTypelib(mod.CLSID, mod.LCID, mod.MajorVersion, mod.MinorVersion)
  107.         target_clsid = mod.NamesToIIDMap.get(target)
  108.         if target_clsid is None:
  109.             raise ValueError, "The interface name '%s' does not appear in the same library as object '%r'" % (target, ob)
  110.         target_clsid is None
  111.         mod = gencache.GetModuleForCLSID(target_clsid)
  112.         target_class = getattr(mod, target)
  113.         target_class = getattr(target_class, 'default_interface', target_class)
  114.         return target_class(ob)
  115.     raise ValueError, 'This object can not be cast'
  116.  
  117.  
  118. class Constants:
  119.     
  120.     def __init__(self):
  121.         self.__dicts__ = []
  122.  
  123.     
  124.     def __getattr__(self, a):
  125.         for d in self.__dicts__:
  126.             if d.has_key(a):
  127.                 return d[a]
  128.         
  129.         raise AttributeError, a
  130.  
  131.  
  132. constants = Constants()
  133.  
  134. def _event_setattr_(self, attr, val):
  135.     
  136.     try:
  137.         self.__class__.__bases__[0].__setattr__(self, attr, val)
  138.     except AttributeError:
  139.         self.__dict__[attr] = val
  140.  
  141.  
  142.  
  143. class EventsProxy:
  144.     
  145.     def __init__(self, ob):
  146.         self.__dict__['_obj_'] = ob
  147.  
  148.     
  149.     def __del__(self):
  150.         
  151.         try:
  152.             self._obj_.close()
  153.         except pythoncom.com_error:
  154.             pass
  155.  
  156.  
  157.     
  158.     def __getattr__(self, attr):
  159.         return getattr(self._obj_, attr)
  160.  
  161.     
  162.     def __setattr__(self, attr, val):
  163.         setattr(self._obj_, attr, val)
  164.  
  165.  
  166.  
  167. def DispatchWithEvents(clsid, user_event_class):
  168.     disp = Dispatch(clsid)
  169.     if not disp.__class__.__dict__.get('CLSID'):
  170.         
  171.         try:
  172.             ti = disp._oleobj_.GetTypeInfo()
  173.             disp_clsid = ti.GetTypeAttr()[0]
  174.             (tlb, index) = ti.GetContainingTypeLib()
  175.             tla = tlb.GetLibAttr()
  176.             gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile = 0)
  177.             disp_class = gencache.GetClassForProgID(str(disp_clsid))
  178.         except pythoncom.com_error:
  179.             raise TypeError, 'This COM object can not automate the makepy process - please run makepy manually for this object'
  180.         except:
  181.             None<EXCEPTION MATCH>pythoncom.com_error
  182.         
  183.  
  184.     None<EXCEPTION MATCH>pythoncom.com_error
  185.     disp_class = disp.__class__
  186.     clsid = disp_class.CLSID
  187.     import new
  188.     events_class = getevents(clsid)
  189.     if events_class is None:
  190.         raise ValueError, 'This COM object does not support events.'
  191.     events_class is None
  192.     result_class = new.classobj('COMEventClass', (disp_class, events_class, user_event_class), {
  193.         '__setattr__': _event_setattr_ })
  194.     instance = result_class(disp._oleobj_)
  195.     events_class.__init__(instance, instance)
  196.     if hasattr(user_event_class, '__init__'):
  197.         user_event_class.__init__(instance)
  198.     
  199.     return EventsProxy(instance)
  200.  
  201.  
  202. def WithEvents(disp, user_event_class):
  203.     disp = Dispatch(disp)
  204.     if not disp.__class__.__dict__.get('CLSID'):
  205.         
  206.         try:
  207.             ti = disp._oleobj_.GetTypeInfo()
  208.             disp_clsid = ti.GetTypeAttr()[0]
  209.             (tlb, index) = ti.GetContainingTypeLib()
  210.             tla = tlb.GetLibAttr()
  211.             gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile = 0)
  212.             disp_class = gencache.GetClassForProgID(str(disp_clsid))
  213.         except pythoncom.com_error:
  214.             raise TypeError, 'This COM object can not automate the makepy process - please run makepy manually for this object'
  215.         except:
  216.             None<EXCEPTION MATCH>pythoncom.com_error
  217.         
  218.  
  219.     None<EXCEPTION MATCH>pythoncom.com_error
  220.     disp_class = disp.__class__
  221.     clsid = disp_class.CLSID
  222.     import new
  223.     events_class = getevents(clsid)
  224.     if events_class is None:
  225.         raise ValueError, 'This COM object does not support events.'
  226.     events_class is None
  227.     result_class = new.classobj('COMEventClass', (events_class, user_event_class), { })
  228.     instance = result_class(disp)
  229.     if hasattr(user_event_class, '__init__'):
  230.         user_event_class.__init__(instance)
  231.     
  232.     return instance
  233.  
  234.  
  235. def getevents(clsid):
  236.     clsid = str(pywintypes.IID(clsid))
  237.     klass = gencache.GetClassForCLSID(clsid)
  238.     
  239.     try:
  240.         return klass.default_source
  241.     except AttributeError:
  242.         
  243.         try:
  244.             return gencache.GetClassForCLSID(klass.coclass_clsid).default_source
  245.         except AttributeError:
  246.             return None
  247.         
  248.  
  249.         None<EXCEPTION MATCH>AttributeError
  250.  
  251.  
  252.  
  253. def Record(name, object):
  254.     import gencache
  255.     object = gencache.EnsureDispatch(object)
  256.     module = sys.modules[object.__class__.__module__]
  257.     package = gencache.GetModuleForTypelib(module.CLSID, module.LCID, module.MajorVersion, module.MinorVersion)
  258.     
  259.     try:
  260.         struct_guid = package.RecordMap[name]
  261.     except KeyError:
  262.         raise ValueError, "The structure '%s' is not defined in module '%s'" % (name, package)
  263.  
  264.     return pythoncom.GetRecordFromGuids(module.CLSID, module.MajorVersion, module.MinorVersion, module.LCID, struct_guid)
  265.  
  266.  
  267. class DispatchBaseClass:
  268.     
  269.     def __init__(self, oobj = None):
  270.         if oobj is None:
  271.             oobj = pythoncom.new(self.CLSID)
  272.         elif type(self) == type(oobj):
  273.             
  274.             try:
  275.                 oobj = oobj._oleobj_.QueryInterface(self.CLSID, pythoncom.IID_IDispatch)
  276.             except pythoncom.com_error:
  277.                 details = None
  278.                 import winerror
  279.                 if details[0] != winerror.E_NOINTERFACE:
  280.                     raise 
  281.                 details[0] != winerror.E_NOINTERFACE
  282.                 oobj = oobj._oleobj_
  283.             except:
  284.                 None<EXCEPTION MATCH>pythoncom.com_error
  285.             
  286.  
  287.         None<EXCEPTION MATCH>pythoncom.com_error
  288.         self.__dict__['_oleobj_'] = oobj
  289.  
  290.     
  291.     def __repr__(self):
  292.         
  293.         try:
  294.             mod_doc = sys.modules[self.__class__.__module__].__doc__
  295.             if mod_doc:
  296.                 mod_name = 'win32com.gen_py.' + mod_doc
  297.             else:
  298.                 mod_name = sys.modules[self.__class__.__module__].__name__
  299.         except KeyError:
  300.             mod_name = 'win32com.gen_py.unknown'
  301.  
  302.         return '<%s.%s instance at 0x%s>' % (mod_name, self.__class__.__name__, id(self))
  303.  
  304.     
  305.     def __cmp__(self, other):
  306.         other = getattr(other, '_oleobj_', other)
  307.         return cmp(self._oleobj_, other)
  308.  
  309.     
  310.     def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
  311.         return self._get_good_object_(self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), user, resultCLSID)
  312.  
  313.     
  314.     def __getattr__(self, attr):
  315.         args = self._prop_map_get_.get(attr)
  316.         if args is None:
  317.             raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr)
  318.         args is None
  319.         return self._ApplyTypes_(*args)
  320.  
  321.     
  322.     def __setattr__(self, attr, value):
  323.         if self.__dict__.has_key(attr):
  324.             self.__dict__[attr] = value
  325.             return None
  326.         
  327.         try:
  328.             (args, defArgs) = self._prop_map_put_[attr]
  329.         except KeyError:
  330.             self.__dict__.has_key(attr)
  331.             self.__dict__.has_key(attr)
  332.             raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr)
  333.         except:
  334.             self.__dict__.has_key(attr)
  335.  
  336.         self._oleobj_.Invoke(*args + (value,) + defArgs)
  337.  
  338.     
  339.     def _get_good_single_object_(self, obj, obUserName = None, resultCLSID = None):
  340.         return _get_good_single_object_(obj, obUserName, resultCLSID)
  341.  
  342.     
  343.     def _get_good_object_(self, obj, obUserName = None, resultCLSID = None):
  344.         return _get_good_object_(obj, obUserName, resultCLSID)
  345.  
  346.  
  347.  
  348. def _get_good_single_object_(obj, obUserName = None, resultCLSID = None):
  349.     if _PyIDispatchType == type(obj):
  350.         return Dispatch(obj, obUserName, resultCLSID, UnicodeToString = NeedUnicodeConversions)
  351.     if NeedUnicodeConversions and UnicodeType == type(obj):
  352.         return str(obj)
  353.     return obj
  354.  
  355.  
  356. def _get_good_object_(obj, obUserName = None, resultCLSID = None):
  357.     if obj is None:
  358.         return None
  359.     if type(obj) == TupleType:
  360.         obUserNameTuple = (obUserName,) * len(obj)
  361.         resultCLSIDTuple = (resultCLSID,) * len(obj)
  362.         return tuple(map(_get_good_object_, obj, obUserNameTuple, resultCLSIDTuple))
  363.     return _get_good_single_object_(obj, obUserName, resultCLSID)
  364.  
  365.  
  366. class CoClassBaseClass:
  367.     
  368.     def __init__(self, oobj = None):
  369.         if oobj is None:
  370.             oobj = pythoncom.new(self.CLSID)
  371.         
  372.         self.__dict__['_dispobj_'] = self.default_interface(oobj)
  373.  
  374.     
  375.     def __repr__(self):
  376.         return '<win32com.gen_py.%s.%s>' % (__doc__, self.__class__.__name__)
  377.  
  378.     
  379.     def __getattr__(self, attr):
  380.         d = self.__dict__['_dispobj_']
  381.         if d is not None:
  382.             return getattr(d, attr)
  383.         raise AttributeError, attr
  384.  
  385.     
  386.     def __setattr__(self, attr, value):
  387.         if self.__dict__.has_key(attr):
  388.             self.__dict__[attr] = value
  389.             return None
  390.         
  391.         try:
  392.             d = self.__dict__['_dispobj_']
  393.             if d is not None:
  394.                 d.__setattr__(attr, value)
  395.                 return None
  396.         except AttributeError:
  397.             self.__dict__.has_key(attr)
  398.             self.__dict__.has_key(attr)
  399.         except:
  400.             self.__dict__.has_key(attr)
  401.  
  402.         self.__dict__[attr] = value
  403.  
  404.  
  405.