
    g_                        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                           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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	   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    ./usr/lib/python3/dist-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   M   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   Y   s2    oonb199#rBJJ6SUVGNr   c                   X    e Zd ZdZdZd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SUCCESSNr   c                 6    |xs t         j                  | _        y N)rA   stdoutr   selfr   s     r   __init__zBasicPrinter.__init__b   s    *

r   messager	   c                 P    t        | j                   d| | j                         y Nz: file)printrN   r   rS   rU   s     r   successzBasicPrinter.successe   s    b	*=r   c                 X    t        | j                   d| t        j                         y rW   )rZ   rM   rA   stderrr[   s     r   errorzBasicPrinter.errorh   s    Bwi(szz:r   r5   c                 :    | j                   j                  |       y rP   )r   write)rS   r5   s     r   r0   zBasicPrinter.diff_linek   s    $r   rP   )__name__
__module____qualname__rM   rN   r   r   rT   r*   r\   r_   r0    r   r   rL   rL   ^   sV    EG+x/ +>s >t >;S ;T ; c  d  r   rL   c                   V    e Zd Zd
dee   fdZed
dedee   defd       Zdeddfd	Z	y)ColoramaPrinterNr   c                 n   |xs t         j                  | _        | j                  dt        j
                  j                        | _        | j                  dt        j
                  j                        | _	        t        j
                  j                  | _
        t        j
                  j                  | _        y )NrM   rN   )rA   rQ   r   
style_textcoloramaForeREDrM   GREENrN   
ADDED_LINEREMOVED_LINErR   s     r   rT   zColoramaPrinter.__init__p   so    *

 __Whmm.?.?@
y(--2E2EF"----$MM--r   textstyler	   c                 J    || S || z   t         j                  j                  z   S rP   )rj   Style	RESET_ALL)rp   rq   s     r   ri   zColoramaPrinter.style_texty   s%    =Kt|hnn6666r   r5   c                     d }t        j                  t        |      r| j                  }n&t        j                  t        |      r| j
                  }| j                  j                  | j                  ||             y rP   )	rematchADDED_LINE_PATTERNrn   REMOVED_LINE_PATTERNro   r   ra   ri   )rS   r5   rq   s      r   r0   zColoramaPrinter.diff_line   sV    88&-OOEXX*D1%%E$//$67r   rP   )
rb   rc   rd   r   r   rT   staticmethodr*   ri   r0   re   r   r   rg   rg   o   sS    .x/ . 7 7Xc] 7c 7 7
8c 8d 8r   rg   colorc                     | r8t         r2d}t        |t        j                         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]
rX   r>   )colorama_unavailablerZ   rA   r^   rB   rg   rL   )r{   r   no_colorama_messages      r   r)   r)      sE    %, 	 	!

3&+?6"Ef1EEr   )
rP   )rv   rA   r   difflibr   pathlibr   typingr   r   rj   r}   initImportErrorcompilerx   ry   r*   r   r   boolr6   rD   rJ   rL   rg   r)   re   r   r   <module>r      s9   	 
     # !HMMO  RZZ	* !rzz(+ 3 3 	 	 	"  $     ~	 
 V   B	C 	D 	s C 3 
   "8l 82F4 F&1A F}    s   B< <CC