a
    !f"                     @   s  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 eegef ee ee
e e
e f dddZG dd dejZe dejejd	d
dZedkre 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 sXede dejd ed eerede dejd ed eee dS )    N)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   f/var/www/html/python-backend/venv/lib/python3.9/site-packages/../../../bin/fixup_pubsub_v1_keywords.py	partition   s    r   c                '   @   s   e Zd ZU dZee e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"< e	j
e	j
e	jd#d$d%Zd&S )'pubsubCallTransformer)retrytimeoutmetadataCTRL_PARAMS)subscriptionack_ids)nameschema)parentr   Z	schema_id)r   r   labels)r   topicpush_configZbigquery_configZcloud_storage_configack_deadline_secondsZretain_acked_messagesmessage_retention_durationr   Zenable_message_orderingZexpiration_policyfilterZdead_letter_policyZretry_policyZdetachedZenable_exactly_once_deliveryZ topic_message_retention_durationstate)	r   r   Zmessage_storage_policyZkms_key_nameZschema_settingsZsatisfies_pzsr!   r#   Zingestion_data_source_settings)r   )r   Zrevision_id)snapshot)r   )r   )r   view)r   r%   	page_size
page_token)r   r%   r&   r'   )projectr&   r'   )r   r&   r'   )r   r   r    )r   r   )r   messages)r   Zmax_messagesZreturn_immediately)r   timer$   )r   Zstream_ack_deadline_secondsr   Zmodify_deadline_secondsZmodify_deadline_ack_idsZ	client_idZmax_outstanding_messagesZmax_outstanding_bytes)r$   update_mask)r   r+   )r   r+   )r   r   r   messageencoding)r   r   )resourceoptions)r.   policy)r.   Zpermissions)&ZacknowledgeZcommit_schemaZcreate_schemaZcreate_snapshotZcreate_subscriptionZcreate_topicZdelete_schemaZdelete_schema_revisionZdelete_snapshotZdelete_subscriptionZdelete_topicZdetach_subscriptionZ
get_schemaZget_snapshotZget_subscriptionZ	get_topicZlist_schema_revisionsZlist_schemasZlist_snapshotsZlist_subscriptionsZlist_topicsZlist_topic_snapshotsZlist_topic_subscriptionsZmodify_ack_deadlineZmodify_push_configpublishpullZrollback_schemaseekZstreaming_pullZupdate_snapshotZupdate_subscriptionZupdate_topicZvalidate_messageZvalidate_schemaZget_iam_policyZset_iam_policyZtest_iam_permissionsMETHOD_TO_PARAMS)originalupdatedr
   c           
   	      s   z|j jj} j| }W n ttfy2   | Y S 0 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>\       z2pubsubCallTransformer.leave_Call.<locals>.<lambda>c                 s   s   | ]}|j jd kV  qdS )requestN)r9   value).0kr   r   r   	<genexpr>]   r=   z3pubsubCallTransformer.leave_Call.<locals>.<genexpr>c                    s   | j j jvS r7   )r9   r?   r   r:   selfr   r   r<   b   r=   c                 s   s*   | ]"\}}t j|jt j|d dV  qdS )r?   r?   r9   N)cstArgr?   Name)r@   r;   Zctrlr   r   r   rB   g   s   c              	   S   s2   g | ]*\}}t t d |t j|jdqS )z'{}'rE   )rG   ZDictElementZSimpleStringformatZElementr?   )r@   r   argr   r   r   
<listcomp>k   s
   z4pubsubCallTransformer.leave_Call.<locals>.<listcomp>r>   rF   )args)funcattrr?   r4   AttributeErrorKeyErrorr   rM   anylenextendzipr   rG   rH   r   rI   Zwith_changes)
rD   r5   r6   keyZkword_paramsrM   kwargsZctrl_kwargsZ	ctrl_argsZrequest_argr   rC   r   
leave_CallR   s2    


"


	z pubsubCallTransformer.leave_CallN)__name__
__module____qualname__r   r   str__annotations__r4   r   rG   CallZCSTNoderX   r   r   r   r   r   '   sR   
)r   )transformer)in_dirout_dirc          
   	   C   s   dd t | D }|D ]}t|d}| }W d   n1 sD0    Y  t|}||}||| }	|	j	j
ddd t|	d}||j W d   q1 s0    Y  qdS )zDuplicate 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   sF   | ]>\}}}|D ].}t j|d  dkrtt j||V  qqdS )r   z.pyN)ospathsplitextpathlibPathjoin)r@   root_filesfr   r   r   rB      s   zfix_files.<locals>.<genexpr>rNT)parentsexist_okw)rb   walkopenreadrG   Zparse_modulevisitjoinpathrelative_tor   mkdirwritecode)
r`   ra   r_   Z
pyfile_genZfpathrk   srctreer6   Zupdated_pathr   r   r   	fix_files|   s    &

r{   __main__a  Fix up source that uses the pubsub 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)filezoutput directory 'z' is not empty) argparserb   ZlibcstrG   re   systypingr   r   r   r   r   r   r8   r   ZCSTTransformerr   rf   r{   rY   ArgumentParserparseradd_argument
parse_argsrM   r~   r   is_dirprintstderrexitlistdirr   r   r   r   <module>   sn    Y#








