o
    øT·j÷  ã                   @  s€   d Z ddlmZ ddlZddlZddlZddlmZmZ ddd	„Z	d
d„ Z
ddd„Zd dd„Zd!dd„Zd"dd„Zd#dd„ZdS )$z?Pro subcommands: update, list, config (fingerprint management).é    )ÚannotationsN)ÚFingerprintManagerÚFingerprintUpdateErrorÚvalueÚstrÚreturnc                 C  s   |   d¡s
t d¡‚| S )NÚimp_zAPI key must start with 'imp_'.)Ú
startswithÚargparseÚArgumentTypeError©r   © r   úT/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/curl_cffi/cli/pro.pyÚ_validate_api_key   s   

r   c                 C  sH   | d u rdS t | tƒr| rdS dS t | ttB ƒr tj| ddd�S t| ƒS )NÚ ÚtrueÚfalse)ú,ú:F)Ú
separatorsÚensure_ascii)Ú
isinstanceÚboolÚlistÚdictÚjsonÚdumpsr   r   r   r   r   Ú_format_cell   s   
r   Úheadersú	list[str]Úrowsúlist[list[str]]c                   sŒ   dd„ | D ƒ‰ |D ]}t |ƒD ]\}}tˆ | t|ƒƒˆ |< qq	d‡ fdd„}t|| ƒƒ td	 d
d„ ˆ D ƒ¡ƒ |D ]}t||ƒƒ q;d S )Nc                 S  s   g | ]}t |ƒ‘qS r   )Úlen©Ú.0Úheaderr   r   r   Ú
<listcomp>   s    z _print_table.<locals>.<listcomp>Ú
row_valuesr   r   r   c                   s   d  ‡ fdd„t| ƒD ƒ¡S )Nz | c                 3  s"   � | ]\}}|  ˆ | ¡V  qd S )N)Úljust)r$   Úidxr   ©Úwidthsr   r   Ú	<genexpr>#   s   € 
ÿz3_print_table.<locals>.render_row.<locals>.<genexpr>)ÚjoinÚ	enumerate)r'   r*   r   r   Ú
render_row"   s   ÿz _print_table.<locals>.render_rowz-+-c                 s  s   � | ]}d | V  qdS )ú-Nr   )r$   Úwidthr   r   r   r,   (   s   € z_print_table.<locals>.<genexpr>)r'   r   r   r   )r.   Úmaxr"   Úprintr-   )r   r    Úrowr)   Úcellr/   r   r*   r   Ú_print_table   s   ÿÿr6   Úfingerprint_rowsúlist[dict[str, object]]c                   s@   g d¢}g }| D ]‰ ‡ fdd„|D ƒ}|  |¡ qt||ƒ d S )N)ÚtypeÚnameÚbrowserÚversionÚosÚ
os_versionÚh3_fingerprintsc                   s   g | ]}t ˆ | ƒ‘qS r   )r   r#   ©Úitemr   r   r&   9   s    z-_print_fingerprints_table.<locals>.<listcomp>)Úappendr6   )r7   r   r    r4   r   r@   r   Ú_print_fingerprints_table-   s   	rC   c                 C  s   t tj| ddd�ƒ d S )Né   F)Úindentr   )r3   r   r   )r    r   r   r   Ú_print_fingerprints_json>   s   rF   ÚNonec                 C  sV   | j dddd� | j dddd�}|jdd	d
d� | j dddd�}|jddtdd� dS )z.Register update, list, and config subcommands.ÚupdatezUpdate local fingerprints cachez-Update fingerprints from the impersonate API.)ÚhelpÚdescriptionr   z"List local and native fingerprintsz#List local and native fingerprints.z--jsonÚ
store_truezOutput fingerprints as JSON.)ÚactionrI   ÚconfigzConfigure API accessz$Set the API key for impersonate.pro.z	--api-keyTzAPI key for impersonate.pro)Úrequiredr9   rI   N)Ú
add_parserÚadd_argumentr   )Ú
subparsersÚlist_parserÚconfig_parserr   r   r   Úadd_pro_parsersB   s4   ýýýý
ürT   r   c              
   C  sØ   | j dkr=zt ¡ }W n ty' } ztt|ƒtjd� W Y d}~d
S d}~ww |dkr.dnd}td|› d|› d	�ƒ d
S | j dkrUt ¡ }| j	rOt
|ƒ d
S t|ƒ d
S | j dkrjt | j¡ tdt ¡  ƒ d
S dS )zAHandle pro subcommands. Returns True if handled, False otherwise.rH   )ÚfileNé   r   ÚszTotal z fingerprintz
 in cache.Tr   rM   zAPI key saved to F)Úcommandr   Úupdate_fingerprintsr   r3   r   ÚsysÚstderrÚlist_fingerprintsr   rF   rC   Úset_api_keyÚapi_keyÚget_config_path)ÚargsÚupdatedÚexcÚsuffixr    r   r   r   Úhandle_pro_commande   s.   
€û
ÿ
rd   )r   r   r   r   )r   r   r    r!   )r7   r8   )r    r8   )r   rG   )r   r   )Ú__doc__Ú
__future__r   r
   r   rZ   Úcurl_cffi.fingerprintsr   r   r   r   r6   rC   rF   rT   rd   r   r   r   r   Ú<module>   s    





#