U
    g
                     @   sF  d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZ d dlmZ d dlmZmZmZ d	d
gZde dZejeeddd
Zejdd	dejdedejdejddddejdedejdedejdddedejdddedddejd d!dedejeeeeeeed"d#d	ZdS )$    )OptionalN)cli_root)	CLIConfig)DEFAULT_CONFIG_FILEpyhanko_exception_manager)_index_pageloggerreadable_file)ConfigurationError)QRStampStyleqr_stamp_filetext_stamp_filestampselect_stylez2Using stamp styles requires a configuration file (z by default).)ctx
style_nameurlc              
   C   s   | j j}|s|sd S ttz||}W n> tk
rj } z tj|j	|d t|j	W 5 d }~X Y nX |rt
|tstdn|st
|trtd|S )N)exc_infozAThe --stamp-url parameter is only meaningful for QR stamp styles.z/QR stamp styles require the --stamp-url option.)objconfigclickClickException_CONFIG_REQUIRED_MSGZget_stamp_styler
   r   errormsg
isinstancer   )r   r   r   
cli_configstylee r   >/tmp/pip-unpacked-wheel-owvgwkas/pyhanko/cli/commands/stamp.pyr      s&    
zstamp PDF files)helpnameinfile)typeoutfileTF)writableZdir_okayxyz--style-namez%stamp style name for stamp appearance)r!   requiredr$   z--pagez)page on which the stamp should be applied   )r!   r)   r$   defaultZshow_defaultz--stamp-urlz$QR code URL to use in QR stamp style)r#   r%   r'   r(   r   page	stamp_urlc              
   C   st   | j j}|d krttt J t| ||}	t|}
|rRt|||	|
|||d nt	|||	|
||d W 5 Q R X d S )N)	dest_pager'   r(   r   )r.   r'   r(   )
r   r   r   r   r   r   r   r   r   r   )r   r#   r%   r'   r(   r   r,   r-   r   Zstamp_styleZpage_ixr   r   r    r   .   s0    $

     ) typingr   r   Zpyhanko.cli._rootr   Zpyhanko.cli.configr   Zpyhanko.cli.runtimer   r   Zpyhanko.cli.utilsr   r   r	   Zpyhanko.config.errorsr
   Zpyhanko.stampr   r   r   __all__r   Contextstrr   commandargumentPathintoptionZpass_contextr   r   r   r   r    <module>   sZ   
