o
    ×èFhœ  ã                	   @   s°  d dl Z d dlZzd dlZW n ey   edƒ‚w d dlZd dlZd dlmZm	Z	m
Z
mZmZmZ de	egef dee deee ee f fdd„ZG d	d
„ d
ejƒZeƒ dœdejdejfdd„ZedkrÖe jdd�Zejdddddd� ejdddddd� e ¡ Ze ej¡Ze ej¡Ze ¡ s¦ede› d�ejd� e d ¡ e ¡ sºed!e› d�ejd� e d ¡ e  e¡rÏed!e› d"�ejd� e d ¡ eeeƒ dS dS )#é    Nz@Run `python -m pip install "libcst >= 0.2.5"` to install libcst.)ÚAnyÚCallableÚDictÚListÚSequenceÚTupleÚ	predicateÚiteratorÚreturnc                 C   s8   g g f}|D ]}|t | |ƒƒ  |¡ q|d |d fS )z!A stable, out-of-place partition.é   r   )ÚintÚappend)r   r	   ÚresultsÚi© r   úg/var/www/html/loop/nvenv/lib/python3.10/site-packages/../../../bin/fixup_firestore_admin_v1_keywords.pyÚ	partition   s   r   c                   @   sÊ   e Zd ZU dZee ed< i dd“dd“dd“d	d
“dd
“dd“dd
“dd“dd
“dd
“dd
“dd
“dd
“dd“dd“dd“dd“dddddd d!œ¥Zeeee f ed"< d#e	j
d$e	j
d%e	jfd&d'„Zd(S ))Úfirestore_adminCallTransformer)ÚretryÚtimeoutÚmetadataÚCTRL_PARAMSÚcreate_backup_schedule)ÚparentÚbackup_scheduleÚcreate_database)r   ÚdatabaseÚdatabase_idÚcreate_index)r   ÚindexÚdelete_backup)ÚnameÚdelete_backup_scheduleÚdelete_database)r!   ÚetagÚdelete_indexÚexport_documents)r!   Úcollection_idsÚoutput_uri_prefixÚnamespace_idsÚsnapshot_timeÚ
get_backupÚget_backup_scheduleÚget_databaseÚ	get_fieldÚ	get_indexÚimport_documents)r!   r'   Úinput_uri_prefixr)   Úlist_backups)r   Úlist_backup_schedulesÚlist_databases)r   ÚfilterÚ	page_sizeÚ
page_token)r   r   Úbackup)r   Úupdate_mask)r   r9   )Úfieldr9   )Úlist_fieldsÚlist_indexesÚrestore_databaseÚupdate_backup_scheduleÚupdate_databaseÚupdate_fieldÚMETHOD_TO_PARAMSÚoriginalÚupdatedr
   c           
   	      sò   z|j jj}ˆ j| }W n ttfy   | Y S w tdd„ |jƒ\}}tdd„ |D ƒƒr/|S t‡ fdd„|ƒ\}}|d t	|ƒ… |t	|ƒd … }}| 
dd„ t|ˆ jƒD ƒ¡ tjt dd„ t||| ƒD ƒ¡t d	¡d
�}	|j|	g| d�S )Nc                 S   s   t | jƒ S ©N)ÚboolÚkeyword©Úar   r   r   Ú<lambda>S   s    z;firestore_adminCallTransformer.leave_Call.<locals>.<lambda>c                 s   s   � | ]	}|j jd kV  qdS )ÚrequestN)rF   Úvalue)Ú.0Úkr   r   r   Ú	<genexpr>T   s   € z<firestore_adminCallTransformer.leave_Call.<locals>.<genexpr>c                    s   | j jˆ jvS rD   )rF   rK   r   rG   ©Úselfr   r   rI   Y   s    c                 s   s,   � | ]\}}t j|jt j|d �d�V  qdS )©rK   ©rK   rF   N)ÚcstÚArgrK   ÚName)rL   rH   Úctrlr   r   r   rN   ^   s   €  ÿc              	   S   s2   g | ]\}}t  t  d  |¡¡t j|jd�¡‘qS )z'{}'rQ   )rS   ÚDictElementÚSimpleStringÚformatÚElementrK   )rL   r!   Úargr   r   r   Ú
<listcomp>b   s    ùþÿz=firestore_adminCallTransformer.leave_Call.<locals>.<listcomp>rJ   rR   )Úargs)ÚfuncÚattrrK   rA   ÚAttributeErrorÚKeyErrorr   r]   ÚanyÚlenÚextendÚzipr   rS   rT   r   rU   Úwith_changes)
rP   rB   rC   ÚkeyÚkword_paramsr]   ÚkwargsÚctrl_kwargsÚ	ctrl_argsÚrequest_argr   rO   r   Ú
leave_CallI   s4   
þ
þ"

