o
    iSbq  ã                   @   s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZG dd„ deƒZ	d\Z
ZZZG dd„ dƒZG dd	„ d	eeƒZd
ejv rKejd
 dkrKdZndZdd„ Zedkr‡eƒ  eƒ Ze ed¡ e ¡  e d¡Ze d¡Ze ¡  eejƒ eejƒ eeƒ eeƒ dS dS )é    )Úprint_functionNc                   @   s   e Zd ZdS )ÚDebconfErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú)/usr/lib/python3/dist-packages/debconf.pyr   "   s    r   )ÚlowÚmediumÚhighÚcriticalc                   @   sb   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚDebconfaT  A class that speaks the debconf protocol.

    The simplest way to use this is as a context manager:

        import debconf

        with debconf.Debconf(run_frontend=True) as db:
            print(db.get('debconf/frontend'))

    Note that this will send the STOP command on exiting the context
    manager, so you shouldn't expect to be able to use the same frontend
    again after this.  If you need to do that, then you should instantiate
    the class directly instead:

        import debconf

        db = debconf.Debconf(run_frontend=True)
        print(db.get('debconf/frontend'))
    NFc                 C   sP   d  ¡ D ]}|  |¡ q|ptj| _|ptj| _tjt_|r!tƒ  |  	|¡ d S )Nz©capb set reset title input beginblock endblock go get register unregister subst fset fget previous_module visible purge metaget exist version settitle info progress data)
ÚsplitÚ
setCommandÚsysÚstdinÚreadÚstdoutÚwriteÚstderrÚrunFrontEndÚsetUp)ÚselfÚtitler   r   Úrun_frontendÚcommandr   r   r   Ú__init__<   s   ýzDebconf.__init__c                 C   sR   |   d¡| _ | j d d… dkrtdd| j  ƒ‚|  ¡  ¡ | _|r'|  |¡ d S d S )Né   z2.é   zwrong version: %s)Úversionr   Úcapbr   Úcapabilitiesr   )r   r   r   r   r   r   I   s   ÿzDebconf.setUpc                    s   t ˆˆ ‡ ‡fdd„ƒ d S )Nc                     s   ˆj ˆ g| ¢R i |¤ŽS ©N)r   )ÚargsÚkw©r   r   r   r   Ú<lambda>S   s    z$Debconf.setCommand.<locals>.<lambda>)Úsetattr)r   r   r   r%   r   r   Q   s   ÿzDebconf.setCommandc           	   
   G   s"  |  ¡ }| j d|d tt|ƒ¡f ¡ | j ¡  	 z
| j ¡  d¡}W n t	y= } z|j
t
jkr8W Y d }~q‚ d }~ww d|v rK| dd¡\}}n|d}}t|ƒ}|dkrZ|S |dkrŒd}t d|¡D ]#}| d	¡r…t|ƒd
kr…|d dkr~|d7 }qf||d 7 }qf||7 }qf|S t||ƒ‚)Nz%s %s
ú TÚ
é   Ú r   z(\\.)ú\r   Ún)Úupperr   ÚjoinÚmapÚstrÚflushr   ÚreadlineÚrstripÚIOErrorÚerrnoÚEINTRr   ÚintÚreÚ
startswithÚlenr   )	r   r   ÚparamsÚrespÚeÚstatusÚdataÚ	unescapedÚchunkr   r   r   r   U   s:    
€ü



zDebconf.commandc                 C   s   | j   d¡ | j  ¡  d S )NzSTOP
)r   r2   ©r   r   r   r   Ústopy   s   zDebconf.stopc              
   C   sJ   z	|   ||¡ W dS  ty$ } z|jd dkr‚ W Y d }~dS d }~ww )Nr*   r   é   )Úinputr   r#   )r   ÚpriorityÚquestionr>   r   r   r   Ú
forceInput}   s   
ÿ€ýzDebconf.forceInputc                 C   s   |   |¡}|dkS )NÚtrue©Úget)r   rH   Úresultr   r   r   Ú
getBoolean†   s   
zDebconf.getBooleanc                 C   s
   |   |¡S r"   rK   )r   rH   r   r   r   Ú	getStringŠ   s   
zDebconf.getStringc                 C   s   | S r"   r   rC   r   r   r   Ú	__enter__�   s   zDebconf.__enter__c                 C   s   |   ¡  d S r"   )rD   )r   Úexc_typeÚ	exc_valueÚexc_tbr   r   r   Ú__exit__�   s   zDebconf.__exit__)NNNF)r   r   r   Ú__doc__r   r   r   r   rD   rI   rN   rO   rP   rT   r   r   r   r   r   '   s    
$	r   c                       s.   e Zd Zd	‡ fdd„	Zdd„ Zdd„ Z‡  ZS )
ÚDebconfCommunicatorNFc                    s~   dd|g}t j|t jt jddd�| _tt| ƒj|| jj| jjd� |r=t	 	| j
 ¡ t	jt	j¡ t	 	| j ¡ t	jt	j¡ d S d S )Nzdebconf-communicatez-fnoninteractiveT)r   r   Ú	close_fdsÚuniversal_newlines)r   r   r   )Ú
subprocessÚPopenÚPIPEÚdccommÚsuperrV   r   r   r   Úfcntlr   ÚfilenoÚF_SETFDÚ
FD_CLOEXECr   )r   Úownerr   Úcloexecr#   ©Ú	__class__r   r   r   •   s   

þþþzDebconfCommunicator.__init__c                 C   s:   | j d ur| j j ¡  | j j ¡  | j  ¡  d | _ d S d S r"   )r\   r   Úcloser   ÚwaitrC   r   r   r   Úshutdown¡   s   


üzDebconfCommunicator.shutdownc                 C   s$   z|   ¡  W d S  ty   Y d S w r"   )rh   ÚAttributeErrorrC   r   r   r   Ú__del__©   s
   ÿzDebconfCommunicator.__del__)NF)r   r   r   r   rh   rj   Ú__classcell__r   r   rd   r   rV   ”   s    rV   ÚDEBCONF_USE_CDEBCONFr+   z/usr/lib/cdebconf/debconfz/usr/share/debconf/frontendc                   C   s4   dt jvrdt jd< t  tttjgtj ¡ d S d S )NÚDEBIAN_HAS_FRONTENDÚ1ÚPERL_DL_NONLAZY)ÚosÚenvironÚexecvÚ_frontEndProgramr   Ú
executableÚargvr   r   r   r   r   ¶   s   

þr   Ú__main__z&bsdmainutils/calendar_lib_is_not_emptyzless/add_mime_handlerzapt-listchanges/email-address) Ú
__future__r   r   rp   r6   r9   rY   r^   Ú	Exceptionr   ÚLOWÚMEDIUMÚHIGHÚCRITICALr   ÚobjectrV   rq   rs   r   r   ÚdbrI   ÚgorN   ÚlessrO   ÚaptlcrD   Úprintr   r!   r   r   r   r   Ú<module>   s8   m




õ