o
    8fc                  
   @   s  d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	m
Z
 ddlmZ eddd(dee d	ed
eddfddZeddd(dee d	ed
eddfddZeddd(dee d	ed
eddfddZd(dee d	ed
eddfddZdededededef
ddZedZdedee fddZdededededef
ddZd edefd!d"Zedddd#d$ed%edefd&d'ZdS ))zMNice output for Black.

The double calls are for patching purposes in tests.
    N)AnyListOptional)echostyle)
mypyc_attrT)	patchablemessagenlstylesreturnc                 K   s:   | d urd|vrd|d< t | fi |} t| |dd d S )NboldTr
   errr   r   r	   r
   r    r   E/home/ertert/spirit/venv/lib/python3.10/site-packages/black/output.py_out   
   r   c                 K   s:   | d urd|vrd|d< t | fi |} t| |dd d S )NfgredTr   r   r   r   r   r   _err   r   r   c                 K      t | fd|i| d S Nr
   )r   r   r   r   r   out!   s   r   c                 K   r   r   )r   r   r   r   r   r   &   s   r   aba_nameb_namec                    s>   t | t | fddtd D }d|S )zHReturn a unified diff string between each cell in notebooks `a` and `b`.c              	      sj   g | ]1\}}|d  dkrt dd | d d dd | d d   d|  d| qS )	cell_typecode cellssource
z:cell_)diffjoin).0cell_numbercellr   a_nbr   b_nbr   r   
<listcomp>.   s    zipynb_diff.<locals>.<listcomp>r#   r"   )jsonloads	enumerater'   )r   r   r   r   
diff_linesr   r+   r   
ipynb_diff*   s   




r3   z(.*?(?:\r\n|\n|\r|$))r$   c                 C   s.   dd t | D }|d dkr|d |S )zSplit a string into lines ignoring form feed and other chars.

    This mimics how the Python parser splits source code.

    A simplified version of the function with the same name in Lib/ast.py
    c                 S   s   g | ]}|d  qS )r   r   )r(   matchr   r   r   r.   E   s    z%_splitlines_no_ff.<locals>.<listcomp>r"   )_line_patternfinditerpop)r$   resultr   r   r   _splitlines_no_ff>   s   
r:   c           	      C   sp   ddl }t| }t|}g }|j||||ddD ]}|d dkr&|| q||d  |d qd|S )	z9Return a unified diff string between strings `a` and `b`.r   N   )fromfiletofilenr5   r%   z\ No newline at end of file
r"   )difflibr:   unified_diffappendr'   )	r   r   r   r   r?   a_linesb_linesr2   liner   r   r   r&   K   s   


r&   contentsc                 C   s   |  d}t|D ]<\}}|ds|drd| d }n#|dr*d| d }n|dr6d	| d }n|d
rAd| d }|||< q	d|S )z(Inject the ANSI color codes to the diff.r%   z+++z---z[1mz[0mz@@z[36m+z[32m-z[31m)splitr1   
startswithr'   )rE   linesirD   r   r   r   
color_diff`   s   





rL   )ensure_final_newlineoutputrM   c                 G   sp   t jdddddd#}|D ]}|| | r#|r#|d dkr#|d qW d	   |jS 1 s0w   Y  |jS )
z;Dump `output` to a temporary file. Return path to the file.wblk_z.logFutf8)modeprefixsuffixdeleteencodingr5   r%   N)tempfileNamedTemporaryFilewritename)rM   rN   frJ   r   r   r   dump_to_filep   s   



r\   )NT)__doc__r/   rerW   typingr   r   r   clickr   r   mypy_extensionsr   strboolr   r   r   r   r3   compiler6   r:   r&   rL   r\   r   r   r   r   <module>   s*    """ 
"