U
    ÔZjœ  ã                   @   sx   d Z ddlZddlZddlm  mZ ddlm	Z	 ddlm
Z
 ddlmZ e e¡Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )z*Contains UI methods for Apache operations.é    N)Úerrors)Ú
interfaces)Úosc                 C   sj   | s
t ƒ S dd„ | D ƒ}|r0|d dd… |d< tj tj¡jd|dd�\}}|tjkrft	|| ƒ}|S g S )zóSelect multiple Vhosts to install the certificate for

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

    :returns: List of VirtualHosts
    :rtype: :class:`list`of type `~obj.Vhost`
    c                 S   s   g | ]}|  ¡ d  ‘qS )Ú
)Údisplay_repr)Ú.0Úvhost© r	   ú]/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/certbot_apache/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)
ÚlistÚzopeÚ	componentÚ
getUtilityr   ÚIDisplayZ	checklistÚdisplay_utilÚOKÚ_reversemap_vhosts)ÚvhostsZ	tags_listÚcodeÚnamesÚreturn_vhostsr	   r	   r
   Úselect_vhost_multiple   s    	 þ


r   c                 C   s<   t ƒ }| D ],}|D ]"}| ¡  ¡ | ¡ kr| |¡ qq
|S )zmHelper function for select_vhost_multiple for mapping string
    representations back to actual vhost objects)r   r   ÚstripÚappend)r   r   r   Z	selectionr   r	   r	   r
   r   %   s    r   c                 C   s,   |sdS t | |ƒ\}}|tjkr(|| S dS )zØSelect an appropriate Apache Vhost.

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

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

    N)Ú_vhost_menur   r   )Údomainr   r   Útagr	   r	   r
   Úselect_vhost0   s    

r!   c                 C   sB  t jtdƒ tdƒ d }|dk r6t d¡ d}d}nt|d ƒ}|| }g }|D ]‚}t| ¡ ƒdkrxtt| ¡ ƒƒ}n| ¡ s†d}nd	}| 	d
j
tj |j¡d|… |d|… |jrºdnd|jrÆdnd||d�¡ qRz,tj tj¡jd 
| tj¡|dd�\}}	W n6 tjk
�r8   d 
| ¡}
t |
¡ t |
¡‚Y nX ||	fS )zÓSelect 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`

    ZHTTPSZEnabledé	   é   zFDisplay size is too small for certbot_apache.display_ops._vhost_menu()é   g333333ã?Ú zMultiple Namesz@{fn:{fn_size}s} | {name:{name_size}s} | {https:5s} | {active:7s}N)ÚfnÚnameÚhttpsZactiveZfn_sizeÚ	name_sizezrWe were unable to find a vhost with a ServerName or Address of {0}.{1}Which virtual host would you like to choose?T)r   zÝEncountered vhost ambiguity when trying to find a vhost for {0} 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   ZWIDTHÚlenÚloggerÚdebugÚintÚ	get_namesÚnextÚiterr   Úformatr   ÚpathÚbasenameZfilepÚsslZenabledr   r   r   r   r   ZmenuÚlinesepr   ZMissingCommandlineFlagÚwarning)r   r   Z
free_charsZfilename_sizeZdisp_name_sizeÚchoicesr   Z	disp_namer   r    Úmsgr	   r	   r
   r   A   sR    

ùÿ þ üüÿ
r   )Ú__doc__ÚloggingZzope.componentr   Zcertbot.display.utilÚdisplayÚutilr   Zcertbotr   r   Zcertbot.compatr   Ú	getLoggerÚ__name__r+   r   r   r!   r   r	   r	   r	   r
   Ú<module>   s   
