U
    g                     @   s"  U d dl Z d dlZd dlmZ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 d dlmZmZ d dlmZmZ d	gZe ejd
edejdde ddeddejddddeddejddeddejejdddZee edddZeZ ej!e"d	< dS )    N)IterableOptional)__version__)
CLIContext)CLIRootConfigparse_cli_config) SIGNING_PLUGIN_ENTRY_POINT_GROUPSIGNING_PLUGIN_REGISTRY)DEFAULT_CONFIG_FILElogging_setup)	LogConfigparse_logging_configcli_rootZpyHanko)Z	prog_nameversionz--configz.YAML file to load configuration from[default: ]Fr)helprequiredtypez	--verbosezRun in verbose modeT)r   r   defaultr   is_flagz--no-pluginsz"Disable non-builtin plugin loading)r   r   r   )ctxc              
   C   s  d }|d krz&t td}| }W 5 Q R X t}W q tk
rF   Y q tk
r } ztdt dt| W 5 d }~X Y qX nDz| }W n6 tk
r } ztdt| W 5 d }~X Y nX | t	 | j
}d }|d k	rt|}|j|_|j}	nti }	ddlm}
 t|| d}|
| |rJ|	d  }ttj|jd|	d < n8|	d  j}ttj|d|	d	< d
|	krttj|d|	d
< t|	| |rtd |d k	rtd| d n
td d S )Nr   zFailed to read z: zFailed to read configuration:    )register)plugins_enabled)leveloutputzpyhanko_certvalidator.fetcherszfontTools.subsetzRunning with --verbosez$Finished reading configuration from .z$There was no configuration to parse.)openr
   readFileNotFoundErrorIOErrorclickZClickExceptionstrZensure_objectr   objr   config
log_configr   Zcommands.signingr   _load_pluginsr   loggingDEBUGr   WARNINGr   debug)r   r%   verboseZ
no_pluginsZconfig_textfeZctx_objcfgr&   r   Zplugins_to_registerZroot_logger_configZ
log_output r0   5/tmp/pip-unpacked-wheel-owvgwkas/pyhanko/cli/_root.py_root   sf    
 
 

 



r2   )root_configr   c           
   	      s  dd l }ddlm  dddg}g }|rj| d k	rB|dd | jD 7 }|jdk r^  tg }n jtd	} fd
d|D }tt	}t
dd t	D }t||D ]^}| }	t|	tsttjd|j dt|	 ddd q|	|kr||	 ||	  q|S )Nr   metadataz4pyhanko.cli.commands.signing.pkcs11_cli:PKCS11Pluginz0pyhanko.cli.commands.signing.simple:PKCS12Pluginz0pyhanko.cli.commands.signing.simple:PemderPluginc                 S   s   g | ]}t |qS r0   )r#   ).0modr0   r0   r1   
<listcomp>   s     z!_load_plugins.<locals>.<listcomp>)   
   )groupc                    s   g | ]} j d |tdqS ) )namevaluer;   )
EntryPointr   )r6   vr4   r0   r1   r8      s   c                 s   s   | ]}t |V  qd S )N)r   )r6   xr0   r0   r1   	<genexpr>   s     z _load_plugins.<locals>.<genexpr>zTPlugins must be defined as references to classes with a nullary init function, but 'z' is a z. Disregarding...T)Zbold)sys	importlibr5   Zplugin_endpointsversion_infoentry_pointsgetr   listr	   set	itertoolschainload
isinstancer   r"   Zechostyler>   addappend)
r3   r   rC   Zto_loadZeps_from_metadataZto_load_as_endpointsZresulting_pluginsseenepZ
plugin_clsr0   r4   r1   r'   q   sJ    
 


r'   )#rJ   r(   typingr   r   r"   Zpyhankor   Zpyhanko.cli._ctxr   Zpyhanko.cli.configr   r   Zpyhanko.cli.plugin_apir   r	   Zpyhanko.cli.runtimer
   r   Zpyhanko.config.loggingr   r   __all__r;   Zversion_optionoptionZFileboolZpass_contextContextr2   r'   r   Group__annotations__r0   r0   r0   r1   <module>   sJ    
	C7