
    %
i                         d Z ddlZddlZddlmZ ddlmZ ddZd Z G d d	          Z	 G d
 de	          Z
e	ej        ddfdZ G d d          ZefdZ G d d          ZdS )zGeneral Server side utilities    N   )policy)COMExceptionc                     |t           j        }|dk    rddl}|j        j        j        }||dk    r ||           } n |||           } t          j        |           } ||                     |          } | S )zWraps an object in a PyGDispatch gateway.

    Returns a client side PyI{iid} interface.

    Interface and gateway support must exist for the specified IID, as
    the QueryInterface() method is used.

    Nr   r   )	r   DefaultPolicywin32com.server.dispatcherserver
dispatcherDefaultDebugDispatcher	pythoncom
WrapObjectQueryInterface)obiid	usePolicyuseDispatcherwin32coms        C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\win32com/server/util.pywrapr   
   s     (	)))) 2I 2 2Yr]]]9b)) 
	b	!	!B
s##I    c                 f    t          j        |           } t          | d          r| j        } | j        S )zvUnwraps an interface.

    Given an interface which wraps up a Gateway, return the object behind
    the gateway.
    r   )r   UnwrapObjecthasattrr   _obj_)r   s    r   unwrapr   %   s4     
		#	#Br8 Y8Or   c                   T    e Zd ZdZg dZdej        fdZd Zd Z	d Z
d Zd	 Zd
 ZdS )ListEnumeratoran  A class to expose a Python sequence as an EnumVARIANT.

    Create an instance of this class passing a sequence (list, tuple, or
    any sequence protocol supporting object) and it will automatically
    support the EnumVARIANT interface for the object.

    See also the @NewEnum@ function, which can be used to turn the
    instance into an actual COM server.
    )NextSkipResetCloner   c                 0    || _         || _        || _        d S N)_list_index_iid_)selfdatar%   r   s       r   __init__zListEnumerator.__init__?   s    



r   c                      || j         k    rdS d S )Nr   )r&   )r'   r   s     r   _query_interface_z ListEnumerator._query_interface_D   s    $*1 r   c                 h    | j         | j        | j        |z            }|                     |           |S r#   )r$   r%   r   r'   countresults      r   r   zListEnumerator.NextH   s3    TZ$*u*<<=		%r   c                     | j         |z   }|t          | j                  k    rt          | j                  }|| _         d S r#   )r%   lenr$   )r'   r.   ends      r   r   zListEnumerator.SkipM   s=    j5 T[!!!!dk""C


r   c                     d| _         d S Nr   )r%   r'   s    r   r    zListEnumerator.ResetS   s    


r   c                 h    |                      |                     | j        | j                            S r#   )_wrap	__class__r$   r%   r5   s    r   r!   zListEnumerator.CloneV   s&    zz$..djAABBBr   c                      t          |          S r#   r   r'   r   s     r   r7   zListEnumerator._wrapY       Bxxr   N)__name__
__module____qualname____doc___public_methods_r   IID_IEnumVARIANTr)   r+   r   r   r    r!   r7    r   r   r   r   2   s          :99#$)*D    
    
    C C C    r   r   c                       e Zd ZdZd ZdS )ListEnumeratorGatewayaf  A List Enumerator which wraps a sequence's items in gateways.

    If a sequence contains items (objects) that have not been wrapped for
    return through the COM layers, then a ListEnumeratorGateway can be
    used to wrap those items before returning them (from the Next() method).

    See also the @ListEnumerator@ class and the @NewEnum@ function.
    c                     | j         | j        | j        |z            }|                     |           t          | j        |          S r#   )r$   r%   r   mapr7   r-   s      r   r   zListEnumeratorGateway.Nextg   s@    TZ$*u*<<=		%4:v&&&r   N)r=   r>   r?   r@   r   rC   r   r   rE   rE   ]   s-         ' ' ' ' 'r   rE   c                 B     || |          }t          ||||          S )a  Creates a new enumerator COM server.

    This function creates a new COM Server that implements the
    IID_IEnumVARIANT interface.

    A COM server that can enumerate the passed in sequence will be
    created, then wrapped up for return through the COM framework.
    Optionally, a custom COM server for enumeration can be passed
    (the default is @ListEnumerator@), and the specific IEnum
    interface can be specified.
    )r   )r   r   r:   )seqclsr   r   r   r   s         r   NewEnumrK   m   s/    $ 
Sc			BC9MJJJJr   c                   J    e Zd ZdZg dZddZd ZeZd Zd Z	d	 Z
d
 Zd ZdS )
