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re  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 )Nzcapb 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rd}td|D ]#}|d	rt|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>   s:   m




