o
    Ưhk                     @   sH  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	 zd dl
Z
W n ey3   dZY nw dZe dZe d	Zd
edefddZd
edefddZddddededee dee	 deddfddZdedefddZd)dededefddZG dd  d ZG d!d" d"eZ	#d*d$edee	 d%ed&edef
d'd(ZdS )+    N)datetime)unified_diff)Path)OptionalTextIOTFz\+[^+]z-[^-]import_linereturnc                 C   sH   |   } | dr| dd} | dd} | S | dr"| dd} | S )Nfrom   import .import )strip
startswithreplace)r    r   I/var/www/Befach/backend/venv/lib/python3.10/site-packages/isort/format.pyformat_simplified   s   

r   c                 C   s\   |   } | ds,| ds,d| vrd|  S | d}|d}dd| d| S | S )Nr	   r   r   r   )r   r   splitpopjoin)r   partsendr   r   r   format_natural   s   


r   )outputcolor_output
file_inputfile_output	file_pathr   r   c           
   	   C   s   t ||}|du rdnt|}t|du rt nt| j}t| jdd|jdd|d |d |tt d}|D ]}	|	|	 q=dS )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liner   r   r   show_unified_diff+   s    



r2   c                 C   sN   d }|dvr%t d|  d}| }|dv rdS |dv r!td |dvsdS )	N)yesynonquitqzApply suggested changes to 'z' [y/n/q]? )r5   r6   F)r7   r8      T)inputlowersysexit)r   answerr   r   r   $ask_whether_to_apply_changes_to_fileL   s   
r?   
contentline_separatorc                 C   s    |  |d dd dd} | S )Nr
    )r   )rA   rB   r   r   r   remove_whitespaceX   s   rE   c                   @   sf   e Zd ZdZdZddededee fddZd	ed
dfddZ	d	ed
dfddZ
ded
dfddZdS )BasicPrinterERRORSUCCESSNerrorsuccessr   c                 C   s   |pt j| _|| _|| _d S N)r<   stdoutr   success_messageerror_messageselfrI   rJ   r   r   r   r   __init__a   s   
zBasicPrinter.__init__messager   c                 C   s    t | jj| j|d| jd d S )N)rJ   rR   file)printrM   formatrH   r   rP   rR   r   r   r   rJ   f       zBasicPrinter.successc                 C   s    t | jj| j|dtjd d S )N)rI   rR   rS   )rU   rN   rV   rG   r<   stderrrW   r   r   r   rI   i   rX   zBasicPrinter.errorr1   c                 C   s   | j | d S rK   )r   write)rP   r1   r   r   r   r,   l   s   zBasicPrinter.diff_linerK   )__name__
__module____qualname__rG   rH   r&   r   r   rQ   rJ   rI   r,   r   r   r   r   rF   ]   s    rF   c                       s`   e Zd Zdededee f fddZeddedee d	efd
dZded	dfddZ	  Z
S )ColoramaPrinterrI   rJ   r   c                    sN   t  j|||d | dtjj| _| dtjj| _tjj| _	tjj| _
d S )N)r   rG   rH   )superrQ   
style_textcoloramaForeREDrG   GREENrH   
ADDED_LINEREMOVED_LINErO   	__class__r   r   rQ   q   s
   
zColoramaPrinter.__init__Ntextstyler   c                 C   s    |d u r| S ||  t tjj S rK   )r&   ra   Style	RESET_ALL)ri   rj   r   r   r   r`   {   s   zColoramaPrinter.style_textr1   c                 C   sB   d }t t|r| j}n	t t|r| j}| j| || d S rK   )	rematchADDED_LINE_PATTERNre   REMOVED_LINE_PATTERNrf   r   rZ   r`   )rP   r1   rj   r   r   r   r,      s   zColoramaPrinter.diff_linerK   )r[   r\   r]   r&   r   r   rQ   staticmethodr`   r,   __classcell__r   r   rg   r   r^   p   s
    
r^   r
   colorrI   rJ   c                 C   sP   | rt rd}t|tjd td t stjd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]
rS   r9   F)r   )	colorama_unavailablerU   r<   rY   r=   ra   initr^   rF   )rs   r   rI   rJ   no_colorama_messager   r   r   r%      s   

r%   )r@   )Nr
   r
   )rm   r<   r   difflibr   pathlibr   typingr   r   ra   ImportErrorrt   compilero   rp   r&   r   r   boolr2   r?   rE   rF   r^   r%   r   r   r   r   <module>   s^    


!