CollectionzA collection of VARIANT values.)ItemCountAddRemoveInsertNr   c                 6    |g }|| _         |rddg| _        d S d S )NrN   rO   )r(   rA   )r'   r(   readOnlys      r   r)   zCollection.__init__   s:    <D	  	6%+W$5D!!!	6 	6r   c                     t          |          dk    rt          t          j                  	 | j        |d                  S # t
          $ r-}t          t          j        t          |                    d }~ww xY w)Nr   scoder   rW   desc)r1   r   winerrorDISP_E_BADPARAMCOUNTr(   
IndexErrorDISP_E_BADINDEXstr)r'   argsrY   s      r   rN   zCollection.Item   s{    t99>>X%BCCCC	O9T!W%% 	O 	O 	OX%=CIINNNN	Os   A 
A9(A44A9c                 *    t          | j                  S r#   )r1   r(   r5   s    r   rO   zCollection.Count   s    49~~r   c                 :    | j                             |           d S r#   )r(   append)r'   values     r   rP   zCollection.Add   s    	r   c                     	 | j         |= d S # t          $ r-}t          t          j        t          |                    d }~ww xY w)NrX   )r(   r\   r   rZ   r]   r^   )r'   r%   rY   s      r   rQ   zCollection.Remove   sW    	O	%    	O 	O 	OX%=CIINNNN	Os    
A(>Ac                     	 t          |          }n/# t          t          f$ r t          t          j                  w xY w| j                            ||           d S )NrV   )int
ValueError	TypeErrorr   rZ   DISP_E_TYPEMISMATCHr(   insert)r'   r%   rc   s      r   rR   zCollection.Insert   sk    	CJJEEI& 	C 	C 	CX%ABBBB	C	&&&&&s    ,>c                 *    t          | j                  S r#   )rK   r(   r5   s    r   _NewEnumzCollection._NewEnum   s    ty!!!r   r4   )r=   r>   r?   r@   rA   r)   rN   _value_rO   rP   rQ   rR   rl   rC   r   r   rM   rM      s        %%CCC6 6 6 6O O O G       O O O' ' '" " " " "r   rM   c                     t          j        t          j         ||                     t           j        t           j                  S )a  Creates a new COM collection object

    This function creates a new COM Server that implements the
    common collection protocols, including enumeration. (_NewEnum)

    A COM server that can enumerate the passed in sequence will be
    created, then wrapped up for return through the COM framework.
    Optionally, a custom COM server for enumeration can be passed
    (the default is @Collection@).
    )r   r   r   r   IID_IDispatch)rI   rJ   s     r   NewCollectionrp      s9     SSXX&&	(?AX  r   c                   P    e Zd Zg dZej        gZd Zd Zd Z	d Z
d Zd Zd Zd	S )

FileStream)ReadWriter!   CopyToSeekc                     || _         d S r#   )file)r'   rx   s     r   r)   zFileStream.__init__   s    			r   c                 6    | j                             |          S r#   )rx   read)r'   amounts     r   rs   zFileStream.Read   s    y~~f%%%r   c                 T    | j                             |           t          |          S r#   )rx   writer1   )r'   r(   s     r   rt   zFileStream.Write   s"    	4yyr   c                 \    |                      |                     | j                            S r#   )r7   r8   rx   r5   s    r   r!   zFileStream.Clone   s"    zz$..33444r   c                     | j                             |          }t          |          }|                    |           ||fS r#   )rx   rz   r1   rt   )r'   destcbr(   cbreads        r   ru   zFileStream.CopyTo   s<    y~~b!!T

4v~r   c                 j    | j                             ||           | j                                         S r#   )rx   seektell)r'   offsetorigins      r   rv   zFileStream.Seek   s*    	vv&&&y~~r   c                      t          |          S r#   r:   r;   s     r   r7   zFileStream._wrap   r<   r   N)r=   r>   r?   rA   r   IID_IStream_com_interfaces_r)   rs   rt   r!   ru   rv   r7   rC   r   r   rr   rr      s        CCC!-.  & & &  5 5 5       
    r   rr   )NNN)r@   r   rZ    r   	exceptionr   r   r   r   rE   rB   rK   rM   rp   rr   rC   r   r   <module>r      sW   # #            # # # # # #   6
 
 
( ( ( ( ( ( ( (V' ' ' ' 'N ' ' '$ 	"K K K K,2" 2" 2" 2" 2" 2" 2" 2"j &              r   