o
    c                     @   s  d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	l
mZ dd
lmZ ddlmZ eeZdeee  dee fddZdee dee dee fddZdedee dee fddZdedee deeef fddZdS )z*Contains UI methods for Apache operations.    N)Iterable)List)Optional)Sequence)Tuple)errors)os)util)VirtualHostvhostsreturnc                 C   s^   | sg S dd | D }|r|d dd |d< t jd|dd\}}|t jkr-t|| }|S g S )zSelect multiple Vhosts to install the certificate for

    :param vhosts: Available Apache VirtualHosts
    :type vhosts: :class:`list` of type `~VirtualHost`

    :returns: List of VirtualHosts
    :rtype: :class:`list`of type `~VirtualHost`
    c                 S   s   g | ]}|  d  qS )
)display_repr).0vhost r   Q/opt/certbot/lib/python3.10/site-packages/certbot_apache/_internal/display_ops.py
<listcomp>   s    z)select_vhost_multiple.<locals>.<listcomp>NzJWhich VirtualHosts would you like to install the wildcard certificate for?T)tagsforce_interactive)display_util	checklistOK_reversemap_vhosts)r   	tags_listcodenamesreturn_vhostsr   r   r   select_vhost_multiple   s   	


r   r   c                 C   s:   g }| D ]}|D ]}|   | kr|| qq|S )zmHelper function for select_vhost_multiple for mapping string
    representations back to actual vhost objects)r   stripappend)r   r   r   	selectionr   r   r   r   r   )   s   
r   domainc                 C   s,   |sdS t | |\}}|tjkr|| S dS )a  Select an appropriate Apache Vhost.

    :param str domain: Domain for vhost selection

    :param vhosts: Available Apache VirtualHosts
    :type vhosts: :class:`list` of type `~VirtualHost`

    :returns: VirtualHost or `None`
    :rtype: `~obj.Vhost` or `None`

    N)_vhost_menur   r   )r#   r   r   tagr   r   r   select_vhost5   s   
r&   c                 C   s6  t jtd td d }|dk rtd d}d}n
t|d }|| }g }|D ]A}t| dkr<tt| }n	| sCd}nd	}|	d
j
tj|jd| |d| |jr]dnd|jrcdnd||d q)zt jd|  dtj d|dd\}}	W ||	fS  tjy   d|  d}
t|
 t|
w )zSelect an appropriate Apache Vhost.

    :param vhosts: Available Apache Virtual Hosts
    :type vhosts: :class:`list` of type `~obj.Vhost`

    :returns: Display tuple - ('code', tag')
    :rtype: `tuple`

    HTTPSEnabled	      zPDisplay size is too small for certbot_apache._internal.display_ops._vhost_menu()   g333333? zMultiple Namesz@{fn:{fn_size}s} | {name:{name_size}s} | {https:5s} | {active:7s}N)fnnamehttpsactivefn_size	name_sizez?We were unable to find a vhost with a ServerName or Address of .z,Which virtual host would you like to choose?T)r   z<Encountered vhost ambiguity when trying to find a vhost for z but was unable to ask for user guidance in non-interactive mode. Certbot may need vhosts to be explicitly labelled with ServerName or ServerAlias directives.)r   WIDTHlenloggerdebugint	get_namesnextiterr!   formatr   pathbasenamefilepsslenabledmenulinesepr   MissingCommandlineFlagerror)r#   r   
free_charsfilename_sizedisp_name_sizechoicesr   	disp_namer   r%   msgr   r   r   r$   I   sV   



r$   )__doc__loggingtypingr   r   r   r   r   certbotr   certbot.compatr   certbot.displayr	   r   certbot_apache._internal.objr
   	getLogger__name__r6   r   strr   r&   r8   r$   r   r   r   r   <module>   s     
"&