a
    �˜ëj
  ã                   @   sL   d dl mZ d dlmZmZmZ dZdZdZe	ddd�Z
d	d
„ Zdd„ ZdS )é    )ÚPath)Ú	add_inputÚ	get_inputÚparse_numtextÚlistÚextractZeditú+© )ÚnargsÚdefaultc                 C   s®   t | dd� | jdd�}| t¡ | t¡}|jdtd� |jddtd	d
� | t¡}|jdi t	¤ddi¤Ž |jdtdd� |jdi t	¤dtdœ¤Ž |jddtd	d
� d S )NF)ZpagesÚaction)Údestz--nums)Útypez--output-dirz-oT)r   Úrequiredú
--set-descÚhelpz¹Syntax: n=desc, where n is the attachment number, and desc the new description to be set. Example: '1=Hello world'. Use `pypdfium2 attachments list` to determine the attachment numbers.z
--del-numsr	   )r   r   ú--add-filesÚF)Úmetavarr   z--output)r   )r   )
r   Úadd_subparsersÚ
add_parserÚACTION_LISTÚACTION_EXTRACTÚadd_argumentr   r   ÚACTION_EDITÚ
NARGS_PLUS)ÚparserZ
subparsersZparser_extractZparser_editr	   r	   úX/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pypdfium2_cli/attachments.pyÚattach   sN    

þý
 ÿþýý ÿþü
ýr   c              	   C   s   t | ƒ}| ¡ }| jtkr|t|ƒD ]T}| |¡}| ¡ }|rFd|›�nd}td|d › d| ¡ › d| 	¡ › d�| ƒ q"�n | jt
krò| js–t|ƒ| _ttt| jƒd ƒƒ}| jD ]<}| |¡}| ¡ }| jd||d |f  }	|	 | ¡ ¡ q²nª| jtk�r”| jD ]8}
|
jd	dd
�\}}t|ƒd }| |¡}| |¡ �qt| jdd�D ]}| |¡ �qL| jD ] }| |j¡}| | ¡ ¡ �qd| | j¡ nt dƒ‚d S )Nz: Ú ú[é   z] z (ú)z%0*d_%sú=)ÚmaxsplitT)ÚreversezNo valid subcommand provided)!r   Zcount_attachmentsr   r   ÚrangeZget_attachmentZget_descÚprintÚget_nameZget_subtyper   ÚnumsÚlenÚstrÚmaxÚ
output_dirÚwrite_bytesÚget_datar   Zset_descÚsplitÚintÚsortedZdel_numsZdel_attachmentZ	add_filesZnew_attachmentÚnameÚset_dataÚ
read_bytesÚsaveÚoutputÚ
ValueError)ÚargsZpdfZn_attachmentsÚiZatmÚdescZdesc_strZn_digitsr3   Zout_pathÚspecZnum_strÚfpr	   r	   r   Úmain<   s<    

2






r>   N)Úpathlibr   Zpypdfium2_cli._parsersr   r   r   r   r   r   Údictr   r   r>   r	   r	   r	   r   Ú<module>   s   +