o
    Ưh                      @   s   U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZ d	Ze
ed
f ed< G dd deZeddfde	dedee dedee f
ddZdS )zVFast stream based import identification.
Eventually this will likely replace parse.py
    )partial)Path)Iterator
NamedTupleOptionalTextIOTuple)normalize_line	skip_linestrip_syntax   )parse)DEFAULT_CONFIGConfig)zdef zcdef zcpdef zclass @z	async def.STATEMENT_DECLARATIONSc                   @   s~   e Zd ZU eed< eed< eed< dZee ed< dZ	ee ed< dZ
eed< dZee ed	< d
efddZd
efddZdS )Importline_numberindentedmoduleN	attributealiasFcimport	file_pathreturnc                 C   sZ   | j rdnd}| jrd| j d| d| j }n| d| j }| jr+|d| j 7 }|S )Nr   importfrom  z as )r   r   r   r   )self
import_cmdimport_string r!   K/var/www/Befach/backend/venv/lib/python3.10/site-packages/isort/identify.py	statement   s   zImport.statementc                 C   s.   | j pd d| j d| jrdnd |   S )N :r   z	indented )r   r   r   r#   )r   r!   r!   r"   __str__$   s   zImport.__str__)__name__
__module____qualname__int__annotations__boolstrr   r   r   r   r   r   r#   r&   r!   r!   r!   r"   r      s   
 
r   NFinput_streamconfigr   top_onlyr   c              
   c   s   d}t | }|D ]\}}t||||jd\}}|r%|s%|tr% dS |r(q	| dd }	|	dr|	dkra|	r@|	dkrazt|\}}
W n	 tyQ   Y nw |
 dd }	|	r@|	dks@|		drzt|\}}
W n	 tyw   Y nw |
 dd }	|		dsfq	|dd^}}d	d
 |dD }|r|d  d|d  |d< |D ]@}t
|\}}|drd}n	|drd}nqt|\}}|dddddd}d|v p|d}tt|d |d||d}d|ddd v r4|dd  	ds3zt|\}}
W n
 ty   Y nw t|
\}}|d| 7 }|dd  	drn| 	drzt|\}}
W n
 tyN   Y nw t|
\}}d|dd v rd|dd vr|d| 7 }|dd  	dszt|\}}
W n
 ty   Y nw t|
\}}|d| 7 }|dd  	dr|n$| 	ds| dr|d| 7 }n| dd |  }| 	ds<|dkr|dddddd}||rdnd}|d d}|rdnd|d d d|dd  g|dd  }dd
 t| D }|dd }d}d|v r|dd t|k rd|v rd}|d}|dkr||d  }|d }|d  | }||d  }|| || |d ||dd< ||kr|jr|||V  n:||||d!V  n1||d  }||d  }|| |d || ||kr|jr||V  n|||d!V  d|v s@|r|dkr|d}|D ]	}|||V  qq|D ]}||V  qqq	dS )"z9Parses a python file taking out and categorizing imports.r$   )in_quoteindexsection_comments#r   )raiseyieldr6   \r   c                 S   s   g | ]}|  qS r!   )strip).0liner!   r!   r"   
<listcomp>S   s    zimports.<locals>.<listcomp>;)zimport zcimport straightr   fromzimport(zimport (r   
z	 cimport r   )r   	)r   r   ())z importz cimportz import Nc                 S   s    g | ]}| d d ddqS )z{|z{ z|}z })replace)r9   itemr!   r!   r"   r;      s    as.)r   )	enumerater
   r3   
startswithr   r8   splitnextStopIterationendswithr	   parse_commentsrD   r   r   rstriplstripjoinr   r2   lenremoveremove_redundant_aliasespop)r.   r/   r   r0   r1   indexed_inputr2   raw_lineskipping_linestripped_line	next_liner:   end_of_line_comment
statementsr#   	_raw_linetype_of_importr    _normalized_import_stringcimportsidentified_importpartsfrom_importjust_importsdirect_importstop_level_moduler   as_indexr   r   r!   r!   r"   imports+   s"  







	(

*
"











ri   )__doc__	functoolsr   pathlibr   typingr   r   r   r   r   isort.parser	   r
   r   commentsr   rN   settingsr   r   r   r-   r+   r   r,   ri   r!   r!   r!   r"   <module>   s.    