ÿ
ø	öÿz)firestore_adminCallTransformer.leave_CallN)Ú__name__Ú
__module__Ú__qualname__r   r   ÚstrÚ__annotations__rA   r   rS   ÚCallÚCSTNoderm   r   r   r   r   r   -   sZ   
 ÿþýüûúùø	÷
öõôóòñðïé r   )ÚtransformerÚin_dirÚout_dirc          
   	   C   s¾   dd„ t  | ¡D ƒ}|D ]P}t|dƒ�}| ¡ }W d  ƒ n1 s"w   Y  t |¡}| |¡}| | | ¡¡}	|	j	j
ddd� t|	dƒ�}| |j¡ W d  ƒ n1 sWw   Y  qdS )z§Duplicate the input dir to the output dir, fixing file method calls.

    Preconditions:
    * in_dir is a real directory
    * out_dir is a real, empty directory
    c                 s   sH   � | ]\}}}|D ]}t j |¡d  dkr	t t j ||¡¡V  q	qdS )r   z.pyN)ÚosÚpathÚsplitextÚpathlibÚPathÚjoin)rL   ÚrootÚ_ÚfilesÚfr   r   r   rN      s   € ýþýzfix_files.<locals>.<genexpr>ÚrNT)ÚparentsÚexist_okÚw)rx   ÚwalkÚopenÚreadrS   Úparse_moduleÚvisitÚjoinpathÚrelative_tor   ÚmkdirÚwriteÚcode)
rv   rw   ru   Ú
pyfile_genÚfpathr�   ÚsrcÚtreerC   Úupdated_pathr   r   r   Ú	fix_filess   s    þ
ÿ

ÿ€ór•   Ú__main__a¨  Fix up source that uses the firestore_admin client library.

The existing sources are NOT overwritten but are copied to output_dir with changes made.

Note: This tool operates at a best-effort level at converting positional
      parameters in client method calls to keyword based parameters.
      Cases where it WILL FAIL include
      A) * or ** expansion in a method call.
      B) Calls via function or method alias (includes free function calls)
      C) Indirect or dispatched calls (e.g. the method is looked up dynamically)

      These all constitute false negatives. The tool will also detect false
      positives when an API method shares a name with another method.
)Údescriptionz-dz--input-directoryTÚ	input_dirz6the input directory to walk for python files to fix up)ÚrequiredÚdestÚhelpz-oz--output-directoryÚ
output_dirz5the directory to output files fixed via un-flatteningzinput directory 'z&' does not exist or is not a directory)Úfileéÿÿÿÿzoutput directory 'z' is not empty)!Úargparserx   ÚlibcstrS   ÚImportErrorr{   ÚsysÚtypingr   r   r   r   r   r   rE   r   ÚCSTTransformerr   r|   r•   rn   ÚArgumentParserÚparserÚadd_argumentÚ
parse_argsr]   r˜   rœ   Úis_dirÚprintÚstderrÚexitÚlistdirr   r   r   r   Ú<module>   s‚   ÿ ÿþ
ýJüÿ
þ#ÿûû
þ

þ


þ
Ê