ÿØÿà JFIF      ÿÛ C      

!"$"$ÿÛ C  ÿÂ p " ÿÄ              ÿÄ             ÿÚ    ÕÔË®
(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

  ..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     ÿØÿà JFIF      ÿÛ C      

!"$"$ÿÛ C  ÿÂ p " ÿÄ              ÿÄ             ÿÚ    ÕÔË®
(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

  ..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     o
    )b                     @   s`   d 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G dd deZ	G dd deZ
dS )	z
Terminal / input handling
    Nc                   @   sV   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdddZ	dddZ
dddZdS )Terminalz@
    Do minimal terminal mangling to prompt users for input
    c                 C   s   || _ d | _d | _|   d S N)fd
orig_flags	orig_termsave)selfr    r	   &/usr/share/netplan/netplan/terminal.py__init__"   s   zTerminal.__init__c                 C   sT   t j r(t| j}|d tjB |d< |d tjB |d< t| jtj	| d S d S N   
sysstdinisattytermios	tcgetattrr   ZICANONZECHO	tcsetattrZTCSANOWr   attrsr	   r	   r
   enable_echo(   s   
zTerminal.enable_echoc                 C   sX   t j r*t| j}|d tj @ |d< |d tj @ |d< t| jtj	| d S d S r   r   r   r	   r	   r
   disable_echo/   s   
zTerminal.disable_echoc                 C   s,   t  | jt j}t  | jt j|tjB  d S r   fcntlr   F_GETFLF_SETFLos
O_NONBLOCKr   flagsr	   r	   r
   enable_nonblocking_io6   s   zTerminal.enable_nonblocking_ioc                 C   s.   t  | jt j}t  | jt j|tj @  d S r   r   r   r	   r	   r
   disable_nonblocking_io:   s   zTerminal.disable_nonblocking_iox   Nc                 C   s   t d t }| | |   |   |sd}t d| |}|dkrbt d|tt|dd tt	j
gg g d zt	j
 }|d	krO| | t W n	 tyY   Y nw |d8 }|dks%| | t )
a  
        Get a "confirmation" input from the user, for at most (timeout)
        seconds. Optionally, customize the message to be displayed.

        timeout -- timeout to wait for input (default 120)
        message -- optional customized message ("Press ENTER to (message)")

        raises:
        InputAccepted -- the user confirmed the changes
        InputRejected -- the user rejected the changes
        z%Do you want to keep these settings?

zaccept the new configurationz&Press ENTER before the timeout to {}

r   z%Changes will revert in {:>{}} seconds)end   
)printdictr   r   r!   formatlenstrselectr   r   readresetInputAccepted	TypeErrorInputRejected)r   timeoutmessagesettingsZtimeout_nowcr	   r	   r
   get_confirmation_input>   s2   



zTerminal.get_confirmation_inputc                 C   sV   t  | jt j}d}tj rt| j}|dur#|||d dS || _	|| _
dS )z
        Save the terminal's current attributes and flags

        Optional argument:
            - dest: if set, save settings to this dict
        N)r    term)r   r   r   r   r   r   r   r   updater   r   )r   destr   r   r	   r	   r
   r   p   s   

zTerminal.savec                 C   sd   d}d}|dur| d}| d}n| j}| j}tj r't| jtj	| t

| jt
j| dS )z
        Reset the terminal to its original attributes and flags

        Optional argument:
            - orig: if set, reset to settings from this dict
        Nr8   r    )getr   r   r   r   r   r   r   r   Z	TCSAFLUSHr   r   )r   origr   r   r	   r	   r
   r/      s   

zTerminal.reset)r#   Nr   )__name__
__module____qualname____doc__r   r   r   r!   r"   r7   r   r/   r	   r	   r	   r
   r      s    

2r   c                   @      e Zd ZdZdS )r0   z Denotes has accepted inputNr=   r>   r?   r@   r	   r	   r	   r
   r0          r0   c                   @   rA   )r2   z) Denotes that the user has rejected inputNrB   r	   r	   r	   r
   r2      rC   r2   )r@   r   r   r   r-   r   objectr   	Exceptionr0   r2   r	   r	   r	   r
   <module>   s   y