o
    ×èFh2  ã                	   @   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   úa/var/www/html/loop/nvenv/lib/python3.10/site-packages/../../../bin/fixup_firestore_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"“Zeeee f ed#< d$e	j
d%e	j
d&e	jfd'd(„Zd)S )*ÚfirestoreCallTransformer)ÚretryÚtimeoutÚmetadataÚCTRL_PARAMSÚbatch_get_documents)ÚdatabaseÚ	documentsÚmaskÚtransactionÚnew_transactionÚ	read_timeÚbatch_write)r   ÚwritesÚlabelsÚbegin_transaction)r   ÚoptionsÚcommit)r   r    r   Úcreate_document)ÚparentÚcollection_idÚdocumentÚdocument_idr   Údelete_document)ÚnameÚcurrent_documentÚget_document)r+   r   r   r   Úlist_collection_ids)r&   Ú	page_sizeÚ
page_tokenr   Úlist_documents)	r&   r'   r/   r0   Úorder_byr   r   r   Úshow_missingÚlisten)r   Ú
add_targetÚremove_targetr!   Úpartition_query)r&   Ústructured_queryÚpartition_countr0   r/   r   Úrollback)r   r   Úrun_aggregation_query)r&   Ústructured_aggregation_queryr   r   r   Úexplain_optionsÚ	run_query)r&   r8   r   r   r   r=   Úupdate_document)r(   Úupdate_maskr   r,   Úwrite)r   Ú	stream_idr    Ústream_tokenr!   Ú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>L   s    z5firestoreCallTransformer.leave_Call.<locals>.<lambda>c                 s   s   � | ]	}|j jd kV  qdS )ÚrequestN)rI   Úvalue)Ú.0Úkr   r   r   Ú	<genexpr>M   s   € z6firestoreCallTransformer.leave_Call.<locals>.<genexpr>c                    s   | j jˆ jvS rG   )rI   rN   r   rJ   ©Úselfr   r   rL   R   s    c                 s   s,   � | ]\}}t j|jt j|d �d�V  qdS )©rN   ©rN   rI   N)ÚcstÚArgrN   ÚName)rO   rK   Úctrlr   r   r   rQ   W   s   €  ÿc              	   S   s2   g | ]\}}t  t  d  |¡¡t j|jd�¡‘qS )z'{}'rT   )rV   ÚDictElementÚSimpleStringÚformatÚElementrN   )rO   r+   Úargr   r   r   Ú
<listcomp>[   s    ùþÿz7firestoreCallTransformer.leave_Call.<locals>.<listcomp>rM   rU   )Úargs)ÚfuncÚattrrN   rD   ÚAttributeErrorÚKeyErrorr   r`   ÚanyÚlenÚextendÚzipr   rV   rW   r   rX   Úwith_changes)
rS   rE   rF   ÚkeyÚkword_paramsr`   ÚkwargsÚctrl_kwargsÚ	ctrl_argsÚrequest_argr   rR   r   Ú
leave_CallB   s4   
þ
þ"

ÿ
ø	öÿz#firestoreCallTransformer.leave_CallN)Ú__name__Ú
__module__Ú__qualname__r   r   ÚstrÚ__annotations__rD   r   rV   ÚCallÚCSTNoderp   r   r   r   r   r   -   sH   
 ÿþýüûúùø	÷
öõôóòñð 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)rO   ÚrootÚ_ÚfilesÚfr   r   r   rQ   x   s   € ýþýzfix_files.<locals>.<genexpr>ÚrNT)ÚparentsÚexist_okÚw)r{   ÚwalkÚopenÚreadrV   Úparse_moduleÚvisitÚjoinpathÚrelative_tor&   ÚmkdirrA   Úcode)
ry   rz   rx   Ú
pyfile_genÚfpathr„   ÚsrcÚtreerF   Úupdated_pathr   r   r   Ú	fix_filesl   s    þ
ÿ

ÿ€ór—   Ú__main__a¢  Fix up source that uses the firestore 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)!Úargparser{   ÚlibcstrV   ÚImportErrorr~   ÚsysÚtypingr   r   r   r   r   r   rH   r   ÚCSTTransformerr   r   r—   rq   ÚArgumentParserÚparserÚadd_argumentÚ
parse_argsr`   rš   rž   Úis_dirÚprintÚstderrÚexitÚlistdirr   r   r   r   Ú<module>   s‚   ÿ ÿþ
ýCüÿ
þ#ÿûû
þ

þ


þ
Ê