
    \jk                        d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZm	Z	 	 d dl
Z
dZ e j                  d      Z e j                  d	      Zd
edefdZd
edefdZddddededee   dee	   deddfdZdedefdZd!dededefdZ G d d      Z G d de      Z	 d"dedee	   dededef
d Zy# e$ r dZY w xY w)#    N)datetime)unified_diff)Path)OptionalTextIOFTz\+[^+]z-[^-]import_linereturnc                     | j                         } | j                  d      r&| j                  dd      } | j                  dd      } | S | j                  d      r| j                  dd      } | S )Nfrom   import .import )strip
startswithreplace)r   s    6/root/env/lib/python3.12/site-packages/isort/format.pyformat_simplifiedr      sr    ##%Kg&!))'26!))*c:  
				*!)))R8    c                     | j                         } | j                  d      sS| j                  d      sBd| vrd|  S | j                  d      }|j                  d      }ddj	                  |       d| S | S )Nr   r   r   r   )r   r   splitpopjoin)r   partsends      r   format_naturalr      s    ##%K!!'*;3I3I)3Tk![M**!!#&iimsxx'xu55r   )outputcolor_output
file_inputfile_output	file_pathr   r   c                    t        ||      }|dn
t        |      }t        |t        j                         n,t        j                  |j                         j                              }t        | j                  d      |j                  d      |dz   |dz   |t        t        j                                     }|D ]  }	|j                  |	        y)a  Shows a unified_diff for the provided input and output against the provided file path.

    - **file_input**: A string that represents the contents of a file before changes.
    - **file_output**: A string that represents the contents of a file after changes.
    - **file_path**: A Path object that represents the file path of the file being changed.
    - **output**: A stream to output the diff to. If non is provided uses sys.stdout.
    - **color_output**: Use color in output if True.
    Nr   T)keependsz:beforez:after)fromfiletofilefromfiledate
tofiledate)
create_terminal_printerstrr   nowfromtimestampstatst_mtimer   
splitlines	diff_line)
r    r!   r"   r   r   printer	file_name
file_mtimeunified_diff_lineslines
             r   show_unified_diffr6   +   s      &lF;G'S^I#+1G1G	HXHaHa1bJ &t,-Y&8#x||~& #  $ r   c                     d }|dvrBt        d|  d      }|j                         }|dv ry|dv rt        j                  d       |dvrBy)	N)yesynonquitqzApply suggested changes to 'z' [y/n/q]? )r:   r;   F)r<   r=      T)inputlowersysexit)r"   answers     r   $ask_whether_to_apply_changes_to_filerD   L   s]    F
<
<5i[LM[ ]"HHQK <
< r   contentline_separatorc                 j    | j                  |d      j                  dd      j                  dd      } | S )Nr    )r   )rE   rF   s     r   remove_whitespacerJ   X   s2    oonb199#rBJJ6SUVGNr   c                   `    e Zd ZdZdZddededee   fdZded	dfd
Z	ded	dfdZ
ded	dfdZy)BasicPrinterERRORSUCCESSNerrorsuccessr   c                 R    |xs t         j                  | _        || _        || _        y N)rA   stdoutr   success_messageerror_message)selfrO   rP   r   s       r   __init__zBasicPrinter.__init__a   s"    *

&"r   messager	   c                 |    t        | j                  j                  | j                  |      | j                         y )N)rP   rX   file)printrT   formatrN   r   rV   rX   s     r   rP   zBasicPrinter.successf   s-    d""))$,,)PW[WbWbcr   c                     t        | j                  j                  | j                  |      t        j
                         y )N)rO   rX   rZ   )r\   rU   r]   rM   rA   stderrr^   s     r   rO   zBasicPrinter.errori   s-    d  ''djj''JQTQ[Q[\r   r5   c                 :    | j                   j                  |       y rR   )r   write)rV   r5   s     r   r0   zBasicPrinter.diff_linel   s    $r   rR   )__name__
__module____qualname__rM   rN   r*   r   r   rW   rP   rO   r0    r   r   rL   rL   ]   sj    EG#c #C #&9I #
ds dt d]S ]T ] c  d  r   rL   c                   h     e Zd Zdededee   f fdZeddedee   defd	       Zd
eddfdZ	 xZ
S )ColoramaPrinterrO   rP   r   c                 b   t         |   |||       | j                  dt        j                  j
                        | _        | j                  dt        j                  j                        | _        t        j                  j                  | _	        t        j                  j
                  | _
        y )N)r   rM   rN   )superrW   
style_textcoloramaForeREDrM   GREENrN   
ADDED_LINEREMOVED_LINE)rV   rO   rP   r   	__class__s       r   rW   zColoramaPrinter.__init__q   st    7 __Whmm.?.?@
y(--2E2EF"----$MM--r   Ntextstyler	   c                 \    || S || z   t        t        j                  j                        z   S rR   )r*   rl   Style	RESET_ALL)rs   rt   s     r   rk   zColoramaPrinter.style_text{   s*    =Kt|c(..":":;;;r   r5   c                     d }t        j                  t        |      r| j                  }n&t        j                  t        |      r| j
                  }| j                  j                  | j                  ||             y rR   )	rematchADDED_LINE_PATTERNrp   REMOVED_LINE_PATTERNrq   r   rb   rk   )rV   r5   rt   s      r   r0   zColoramaPrinter.diff_line   sV    88&-OOEXX*D1%%E$//$67r   rR   )rc   rd   re   r*   r   r   rW   staticmethodrk   r0   __classcell__)rr   s   @r   rh   rh   p   sb    .c .C .&9I . < <Xc] <c < <
8c 8d 8r   rh   colorrO   rP   c                     | r8t         r2d}t        |t        j                         t        j                  d       t         st        j                  d       | rt        |||      S t        |||      S )Nz
Sorry, but to use --color (color_output) the colorama python package is required.

Reference: https://pypi.org/project/colorama/

You can either install it separately on your system or as the colors extra for isort. Ex: 

$ pip install isort[colors]
rZ   r>   F)r   )	colorama_unavailabler\   rA   r`   rB   rl   initrh   rL   )r   r   rO   rP   no_colorama_messages        r   r)   r)      se     %, 	 	!

3E"38w/>J5RY[a>br   )
)Nr   r   )ry   rA   r   difflibr   pathlibr   typingr   r   rl   r   ImportErrorcompiler{   r|   r*   r   r   boolr6   rD   rJ   rL   rh   r)   rf   r   r   <module>r      sV   	 
     #! !  RZZ	* !rzz(+ 3 3 	 	 	"  $     ~	 
 V    
 B	C 	D 	s C 3 
   &8l 86 SU!&)9<LOA    s   B4 4B>=B>