o
    ª›h,  ã                   @   s(   d Z ddlmZ dd„ Z	d	dd„ZdS )
zka clumsy attempt at a macro language to let the programmer execute code on the server (ex: determine 64bit)é   )Úis64bitc           	      C   s¶  t |ttfƒr
|g}|d }z¿| dkr5t ¡ r||d fW S z||d fW W S  ty4   |df Y W S w | dkrI||vrHddl}|| ¡ fW S n~| dkrnddl}z||d | ¡  fW W S  tym   || ¡ f Y W S w | d	kr”ddl	}z|d }W n ty‡   d}Y nw ||j
 |d |¡fW S | d
kr¬d|vs |d s¥|dfW S |d| fW S | dkrÇddl	}ddl}||j | ¡ d|d ¡fW S td| › �ƒ‚   td| › d|›�ƒ‚)ay  allow the programmer to perform limited processing on the server by passing macro names and args

    :new_key - the key name the macro will create
    :args[0] - macro name
    :args[1:] - any arguments
    :code - the value of the keyword item
    :kwargs - the connection keyword dictionary. ??key has been removed
    --> the value to put in for kwargs['name'] = value
    é    r   r   é   Ú ÚgetuserNÚgetnodeÚgetenvZauto_securityÚuserzIntegrated Security=SSPIz'User ID=%(user)s; Password=%(password)sZfind_temp_test_pathZadodbapi_testzUnknown connect string macro=zError in macro processing ú )Ú
isinstanceÚstrr   ÚPythonÚ
IndexErrorÚgetpassr   ÚplatformÚnodeÚosÚenvironÚgetÚtempfileÚpathÚjoinÚ
gettempdirÚ
ValueError)	Ú
macro_nameÚargsÚkwargsÚnew_keyr   r   r   Zdfltr   © r   úUc:\Users\shubh\Videos\agent\nova\Lib\site-packages\adodbapi/process_connect_string.pyÚ
macro_call   s\   
ÿÿýÿÿ
ÿr    Fc           
      C   sˆ  z| d }W n t y   d}Y nw t|tƒr| |¡ n|r#||d< z| d }W n t y4   d}Y nw t|tƒr?||d< nt|tƒrI||d< n
t|tƒrS| |¡ z| d |d< | d	 |d
< | d |d< W n	 t yp   Y nw d|vr›z|d |d< W n tyš   z|d
 |d< W n ty—   tdƒ‚w Y nw |rÂt| 	¡ ƒD ]}| 
d¡rÁ|dd… }| |¡}t|||ƒ\}}	|	||< q£|S )zôattempts to inject arguments into a connection string using Python "%" operator for strings

    co: adodbapi connection object
    args: positional parameters from the .connect() call
    kvargs: keyword arguments from the .connect() call
    r   NZconnection_stringr   Útimeoutr	   r   Úpasswordé   Úhosté   ZdatabaseÚdsnz3Must define 'connection_string' for ado connectionsZmacro_é   )r   r   ÚdictÚupdateÚintr   ÚKeyErrorÚ	TypeErrorÚlistÚkeysÚ
startswithÚpopr    )
r   r   Zexpand_macrosr&   Za1Úkwargr   Z
macro_coder   Zrsltr   r   r   ÚprocessN   sf   	ÿ
ÿ





ÿÿÿþ
ÿÿ€r2   N)F)Ú__doc__r   r   r    r2   r   r   r   r   Ú<module>   s
    Iÿ