a
    lcg*                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d	Zd
ZdZd-ddZdd Zdd Zdd Zdd Zdd Zd.ddZdd Zdd Zd/d d!Zd0d"d#Zd$d% Zd&d' Z d1d)d*Z!d2d+d,Z"dS )3    N)python_bytes_to_unicode)dbg)KnownContentFileIOFolderIO)SubModuleName)load_module_from_path)ParserTreeFilter)convert_names)z.toxz.venvz.mypy_cachevenv__pycache__i      c                 c   sF   | D ]<}||v rqt |ts"|V  |jdkrt| | E d H  qd S )Nmodule)
isinstancer   api_type_resolve_namesgoto)Zdefinition_namesZavoid_namesnamer   r   U/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/references.pyr      s    

r   c                 C   s   t dd | D S )Nc                 s   s&   | ]}|j d u r|n|j |fV  qd S N)	tree_name.0nr   r   r   	<genexpr>.   s   z _dictionarize.<locals>.<genexpr>)dict)namesr   r   r   _dictionarize-   s    r   c                 C   s   t | |}t|D ]&}|tt|g|   ddO }q|tt||jO }t|D ]>}|jdksV|j	d u sV|j	j
jdkr~qV|tt|j|jO }qVtt|S )NF)Z
only_stubsZprefer_stub_to_compiledparamtrailer)_find_nameslistsetr	   get_root_contextZis_stub_find_global_variablesvaluer   r   parenttype_add_names_in_same_contextparent_contextstring_namer   )module_contextr   found_namesr   r   r   r   _find_defining_names4   s    
r-   c                 C   s,   |  |}t| }|| tt|S r   )Zcreate_namer"   r   addr   )r+   r   r   r,   r   r   r   r    H   s    

r    c                 c   s\   | j d u rd S d }t| |d}t||}|s2qX|E d H  t|dd d}|d j}qd S )N)r)   until_positionc                 S   s   | j S r   )	start_pos)xr   r   r   <lambda>^       z,_add_names_in_same_context.<locals>.<lambda>)keyr   )	tree_noder   r"   getsortedr0   )contextr*   r/   filter_r   Zorderedr   r   r   r(   P   s    

r(   c              	   c   sz   | D ]p}|j d u rq| }z
|j}W n ty<   Y qY q0 | |D ](}|V  ||j }t||jE d H  qJqd S r   )r   r#   Zget_global_filterAttributeErrorr6   Zcreate_contextr(   r*   )r   search_namer   r+   methodZglobal_namecr   r   r   r$   b   s    


r$   Fc                    s  j }|j}zd|_t|}W d|_nd|_0 t| g}|stdd |D D ]2}|krT|jd urT|jj|	 j
v rT|| qT|stdd |D r|}nt|||}i }	|D ]j |g D ]}
tt|
}t fdd|D rN | |D ]D}|	|g D ]} | qz
|	|= W n tyF   Y n0 qq|D ]}|	|g | qRqq  }|rfdd|D S |S )	NFTc                 s   s   | ]}|  V  qd S r   r#   )r   dr   r   r   r      r3   z"find_references.<locals>.<genexpr>c                 s   s   | ]}|j d kV  qdS )r   N)r   r   r   r   r   r      r3   c                 3   s   | ]}| v V  qd S r   r   )r   r   )found_names_dctr   r   r      r3   c                    s   g | ]}|   kr|qS r   r>   r   )r+   r   r   
<listcomp>   r3   z#find_references.<locals>.<listcomp>)inference_stater%   Zflow_analysis_enabledr-   r   r"   r5   projectpath
py__file__parentsappendany#get_module_contexts_containing_nameZget_used_namesr6   r    updateKeyError
setdefaultvalues)r+   r   Zonly_in_moduleinfr;   r,   module_contextsmZpotential_modulesZnon_matching_reference_mapsZ	name_leafnewdctr   resultr   )r@   r+   r   find_referencesr   sP    

