o
    S™`ñ  ã                   @   sP   d dl mZ G dd„ deƒZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dS )é    )Úutilsc                   @   s   e Zd ZdS )ÚStreamOutputErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú9/usr/lib/python3/dist-packages/compose/progress_stream.pyr      s    r   c              	   C   sL   z|  | ¡ W d S  ty%   t|ddƒ}|  | j|dd |¡¡ Y d S w )NÚencodingÚasciiÚreplace)Úerrors)ÚwriteÚUnicodeEncodeErrorÚgetattrÚencodeÚdecode)ÚsÚstreamr	   r   r   r   Úwrite_to_stream   s    þr   c                 c   sè    t |dƒo	| ¡ }|}i }d}t | ¡D ]\}|V  d|v p!d|v }|s/t|||ƒ | ¡  q|s2q| d¡}|s:q||vrIt|ƒ||< td|ƒ t|ƒ||  }tdd|f |ƒ t|||ƒ d|v rmtd	d|f |ƒ | ¡  qd S )
NÚisattyr   ÚprogressÚprogressDetailÚidÚ
z%c[%dAé   z%c[%dB)	Úhasattrr   r   Újson_streamÚprint_output_eventÚflushÚgetÚlenr   )Úoutputr   Úis_terminalÚlinesÚdiffÚeventÚis_progress_eventÚimage_idr   r   r   Ústream_output   s6   €


àr(   c                 C   sj  d| v rt | d d ƒ‚d}|rd| vrtdd |ƒ d}nd| v r$d S d	| v r1td
| d	  |ƒ d| v r>td| d  |ƒ d| v rKtd| d  |ƒ |  dd¡}d| v rctd || d |¡|ƒ d S d| v r™| d }| d¡}d|v rŽ|rŽt|d ƒt|ƒ d }td |||¡|ƒ d S td ||¡|ƒ d S d| v rªtd | d |¡|ƒ d S td ||¡|ƒ d S )NÚerrorDetailÚmessageÚ r   z%c[2Kr   úr   Útimez[%s] r   z%s: Úfromz
(from %s) Ústatusr   z{} {}{}ÚtotalÚcurrentéd   z{} ({:.1f}%){}z{}{}z{}{}
)r   r   r   ÚformatÚfloat)r%   r   r"   Ú
terminatorr/   Údetailr0   Ú
percentager   r   r   r   9   s6   
r   c                 C   s>   d }| D ]}|  d¡}|rd|vrq| dd¡d  ¡ }q|S )Nr/   ÚDigestú:é   )r   ÚsplitÚstrip)ÚeventsÚdigestr%   r/   r   r   r   Úget_digest_from_pulla   s   
r?   c                 C   s,   | D ]}|  di ¡  d¡}|r|  S qd S )NÚauxr8   )r   )r=   r%   r>   r   r   r   Úget_digest_from_pushl   s   ÿrA   c                 C   sT   | d   ¡ }d| v r(| d }d|v r(d|v r(t|d ƒt|d ƒ }d ||¡}|S )Nr/   r   r1   r0   z{} ({:.1%}))Úlowerr4   r3   )r%   r/   r6   r7   r   r   r   Úread_statust   s   rC   N)
Úcomposer   Ú	Exceptionr   r   r(   r   r?   rA   rC   r   r   r   r   Ú<module>   s    )(