ó
˛Í[Mc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z e  j e  j Z d d d d e  j	 d d  Z
 d d d d  Z e  j d  Z e  j d  Z d d d d e  j	 d  Z d d d d d d d  Z d e j f d	     YZ d
   Z d d d     YZ e   Z d   Z d d d     YZ d   Z d   Z d   Z d   Z d d d     YZ d d d  Z d d d  Z d d d     YZ d S(   i˙˙˙˙Nc   	      C   sç   | d k s t d  | d k rv y5 |  j   } | d k	 rU t | j   d  } n  Wqv t j t f k
 rr qv Xn  | d k	 rś d d l } | j	 |  } | d k	 rś | |   Sn  | d k rË t
 } n  t j |  | | | d | S(   s{   
    Helper function to return a makepy generated class for a CLSID if it exists,
    otherwise cope by using CDispatch.
  s#   this is deprecated and will go awayi    i˙˙˙˙Nt   clsctx(   t   Nonet   AssertionErrort   GetTypeInfot   strt   GetTypeAttrt	   pythoncomt	   com_errort   AttributeErrort   gencachet   GetClassForCLSIDt	   CDispatcht   dynamict   Dispatch(	   t   dispatcht   userNamet   resultCLSIDt   typeinfot   UnicodeToStringR    t   WrapperClassR	   t   klass(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __WrapDispatch   s      	c         C   s   | d k r t j } n  |  d k r0 | d k sH |  d k	 rW | d k	 rW t d   n  | d k	 rp t | |  St |  |  Sd S(   s@  
    Mimic VB's GetObject() function.

    ob = GetObject(Class = "ProgID") or GetObject(Class = clsid) will
    connect to an already running instance of the COM object.
    
    ob = GetObject(r"c:lahlahoo.xls") (aka the COM moniker syntax)
    will return a ready to use Python wrapping of the required COM object.

    Note: You must specifiy one or the other of these arguments. I know
    this isn't pretty, but it is what VB does. Blech. If you don't
    I'll throw ValueError at you. :)
    
    This will most likely throw pythoncom.com_error if anything fails.
  s=   You must specify a value for Pathname or Class, but not both.N(   R   R   t
   CLSCTX_ALLt
   ValueErrort   GetActiveObjectt   Moniker(   t   Pathnamet   ClassR    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt	   GetObject.   s    c         C   sI   t  j |   } t j |  } | j t j  } t | |  d | d | S(   sJ   
    Python friendly version of GetObject's ProgID/CLSID functionality.
  R   R    (   t
   pywintypest   IIDR   R   t   QueryInterfacet   IID_IDispatchR   (   R   R    R   R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   J   s    c         C   sC   t  j |   \ } } } | j | d t  j  } t | |  d | S(   sE   
    Python friendly version of GetObject's moniker functionality.
  R    N(   R   t   MkParseDisplayNamet   BindToObjectR   R    R   (   R   R    t   monikert   it   bindCtxR   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   S   s    c         C   sI   | d k s t d  t j |  | |  \ }  } t |  | | | d | S(   s'   Creates a Dispatch based COM object.
  s#   this is deprecated and will go awayR    N(   R   R   R   t   _GetGoodDispatchAndUserNameR   (   R   R   R   R   R   R    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   [   s    c   	      C   sť   | d k s t d  | d k rJ t j } | d k	 rJ | t j @} qJ n  | d k r_ d } n	 | f } | d k r} |  } n  t j |  d | | t j f  d } t | | | | d | S(   s=   Creates a Dispatch based COM object on a specific machine.
  s#   this is deprecated and will go awayi    R    N(   R   R   R   t   CLSCTX_SERVERt   CLSCTX_INPROCt   CoCreateInstanceExR    R   (	   t   clsidt   machineR   R   R   R   R    t
   serverInfoR   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt
   DispatchExb   s    	 		 	%R   c           B   s    e  Z d  Z d d d d  Z RS(   sî   
    The dynamic class used as a last resort.
    The purpose of this overriding of dynamic.CDispatch is to perpetuate the policy
    of using the makepy generated wrapper Python class instead of dynamic.CDispatch
    if/when possible.
  c         C   s(   | d  k s t d  t | | | d   S(   Ns#   this is deprecated and will go away(   R   R   R   (   t   selft   obR   t   returnCLSIDR   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   _wrap_dispatch_{   s    N(   t   __name__t
   __module__t   __doc__R   R1   (    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   t   s   c         C   s  t  | d  rd |  j j k r3 t j |   }  n  d |  j j k rT t d   n  |  j } t j |  } t j | j | j	 | j
 | j  } | j j |  } | d k rÇ t d | |  f   n  t j |  } t | |  } t | d |  } | |   St  d S(   s(   'Cast' a COM object to another interfacet   indext   CLSIDs-   Must be a makepy-able object for this to worksJ   The interface name '%s' does not appear in the same library as object '%r't   default_interfaceN(   t   hasattrt	   __class__t   __dict__R	   t   EnsureDispatchR   R6   t   GetModuleForCLSIDt   GetModuleForTypelibt   LCIDt   MajorVersiont   MinorVersiont   NamesToIIDMapt   getR   t   getattr(   R/   t   targetR*   t   modt   target_clsidt   target_class(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   CastTo   s$    	
t	   Constantsc           B   s    e  Z d  Z d   Z d   Z RS(   s+   A container for generated COM constants.
  c         C   s   g  |  _  d  S(   N(   t	   __dicts__(   R.   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __init__¤   s    c         C   s8   x% |  j  D] } | | k r
 | | Sq
 Wt |   d  S(   N(   RJ   R   (   R.   t   at   d(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __getattr__Ś   s    (   R2   R3   R4   RK   RN   (    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRI   Ą   s   	c         C   sF   y! |  j  j d j |  | |  Wn t k
 rA | |  j | <n Xd  S(   Ni    (   R9   t	   __bases__t   __setattr__R   R:   (   R.   t   attrt   val(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   _event_setattr_ą   s    !t   EventsProxyc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   | |  j  d <d  S(   Nt   _obj_(   R:   (   R.   R/   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRK   ż   s    c         C   s,   y |  j  j   Wn t j k
 r' n Xd  S(   N(   RU   t   closeR   R   (   R.   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __del__Á   s    c         C   s   t  |  j |  S(   N(   RC   RU   (   R.   RQ   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRN   Č   s    c         C   s   t  |  j | |  d  S(   N(   t   setattrRU   (   R.   RQ   RR   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRP   Ę   s    (   R2   R3   RK   RW   RN   RP   (    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRT   ž   s   			c         C   s  t  |   } | j j j d  sÉ y | j j   } | j   d } | j   \ } } | j   } t	 j
 | d | d | d | d d d t	 j t |   } WqŇ t j k
 rĹ t d   qŇ Xn	 | j } | j }  y d d	 l m }	 Wn t k
 rt }	 n Xt |   }
 |
 d k r0t d
   n  |	 d | |
 | f i t d 6 } | | j  } |
 j | |  t | d  r| j |  n  t |  S(   sÔ  Create a COM object that can fire events to a user defined class.
  clsid -- The ProgID or CLSID of the object to create.
  user_event_class -- A Python class object that responds to the events.

  This requires makepy support for the COM object being created.  If
  this support does not exist it will be automatically generated by
  this function.  If the object does not support makepy, a TypeError
  exception will be raised.

  The result is a class instance that both represents the COM object
  and handles events from the COM object.

  It is important to note that the returned instance is not a direct
  instance of the user_event_class, but an instance of a temporary
  class object that derives from three classes:
  * The makepy generated class for the COM object
  * The makepy generated class for the COM events
  * The user_event_class as passed to this function.

  If this is not suitable, see the getevents function for an alternative
  technique of handling events.

  Object Lifetimes:  Whenever the object returned from this function is
  cleaned-up by Python, the events will be disconnected from
  the COM object.  This is almost always what should happen,
  but see the documentation for getevents() for more details.

  Example:

  >>> class IEEvents:
  ...    def OnVisible(self, visible):
  ...       print "Visible changed:", visible
  ...
  >>> ie = DispatchWithEvents("InternetExplorer.Application", IEEvents)
  >>> ie.Visible = 1
  Visible changed: 1
  >>> 
  R6   i    i   i   i   t   bValidateFiles`   This COM object can not automate the makepy process - please run makepy manually for this objecti˙˙˙˙(   t	   ClassTypes(   This COM object does not support events.t   COMEventClassRP   RK   N(   R   R9   R:   RB   t   _oleobj_R   R   t   GetContainingTypeLibt
   GetLibAttrR	   t   EnsureModulet   GetClassForProgIDR   R   R   t	   TypeErrorR6   t   typesRZ   t   ImportErrort   typet	   geteventsR   R   RS   RK   R8   RT   (   R*   t   user_event_classt   dispt   tit
   disp_clsidt   tlbR5   t   tlat
   disp_classt   new_typet   events_classt   result_classt   instance(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   DispatchWithEventsÍ   s4    (,		
"c         C   sX  t  |   }  |  j j j d  sÉ y |  j j   } | j   d } | j   \ } } | j   } t	 j
 | d | d | d | d d d t	 j t |   } WqŇ t j k
 rĹ t d   qŇ Xn	 |  j } | j } d d	 l }	 t |  }
 |
 d	 k rt d
   n  |	 j d |
 | f i   } | |   } t | d  rT| j |  n  | S(   s^  Similar to DispatchWithEvents - except that the returned
  object is *not* also usable as the original Dispatch object - that is
  the returned object is not dispatchable.

  The difference is best summarised by example.

  >>> class IEEvents:
  ...    def OnVisible(self, visible):
  ...       print "Visible changed:", visible
  ...
  >>> ie = Dispatch("InternetExplorer.Application")
  >>> ie_events = WithEvents(ie, IEEvents)
  >>> ie.Visible = 1
  Visible changed: 1

  Compare with the code sample for DispatchWithEvents, where you get a
  single object that is both the interface and the event handler.  Note that
  the event handler instance will *not* be able to use 'self.' to refer to
  IE's methods and properties.

  This is mainly useful where using DispatchWithEvents causes
  circular reference problems that the simple proxy doesn't deal with
  R6   i    i   i   i   RY   s`   This COM object can not automate the makepy process - please run makepy manually for this objecti˙˙˙˙Ns(   This COM object does not support events.R[   RK   (   R   R9   R:   RB   R\   R   R   R]   R^   R	   R_   R`   R   R   R   Ra   R6   t   newRe   R   R   t   classobjR8   RK   (   Rg   Rf   Rh   Ri   Rj   R5   Rk   Rl   R*   Rr   Rn   Ro   Rp   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt
   WithEvents  s,    ,		c         C   ss   t  t j |    }  t j |   } y | j SWn= t k
 rn y t j | j  j SWqo t k
 rj d SXn Xd S(   sC  Determine the default outgoing interface for a class, given
    either a clsid or progid. It returns a class - you can
    conveniently derive your own handler from this class and implement
    the appropriate methods.

    This method relies on the classes produced by makepy. You must use
    either makepy or the gencache module to ensure that the
    appropriate support classes have been generated for the com server
    that you will be handling events from.

    Beware of COM circular references.  When the Events class is connected
    to the COM object, the COM object itself keeps a reference to the Python
    events class.  Thus, neither the Events instance or the COM object will
    ever die by themselves.  The 'close' method on the events instance
    must be called to break this chain and allow standard Python collection
    rules to manage object lifetimes.  Note that DispatchWithEvents() does
    work around this problem by the use of a proxy object, but if you use
    the getevents() function yourself, you must make your own arrangements
    to manage this circular reference issue.

    Beware of creating Python circular references: this will happen if your
    handler has a reference to an object that has a reference back to
    the event source. Call the 'close' method to break the chain.
    
    Example:

    >>>win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}',0,1,1)
    <module 'win32com.gen_py.....
    >>>
    >>> class InternetExplorerEvents(win32com.client.getevents("InternetExplorer.Application.1")):
    ...    def OnVisible(self, Visible):
    ...        print "Visibility changed: ", Visible
    ...
    >>>
    >>> ie=win32com.client.Dispatch("InternetExplorer.Application.1")
    >>> events=InternetExplorerEvents(ie) 
    >>> ie.Visible=1
    Visibility changed:  1
    >>>
    N(	   R   R   R   R	   R
   t   default_sourceR   t   coclass_clsidR   (   R*   R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRe   J  s    +c         C   s˛   d d l  } | j |  } t j | j j } | j | j | j | j	 | j
  } y | j |  } Wn' t k
 r t d |  | f   n Xt j | j | j	 | j
 | j |  S(   s)  Creates a new record object, given the name of the record,
  and an object from the same type library.

  Example usage would be:
    app = win32com.client.Dispatch("Some.Application")
    point = win32com.client.Record("SomeAppPoint", app)
    point.x = 0
    point.y = 0
    app.MoveTo(point)
  i˙˙˙˙Ns0   The structure '%s' is not defined in module '%s'(   R	   R;   t   syst   modulesR9   R3   R=   R6   R>   R?   R@   t	   RecordMapt   KeyErrorR   R   t   GetRecordFromGuids(   t   namet   objectR	   t   modulet   packaget   struct_guid(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   Record  s    $t   DispatchBaseClassc           B   sh   e  Z d	 d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	 d	 d  Z
 d	 d	 d  Z RS(
   c         C   s˛   | d  k r! t j |  j  } n t |   t |  k rĄ y | j j |  j t j  } WqĄ t j k
 r } d d  l	 } | j
 | j k r   n  | j } qĄ Xn  | |  j d <d  S(   Ni˙˙˙˙R\   (   R   R   Rr   R6   Rd   R\   R   R    R   t   winerrort   hresultt   E_NOINTERFACER:   (   R.   t   oobjt   detailsR   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRK   ˘  s    c         C   sz   yC t  j |  j j j } | r, d | } n t  j |  j j j } Wn t k
 r\ d } n Xd | |  j j t |   f S(   Ns   win32com.gen_py.s   win32com.gen_py.unknowns   <%s.%s instance at 0x%s>(   Rw   Rx   R9   R3   R4   R2   Rz   t   id(   R.   t   mod_doct   mod_name(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __repr__˛  s    
c         C   s   t  | d |  } |  j | k S(   NR\   (   RC   R\   (   R.   t   other(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __eq__ž  s    c         C   s   t  | d |  } |  j | k S(   NR\   (   RC   R\   (   R.   R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   __ne__Â  s    c         G   s.   |  j  |  j j | d | | | |  | |  S(   Ni    (   t   _get_good_object_R\   t   InvokeTypes(   R.   t   dispidt   wFlagst   retTypet   argTypest   userR   t   args(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   _ApplyTypes_Ć  s    c         C   sJ   |  j  j |  } | d  k r= t d t |   | f   n  |  j |   S(   Ns!   '%s' object has no attribute '%s'(   t   _prop_map_get_RB   R   R   t   reprR   (   R.   RQ   R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRN   Ë  s    c         C   s   | |  j  k r  | |  j  | <d  Sy |  j | \ } } Wn- t k
 rf t d t |   | f   n X|  j j | | f |   d  S(   Ns!   '%s' object has no attribute '%s'(   R:   t   _prop_map_put_Rz   R   R   R\   t   Invoke(   R.   RQ   t   valueR   t   defArgs(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRP   Ń  s       c         C   s   t  | | |  S(   N(   t   _get_good_single_object_(   R.   t   objt
   obUserNameR   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   Ř  s    c         C   s   t  | | |  S(   N(   R   (   R.   R   R    R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   Ú  s    N(   R2   R3   R   RK   R   R   R   R   RN   RP   R   R   (    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   Ą  s   						c         C   s&   t  t |   k r" t |  | |  S|  S(   N(   t   _PyIDispatchTypeRd   R   (   R   R    R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   Ţ  s    c         C   sr   |  d  k r d  St |  t  r^ | f t |   } | f t |   } t t t |  | |   St |  | |  Sd  S(   N(   R   t
   isinstancet   tuplet   lent   mapR   R   (   R   R    R   t   obUserNameTuplet   resultCLSIDTuple(    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   ă  s    t   CoClassBaseClassc           B   s/   e  Z d d   Z d   Z d   Z d   Z RS(   c         C   s;   | d  k r! t j |  j  } n  |  j |  |  j d <d  S(   Nt	   _dispobj_(   R   R   Rr   R6   R7   R:   (   R.   R   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRK   î  s     c         C   s   d t  |  j j f S(   Ns   <win32com.gen_py.%s.%s>(   R4   R9   R2   (   R.   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR   ń  s    c         C   s6   |  j  d } | d  k	 r& t | |  St |   d  S(   NRŠ   (   R:   R   RC   R   (   R.   RQ   RM   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRN   ô  s     c         C   sv   | |  j  k r  | |  j  | <d  Sy1 |  j  d } | d  k	 rP | j | |  d  SWn t k
 rd n X| |  j  | <d  S(   NRŠ   (   R:   R   RP   R   (   R.   RQ   R   RM   (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyRP   ř  s      N(   R2   R3   R   RK   R   RN   RP   (    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyR¨   í  s   		(    (    (    (    (   R   R   R	   Rw   R   t   TypeIIDsR    RĄ   R   R'   R   R   R   R   R   R   R-   R   RH   RI   t	   constantsRS   RT   Rq   Rt   Re   R   R   R   R   R¨   (    (    (    s;   C:\RCS\Python\lib\site-packages\win32com\client\__init__.pyt   <module>	   s6   				"			I	4	8	=