rT   c                 C   sf   z|  }W n ty    Y d S 0 t|dd}||s<d S t|j|}t| |}| r^d S | S )Nreplace)errors)	readFileNotFoundErrorr   searchr   rD   r   is_compiledZ
as_context)rB   file_ioregexcodeZnew_file_iorP   r   r   r   	_check_fs   s    

r^   c                 C   s   t  }t  }|  D ]r}|r|dr,q|dd}|dr|dd  }|tjjrh|d d }|	tj
| j| q|	| q||fS )N   #zutf-8ignore/   )r"   rW   
splitlines
startswithdecodeendswithosrD   sepr.   join)	folder_ior[   ignored_pathsignored_nameslpr   r   r   r   gitignored_lines   s    
rp   c           	      #   s   t   |  D ]\}}}|D ]F}|j}|jdv rD| vrDd |fV  |jdkrt||\}} |O  q fdd|D |d d < |D ]} | d fV  qqd S )N)z.pyz.pyiz
.gitignorec                    s&   g | ]}|j  vr| tvr|qS r   )rD   Zget_base_name_IGNORE_FOLDERS)r   rk   except_pathsr   r   rA      s   
z9recurse_find_python_folders_and_files.<locals>.<listcomp>)r"   walkrD   suffixr   rp   )	rk   rs   Zroot_folder_ioZ
folder_iosZfile_iosr[   rD   rl   rm   r   rr   r   %recurse_find_python_folders_and_files   s     




rv   c                 c   s&   t | |D ]\} }|d ur
|V  q
d S r   )rv   )rk   rs   r[   r   r   r   recurse_find_python_files   s    rw   c                 #   s   |   }t }dd |D }|D ]z}| j}|d u r8q | }|j t fdd|D r |v rfq t||D ]}|j|vrp|V  qp|  | }q@q d S )Nc                 S   s   g | ]}|  qS r   rE   r   rP   r   r   r   rA      r3   z2_find_python_files_in_sys_path.<locals>.<listcomp>c                 3   s   | ]}  |V  qd S r   )re   )r   ro   rD   r   r   r      r3   z1_find_python_files_in_sys_path.<locals>.<genexpr>)	Zget_sys_pathr"   	get_valuer[   Zget_parent_folderrD   rH   rw   r.   )rB   rO   sys_pathrs   Zyielded_pathsr+   r[   rk   r   rz   r   _find_python_files_in_sys_path   s     


r}   c                 c   s*   dd |D }t t| jj|E d H  d S )Nc                 S   s   g | ]}|  qS r   rx   ry   r   r   r   rA      r3   z)_find_project_modules.<locals>.<listcomp>)rw   r   rC   rD   )rB   rO   Zexcept_r   r   r   _find_project_modules   s    r~   rb   c                 c   sN   |D ]}|  rq|V  qt|dkr*dS t| |}t| |||dE dH  dS )z
    Search a name in the directories of modules.

    :param limit_reduction: Divides the limits on opening/parsing files by this
        factor.
       N)limit_reduction)rZ   lenr~   search_in_file_ios)rB   rO   r   r   r+   file_io_iteratorr   r   r   rI     s    	
rI   c                 c   s   t | }t| }d}d}tdt| |r0dnd }	|D ]Z}
|d7 }t| |
|	}|d ur|d7 }|V  ||krtd|  q||kr<td|  qq<d S )Nr   z\b rb   zHit limit of parsed files: %szHit limit of opened files: %s)_PARSED_FILE_LIMIT_OPENED_FILE_LIMITrecompileescaper^   r   )rB   r   r   r   ZcompleteZparse_limitZ
open_limitZfile_io_countZparsed_file_countr\   r[   rP   r   r   r   r     s"     

r   )r   )F)r   )r   )rb   )rb   F)#rh   r   Zparsor   Z
jedi.debugr   Zjedi.file_ior   r   Zjedi.inference.namesr   Zjedi.inference.importsr   Zjedi.inference.filtersr   Z!jedi.inference.gradual.conversionr	   rq   r   r   r   r   r-   r    r(   r$   rT   r^   rp   rv   rw   r}   r~   rI   r   r   r   r   r   <module>   s8   

6

 
 