
[Mc           @   s  d  Z  d Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d Z e j e j Z e j e j Z d d l m Z e d Z d Z  d	 Z! d
 Z" d Z# d   Z$ d d d     YZ% d e% f d     YZ& d e& f d     YZ' d e' f d     YZ( d e% f d     YZ) e' Z* d   Z+ d   Z, d   Z- y d d l. m/ Z/ m0 Z0 Wn e1 k
 rn Xd S(   s  Policies 

Note that Dispatchers are now implemented in "dispatcher.py", but
are still documented here.

Policies

 A policy is an object which manages the interaction between a public 
 Python object, and COM .  In simple terms, the policy object is the 
 object which is actually called by COM, and it invokes the requested 
 method, fetches/sets the requested property, etc.  See the 
 @win32com.server.policy.CreateInstance@ method for a description of
 how a policy is specified or created.

 Exactly how a policy determines which underlying object method/property 
 is obtained is up to the policy.  A few policies are provided, but you 
 can build your own.  See each policy class for a description of how it 
 implements its policy.

 There is a policy that allows the object to specify exactly which 
 methods and properties will be exposed.  There is also a policy that 
 will dynamically expose all Python methods and properties - even those 
 added after the object has been instantiated.

Dispatchers

 A Dispatcher is a level in front of a Policy.  A dispatcher is the 
 thing which actually receives the COM calls, and passes them to the 
 policy object (which in turn somehow does something with the wrapped 
 object).

 It is important to note that a policy does not need to have a dispatcher.
 A dispatcher has the same interface as a policy, and simply steps in its 
 place, delegating to the real policy.  The primary use for a Dispatcher 
 is to support debugging when necessary, but without imposing overheads 
 when not (ie, by not using a dispatcher at all).

 There are a few dispatchers provided - "tracing" dispatchers which simply 
 prints calls and args (including a variation which uses 
 win32api.OutputDebugString), and a "debugger" dispatcher, which can 
 invoke the debugger when necessary.

Error Handling

 It is important to realise that the caller of these interfaces may
 not be Python.  Therefore, general Python exceptions and tracebacks aren't 
 much use.

 In general, there is an Exception class that should be raised, to allow 
 the framework to extract rich COM type error information.

 The general rule is that the **only** exception returned from Python COM 
 Server code should be an Exception instance.  Any other Python exception 
 should be considered an implementation bug in the server (if not, it 
 should be handled, and an appropriate Exception instance raised).  Any 
 other exception is considered "unexpected", and a dispatcher may take 
 special action (see Dispatchers above)

 Occasionally, the implementation will raise the policy.error error.  
 This usually means there is a problem in the implementation that the 
 Python programmer should fix.

 For example, if policy is asked to wrap an object which it can not 
 support (because, eg, it does not provide _public_methods_ or _dynamic_) 
 then policy.error will be raised, indicating it is a Python programmers 
 problem, rather than a COM error.
 
s   Greg Stein and Mark HammondiN(   t   DISPATCH_METHODt   DISPATCH_PROPERTYGETt   DISPATCH_PROPERTYPUTt   DISPATCH_PROPERTYPUTREFt   DISPID_UNKNOWNt   DISPID_VALUEt   DISPID_PROPERTYPUTt   DISPID_NEWENUMt   DISPID_EVALUATEt   DISPID_CONSTRUCTORt   DISPID_DESTRUCTORt   DISPID_COLLECTt   DISPID_STARTENUMi    (   t   COMExceptions    errors   CLSID\%s\PythonCOMs   CLSID\%s\PythonCOMPolicys   CLSID\%s\PythonCOMDispatchers   CLSID\%s\PythonCOMPathc         C   s<  y\ t  j t j t |   j d  } x3 | D]+ } | t j k r, t j j d |  q, q, WWn t  j	 k
 rr n Xy) t  j t j t
 |   } t |  } Wn t  j	 k
 r t } n Xy2 t  j t j t |   } | r t |  } n  Wn t  j	 k
 rd } n X| r | | d  } n | d  } | j |  |  S(   s  Create a new instance of the specified IID

  The COM framework **always** calls this function to create a new 
  instance for the specified CLSID.  This function looks up the
  registry for the name of a policy, creates the policy, and asks the
  policy to create the specified object by calling the _CreateInstance_ method.
  
  Exactly how the policy creates the instance is up to the policy.  See the
  specific policy documentation for more details.
  t   ;i    N(   t   win32apit   RegQueryValuet   win32cont   HKEY_CLASSES_ROOTt   regAddnPatht   splitt   syst   patht   insertt   errort	   regPolicyt   resolve_funct   DefaultPolicyt   regDispatchert   Nonet   _CreateInstance_(   t   clsidt   reqIIDt	   addnPathst   newPatht   policyt
   dispatchert   retObj(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   CreateInstanceb   s2    
 
t   BasicWrapPolicyc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  The base class of policies.

     Normally not used directly (use a child class, instead)

     This policy assumes we are wrapping another object
     as the COM server.  This supports the delegation of the core COM entry points
     to either the wrapped object, or to a child class.

     This policy supports the following special attributes on the wrapped object

     _query_interface_ -- A handler which can respond to the COM 'QueryInterface' call.
     _com_interfaces_ -- An optional list of IIDs which the interface will assume are
         valid for the object.
     _invoke_ -- A handler which can respond to the COM 'Invoke' call.  If this attribute
         is not provided, then the default policy implementation is used.  If this attribute
         does exist, it is responsible for providing all required functionality - ie, the
         policy _invoke_ method is not invoked at all (and nor are you able to call it!)
     _getidsofnames_ -- A handler which can respond to the COM 'GetIDsOfNames' call.  If this attribute
         is not provided, then the default policy implementation is used.  If this attribute
         does exist, it is responsible for providing all required functionality - ie, the
         policy _getidsofnames_ method is not invoked at all (and nor are you able to call it!)

     IDispatchEx functionality:

     _invokeex_ -- Very similar to _invoke_, except slightly different arguments are used.
         And the result is just the _real_ result (rather than the (hresult, argErr, realResult)
         tuple that _invoke_ uses.	
         This is the new, prefered handler (the default _invoke_ handler simply called _invokeex_)
     _getdispid_ -- Very similar to _getidsofnames_, except slightly different arguments are used,
         and only 1 property at a time can be fetched (which is all we support in getidsofnames anyway!)
         This is the new, prefered handler (the default _invoke_ handler simply called _invokeex_)
     _getnextdispid_- uses self._name_to_dispid_ to enumerate the DISPIDs
  c         C   s    | d k	 r |  j |  n  d S(   s   Initialise the policy object

       Params:

       object -- The object to wrap.  May be None *iff* @BasicWrapPolicy._CreateInstance_@ will be
       called immediately after this to setup a brand new object
    N(   R   t   _wrap_(   t   selft   object(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   __init__   s    c   
      C   s   y t  j t j t |  } Wn( t  j k
 rG t d t |   n Xt |  } |  j |  y t j	 |  |  SWnf t j
 k
 r \ } } } } d d l m }	 d | |	 |  | | f } t j
 | | | |   n Xd S(   s   Creates a new instance of a **wrapped** object

       This method looks up a "@win32com.server.policy.regSpec@" % clsid entry
       in the registry (using @DefaultPolicy@)
    s?   The object is not correctly registered - %s key can not be readi(   t   IIDToInterfaceNamesL   The object '%r' was created, but does not support the interface '%s'(%s): %sN(   R   R   R   R   t   regSpecR   t	   call_funcR(   t	   pythoncomt
   WrapObjectt	   com_errort   win32com.utilR,   (
   R)   R   R    t	   classSpect   myobt   hrt   desct   exct   argR,   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR      s    c         C   s?  i  |  _  | } |  _ t | d  r4 | j |  _ n  t | d  rR | j |  _ n  t | d  rp | j |  _ n  t | d  r | j |  _ n  t | d  r | j |  _ n  t | d  r2g  |  _ xt | j D]] } t	 |  t
 j k r| d d k r	t j | } qt j |  } n  |  j j |  q Wn	 g  |  _ d	 S(
   s   Wraps up the specified object.

       This function keeps a reference to the passed
       object, and may interogate it to determine how to respond to COM requests, etc.
    t   _query_interface_t   _invoke_t
   _invokeex_t   _getidsofnames_t   _getdispid_t   _com_interfaces_i    t   {N(   t   _name_to_dispid_t   _obj_t   hasattrR9   R:   R;   R<   R=   R>   t   typet
   pywintypest   IIDTypeR/   t   InterfaceNamest   MakeIIDt   append(   R)   R*   t   obt   i(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR(      s*    		c         C   s    | |  j  k r d S|  j |  S(   s   The main COM entry-point for QueryInterface. 

       This checks the _com_interfaces_ attribute and if the interface is not specified 
       there, it calls the derived helper _query_interface_
    i   (   R>   R9   (   R)   t   iid(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _QueryInterface_   s    c         C   s   d S(   s   Called if the object does not provide the requested interface in _com_interfaces,
       and does not provide a _query_interface_ handler.

       Returns a result to the COM framework indicating the interface is not supported.
    i    (    (   R)   RK   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR9     s    c         C   st   t  |  t  d  k r^ y |  j | j   } Wq^ t k
 rZ t d t j d d   q^ Xn  |  j | | | |  S(   sS   The main COM entry-point for Invoke.  

       This calls the _invoke_ helper.
    t    t   scodeR6   s   Member not found(   RC   R@   t   lowert   KeyErrorR   t   winerrort   DISP_E_MEMBERNOTFOUNDR:   (   R)   t   dispidt   lcidt   wFlagst   args(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _Invoke_
  s    c      	   C   s%   t  d |  j | | | | d  d   f S(   Ni(   t   S_OKR;   R   (   R)   RS   RT   RU   RV   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR:     s    c         C   s=   t  |  d k r- t d t j d d   n  |  j | |  S(   s   The main COM entry-point for GetIDsOfNames.

       This checks the validity of the arguments, and calls the _getidsofnames_ helper.
    i   RN   R6   s$   Cannot support member argument names(   t   lenR   RQ   t   DISP_E_INVALIDR<   (   R)   t   namesRT   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetIDsOfNames_  s    c         C   s   |  j  | d d  f S(   Ni    (   R=   (   R)   R[   RT   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR<   &  s    c         C   s   |  j  | |  S(   N(   R=   (   R)   t   namet   fdex(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetDispID_.  s    c         C   s?   y |  j  | j   SWn# t k
 r: t d t j   n Xd  S(   NRN   (   R@   RO   RP   R   RQ   t   DISP_E_UNKNOWNNAME(   R)   R]   R^   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR=   1  s    c         C   sz   t  |  t  d  k r^ y |  j | j   } Wq^ t k
 rZ t d t j d d   q^ Xn  |  j | | | | | |  S(   sW   The main COM entry-point for InvokeEx.  

       This calls the _invokeex_ helper.
    RM   RN   R6   s   Member not found(   RC   R@   RO   RP   R   RQ   RR   R;   (   R)   RS   RT   RU   RV   t   kwargst   serviceProvider(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt
   _InvokeEx_9  s    c         C   s   t  d   d S(   s[   A stub for _invokeex_ - should never be called.  
 
       Simply raises an exception.
    s0   This class does not provide _invokeex_ semanticsN(   R   (   R)   RS   RT   RU   RV   Ra   Rb   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR;   F  s    c         C   s   |  j  | |  S(   N(   t   _deletememberbyname_(   R)   R]   R^   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _DeleteMemberByName_N  s    c         C   s   t  d t j   d  S(   NRN   (   R   RQ   t	   E_NOTIMPL(   R)   R]   R^   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyRd   P  s    c         C   s   |  j  |  S(   N(   t   _deletememberbydispid(   R)   t   id(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _DeleteMemberByDispID_S  s    c         C   s   t  d t j   d  S(   NRN   (   R   RQ   Rf   (   R)   Rh   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _deletememberbydispid_U  s    c         C   s   |  j  | |  S(   N(   t   _getmemberproperties_(   R)   Rh   R^   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetMemberProperties_X  s    c         C   s   t  d t j   d  S(   NRN   (   R   RQ   Rf   (   R)   Rh   R^   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyRk   Z  s    c         C   s   |  j  |  S(   N(   t   _getmembername_(   R)   RS   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetMemberName_]  s    c         C   s   t  d t j   d  S(   NRN   (   R   RQ   Rf   (   R)   RS   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyRm   _  s    c         C   s   |  j  | |  S(   N(   t   _getnextdispid_(   R)   R^   RS   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetNextDispID_b  s    c         C   s   |  j  j   } | j   t | k r5 | j t  n  | t k rI | d Sy | | j |  d SWnE t k
 r t d t j	   n# t
 k
 r t d t j   n Xd  S(   Ni    i   RN   (   R@   t   valuest   sortR   t   removet   indext
   ValueErrorR   RQ   t   E_UNEXPECTEDt
   IndexErrort   S_FALSE(   R)   R^   RS   t   ids(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyRo   d  s    
 c         C   s
   |  j    S(   N(   t   _getnamespaceparent(   R)   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetNameSpaceParent_r  s    c         C   s   t  d t j   d  S(   NRN   (   R   RQ   Rf   (   R)   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _getnamespaceparent_t  s    (   t   __name__t
   __module__t   __doc__R+   R   R(   RL   R9   RW   R:   R\   R<   R_   R=   Rc   R;   Re   Rd   Ri   Rj   Rl   Rk   Rn   Rm   Rp   Ro   R{   R|   (    (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR'      s4   !			)	
																						t   MappedWrapPolicyc           B   s    e  Z d  Z d   Z d   Z RS(   sT  Wraps an object using maps to do its magic

     This policy wraps up a Python object, using a number of maps
     which translate from a Dispatch ID and flags, into an object to call/getattr, etc.

     It is the responsibility of derived classes to determine exactly how the
     maps are filled (ie, the derived classes determine the map filling policy.

     This policy supports the following special attributes on the wrapped object

     _dispid_to_func_/_dispid_to_get_/_dispid_to_put_ -- These are dictionaries
       (keyed by integer dispid, values are string attribute names) which the COM
       implementation uses when it is processing COM requests.  Note that the implementation
       uses this dictionary for its own purposes - not a copy - which means the contents of 
       these dictionaries will change as the object is used.

  c         C   s   t  j |  |  |  j } t | d  r7 | j |  _ n	 i  |  _ t | d  r^ | j |  _ n	 i  |  _ t | d  r | j |  _ n	 i  |  _ d  S(   Nt   _dispid_to_func_t   _dispid_to_get_t   _dispid_to_put_(   R'   R(   RA   RB   R   R   R   (   R)   R*   RI   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR(     s    			c         C   sd   | |  j  k r |  j  | S| |  j k r4 |  j | S| |  j k rN |  j | St d t j   d  S(   NRN   (   R   R   R   R   RQ   RR   (   R)   RS   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyRm     s    (   R}   R~   R   R(   Rm   (    (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR   x  s   	t   DesignatedWrapPolicyc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sS  A policy which uses a mapping to link functions and dispid
     
     A MappedWrappedPolicy which allows the wrapped object to specify, via certain
     special named attributes, exactly which methods and properties are exposed.

     All a wrapped object need do is provide the special attributes, and the policy
     will handle everything else.

     Attributes:

     _public_methods_ -- Required, unless a typelib GUID is given -- A list
                  of strings, which must be the names of methods the object
                  provides.  These methods will be exposed and callable
                  from other COM hosts.
     _public_attrs_ A list of strings, which must be the names of attributes on the object.
                  These attributes will be exposed and readable and possibly writeable from other COM hosts.
     _readonly_attrs_ -- A list of strings, which must also appear in _public_attrs.  These
                  attributes will be readable, but not writable, by other COM hosts.
     _value_ -- A method that will be called if the COM host requests the "default" method
                  (ie, calls Invoke with dispid==DISPID_VALUE)
     _NewEnum -- A method that will be called if the COM host requests an enumerator on the
                  object (ie, calls Invoke with dispid==DISPID_NEWENUM.)
                  It is the responsibility of the method to ensure the returned
                  object conforms to the required Enum interface.

    _typelib_guid_ -- The GUID of the typelibrary with interface definitions we use.
    _typelib_version_ -- A tuple of (major, minor) with a default of 1,1
    _typelib_lcid_ -- The LCID of the typelib, default = LOCALE_USER_DEFAULT

     _Evaluate -- Dunno what this means, except the host has called Invoke with dispid==DISPID_EVALUATE!
                  See the COM documentation for details.
  c         C   s  t  | d d   } | d  k	 r t  | d d  \ } } t  | d d  } d d l m } g  t  | d g   D]1 } t |  t j k rk | j d	  rk | ^ qk } | j | | | | |  }	 n g  }	 t	 j
 |  |  t | d
  rt | d  rt d   n  x0 |  j j   D] \ }
 } |
 |  j | j   <qWx0 |  j j   D] \ }
 } |
 |  j | j   <qHWx0 |  j j   D] \ }
 } |
 |  j | j   <q{Wx |	 D] \ }
 } } |
 |  j | j   <| t k r| |  j |
 <q| t t f k r| |  j |
 <q| t k r!| |  j |
 <qt d | | f   qWt | d  rgd |  j t <d |  j t <n  t | d  rt |  j d <d |  j t <n  t | d  rt |  j d <d |  j t <n  |  j d  } t | d  rt | d  r| j } n g  } x | j D]~ } |  j j | j    }
 |
 d  k r]| }
 |
 |  j | j   <|  j |  } n  | |  j |
 <| | k r| |  j |
 <qqWn  xv t  | d
 g   D]b } |  j j | j    }
 |
 d  k r| }
 |
 |  j | j   <|  j |  } n  | |  j |
 <qWd  |  _  d  S(   Nt   _typelib_guid_t   _typelib_version_i   i    t   _typelib_lcid_i(   t	   universalR>   R?   t   _public_methods_sw   Object does not support DesignatedWrapPolicy, as it does not have either _public_methods_ or _typelib_guid_ attributes.s   unexpected invkind: %d (%s)t   _value_t   _NewEnumt   _newenumt	   _Evaluatet	   _evaluatei  t   _public_attrs_t   _readonly_attrs_(   i   i    (!   t   getattrR   t   win32comR   RC   RD   RE   t
   startswitht   RegisterInterfacesR   R(   RB   R   R   t	   iteritemsR@   RO   R   R   R    R   R   R   Ru   R   R   R   R   t   _allocnextdispidR   R   t   gett   _typeinfos_(   R)   RI   t   tlb_guidt	   tlb_majort	   tlb_minort   tlb_lcidR   RJ   t
   interfacest   universal_dataRS   R]   t   invkindt   next_dispidt   readonly(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR(     sv    1 c   	      C   s   t  |  j d d   } | d  k r% g  St  |  j d d  \ } } t j | | |  } | j   } xW |  j j D]I } y, | j |  \ } } | d  k	 r | g SWqn t j k
 r qn Xqn Wg  S(   NR   R   i   i    (   i   i    (	   R   RA   R   R/   t   LoadRegTypeLibt   GetTypeCompR>   t   BindTypeR1   (	   R)   R   R   R   t   tlbt   typecompt   inamet	   type_infot	   type_comp(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _build_typeinfos_  s    c         C   s.   |  j  d  k r! |  j   |  _  n  t |  j   S(   N(   R   R   R   RY   (   R)   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetTypeInfoCount_$  s    c         C   sh   |  j  d  k r! |  j   |  _  n  | d k  sB | t |  j   k rW t d t j   n  d |  j  | f S(   Ni    RN   (   R   R   R   RY   R   RQ   t   DISP_E_BADINDEX(   R)   Rt   RT   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _GetTypeInfo_)  s
    !c         C   sE   x> | d } | |  j  k r | |  j k r | |  j k r | Sq d  S(   Ni   (   R   R   R   (   R)   t   last_dispid(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR   0  s    
c         C   sJ  | t  @r y |  j | } Wn0 t k
 rM | t @s t d t j   q q Xy t |  j |  } Wn# t	 k
 r t d t j   n Xy | |   SWq t
 k
 r }	 t |	  j d  d k r d |	 | | f GHn    q Xn  | t @r_y |  j | }
 Wn# t k
 r$t d t j   n Xt |  j |
  } t |  t j k r[| |   } n  | S| t t B@r.y |  j | }
 Wn# t k
 rt d t j   n Xt t |  j |
 d    t j k rt t |  j d |
 d    t j k rt |  j d |
  } | |   n t |  j |
 | d  d  St d t j d d   d  S(   NRN   t	   argumentsi    s'   ** TypeError %s calling function %r(%r)t   SetR6   s   invalid wFlags(   R    R   RP   R   R   RQ   RR   R   RA   t   AttributeErrort	   TypeErrort   strt   findR   RC   t   typest
   MethodTypeR   R   R   R   t   setattrt   E_INVALIDARG(   R)   RS   RT   RU   RV   t   kwArgsRb   t   funcnamet   funct   vR]   t   retobt   fn(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR;   8  sJ    



$((	   R}   R~   R   R(   R   R   R   R   R;   (    (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR     s    	L				t   EventHandlerPolicyc           B   s    e  Z d  Z d   Z d   Z RS(   ss  The default policy used by event handlers in the win32com.client package.

    In addition to the base policy, this provides argument conversion semantics for
    params
      * dispatch params are converted to dispatch objects.
      * Unicode objects are converted to strings (1.5.2 and earlier)

    NOTE: Later, we may allow the object to override this process??
    c         C   s   g  } x | D] } t  |  }	 |	 t k rL d d  l }
 |
 j j |  } nT |	 t k r y. d d  l }
 |
 j j | j t j   } Wq t j	 k
 r q Xn  | j
 |  q Wt |  | f S(   Ni(   RC   t   IDispatchTypet   win32com.clientt   clientt   Dispatcht   IUnknownTypet   QueryInterfaceR/   t   IID_IDispatchR   RH   t   tuple(   R)   RV   R   RS   RT   RU   Rb   t   retR8   t   arg_typeR   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   _transform_args_w  s    "c         C   sC   |  j  | | | | | |  \ } } t j |  | | | | | |  S(   N(   R   R   R;   (   R)   RS   RT   RU   RV   R   Rb   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR;     s    $(   R}   R~   R   R   R;   (    (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR   m  s   		t   DynamicPolicyc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s@  A policy which dynamically (ie, at run-time) determines public interfaces.
  
     A dynamic policy is used to dynamically dispatch methods and properties to the
     wrapped object.  The list of objects and properties does not need to be known in
     advance, and methods or properties added to the wrapped object after construction
     are also handled.

     The wrapped object must provide the following attributes:

     _dynamic_ -- A method that will be called whenever an invoke on the object
            is called.  The method is called with the name of the underlying method/property
            (ie, the mapping of dispid to/from name has been resolved.)  This name property
            may also be '_value_' to indicate the default, and '_NewEnum' to indicate a new
            enumerator is requested.
            
  c         C   s\   t  j |  |  t |  j d  s1 t d   n  d |  _ |  _ i d t 6d t 6|  _	 d  S(   Nt	   _dynamic_s*   Object does not support Dynamic COM Policyi  R   R   (
   R'   R(   RB   RA   R   t   _next_dynamic_t   _min_dynamic_R   R   t   _dyn_dispid_to_name_(   R)   R*   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR(     s
    c         C   sb   | j    } y |  j | SWn@ t k
 r] |  j d } |  _ | |  j | <| |  j | <| SXd  S(   Ni   (   RO   R@   RP   R   R   (   R)   R]   R^   t   lnameRS   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR=     s    c      	   C   s%   t  d |  j | | | | d  d   f S(   Ni(   RX   R;   R   (   R)   RS   RT   RU   RV   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR:     s    c         C   sV   y |  j  | } Wn) t k
 r< t d t j d d   n X|  j j | | | |  S(   NRN   R6   s   Member not found(   R   RP   R   RQ   RR   RA   R   (   R)   RS   RT   RU   RV   Ra   Rb   R]   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR;     s
    (   R}   R~   R   R(   R=   R:   R;   (    (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR     s
   			c         C   sd   yD |  j  d  } |  |  } |  | d } t |  } t | |  SWn t k
 r_ t   |  SXd S(   s   Resolve a function by name
  
  Given a function specified by 'module.function', return a callable object
  (ie, the function itself)
  t   .i   N(   t   rindext   _import_moduleR   Ru   t   globals(   t   spect   idxt   mnamet   fnamet   module(    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR     s    
c         G   s   t  |   |   S(   sp   Call a function specified by name.
  
  Call a function specified by 'module.function' and return the result.
  (   R   (   R   RV   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR.     s    c         C   s   t  |   t j |  S(   s   Import a module just like the 'import' statement.

  Having this function is much nicer for importing arbitrary modules than
  using the 'exec' keyword.  It is more efficient and obvious to the reader.
  (   t
   __import__R   t   modules(   R   (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyR     s    
(   t   DispatcherTracet   DispatcherWin32trace(    (2   R   t
   __author__R   RQ   R   R   RD   R   R/   R    R   R   R   R   R   R   R   R   R	   R
   R   R   RX   t   TypeIIDsR   R   t   IID_IUnknownR   t	   exceptionR   R}   R   R-   R   R   R   R&   R'   R   R   R   R   R   R   R.   R   R$   R   R   t   ImportError(    (    (    s9   K:\RCS\Python\Lib\site-packages\win32com\server\policy.pyt   <module>D   s>   X
	(,2			