
    f'                         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	 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efdZd Zd Z eg       d        Zd Zd ZdefdZdefdZd Zd Zy)    N)Path)all_suffixes)inference_state_method_cache)ContextualizedNode)	is_stringget_str_or_none)get_cached_code_lines)FileIO)settings)debug
   str_pathc                     t        |      }|j                         r|S | j                         }|y |j                  }|j	                  |      j                         S N)r   is_absolute
py__file__parentjoinpathabsolute)module_contextr   pathmodule_pathbase_dirs        R/var/www/cvtools/html/venv/lib/python3.12/site-packages/jedi/inference/sys_path.py	_abs_pathr      sZ    >D ++-K !!HT"++--    c              #     K   t        |j                  ddd   |j                  ddd         D ]  \  }}	 |dv sJ |j                  dv rt        |j                        dkD  sJ |j                  }|d   j                  dk(  r|d   j                  dk(  sJ |d   }|j                  d   d	k(  r|j                  d   j                  d
k(  sJ 	 t        | j                  |      |      }|j                         j                  |      D ]D  }|j                         D ]/  }t        |      st        | |j                               }	|	,|	 1 F ! y# t
        $ r Y /w xY ww)a  
    Extracts the assigned strings from an assignment that looks as follows::

        sys.path[0:0] = ['module/path', 'another/module/path']

    This function is in general pretty tolerant (and therefore 'buggy').
    However, it's not a big issue usually to add more paths to Jedi's sys_path,
    because it will only affect Jedi in very random situations and by adding
    more paths than necessary, it usually benefits the general user.
    N      )=z+=power	atom_exprr   namesys.r   )zipchildrentypelenvalueAssertionErrorr   create_contextinferiterater   r   get_safe_value)
r   	expr_stmtassigneeoperatorctrailercn
lazy_valuer+   abs_paths
             r   _paths_from_assignmentr9       s|     ")"4"4SqS"99;M;MadQRd;ST '(	{***==$::H%%&*+ +!!AQ499&1Q4::+>>>dG##A&#-'2B2B12E2K2Kv2UUU
   = =i H)T((*,,R0 	'J#))+ 'U#(9M9M9OPH+&	'	'1'(  		s6   4E"BEAE")E"E"	EE"EE"c              #     K   |j                   dk(  rK|j                  d   dk(  r9|j                   dk(  r*|j                  d   dk(  rt        |j                        dk(  sy|j                  d   j                  }|dvry|j                  d   }|d	k(  r&t        |j                        d
v r|j                  d   }| j	                  |      j                  |      D ]#  }t        |      }|t        | |      }| | % yw)zE extract the path from either "sys.path.append" or "sys.path.insert" r5   r   r&   (   Nr   )insertappendr=   )r<      r   )r)   r(   r*   r+   r-   
infer_noder   r   )r   trailer1trailer2r$   argr+   pr8   s           r   _paths_from_list_modificationsrE   K   s      MMY&8+<+<Q+?3+F*x/@/@/Cs/JH%%&!+Q%%D''


A
CxC-7ll1o..s3>>sC E"9^Q/Ns   C3C=6C=)defaultc           	         d }| j                   g S g }	 | j                   j                         d   } ||      D ]  \  }}|j                  }t        |j                        dk\  r)|j                  t        | g|j                  dd         S|V|j                  dk(  sf|j                  t        | |              |S # t        $ r Y |S w xY w)z6
    Detect sys.path modifications within module.
    c              3   d  K   | D ]  }|j                   j                   }||j                  dv s+|j                  }|d   j                  dk(  sJ|d   j                  dk(  s]|d   j                  dk(  sp|d   j                  d   }|j                  dk(  s|j                  dk(  s||f  y w)Nr!   r   r$   r%   r   r5   r   )r   r)   r(   r+   )namesr$   r"   r4   ns        r   get_sys_path_powersz9check_sys_path_modifications.<locals>.get_sys_path_powersi   s      	*DKK&&E UZZ3I%INNQ499&1Q4::+>aDII2!a(Avv'AGGv,="Ek)	*s-   B0B0B0B0"B05!B0B0'	B0r   r?   r   r1   )
	tree_nodeget_used_namesr   r*   r(   extendrE   r)   r9   KeyError)r   rK   addedpossible_namesr$   r"   r1   s          r   check_sys_path_modificationsrR   d   s    
	* '	EP'11@@B6J /~> 		PKD%I5>>"a'2&).!)<
 &9>>[+H3NINO		P L   Ls   B? ?	CCc                     t               }t        |      D ]8  }t        | |      D ]'  }|j                  |       t	        |      t
        k\  s' 8 : |S r   )set_get_buildout_script_paths_get_paths_from_buildout_scriptaddr*   _BUILDOUT_PATH_INSERTION_LIMIT)inference_statescript_pathbuildout_script_pathsbuildout_script_pathr   s        r   discover_buildout_pathsr]      s^    E :; G 3OEYZ 	D!%%d+()-KK	 ! r   c           
   #   X  K   t        t        |            }	 | j                  |dt        j                        }ddlm	}  || ||d t        | j                  |            j                         }t        |      E d {    y # t
        $ r t        j                  d|       Y y w xY w7 *w)NT)file_iocache
cache_pathz(Error trying to read buildout_script: %sr   )ModuleValue)r_   string_names
code_lines)r
   strparser   cache_directoryIOErrorr   warningjedi.inference.valuerb   r	   grammar
as_contextrR   )rY   r\   r_   module_noderb   r   s         r   rV   rV      s     S-./G%++// , 
 1 ()@)@BVW	
 jl  ,N;;;  @BVW <s4   B*"B AB*=B(>B*B%"B*$B%%B*r   c                     | j                   D ]&  }	 |j                  |      j                         r|c S ( y # t        $ r Y 5w xY wr   )parentsr   is_fileOSError)r   filenamer   s      r   _get_parent_dir_with_filers      sR    ,, 	x(002 3   		s    7	AAsearch_pathc              #     K   t        | d      }|sy|j                  d      }|j                         syt        j                  |      D ]R  }	 |j                  |      }t        |d      5 }|j                         }|j                  d      rd|v r| ddd       T y# 1 sw Y   xY w# t        t        f$ r(}t        j                  t        |             Y d}~d}~ww xY ww)z
    if there is a 'buildout.cfg' file in one of the parent directories of the
    given module it will return a list of all files in the buildout bin
    directory that look like python files.

    :param search_path: absolute path to the module.
    zbuildout.cfgNbinrz#!python)rs   r   existsoslistdiropenreadline
startswithUnicodeDecodeErrorrh   r   ri   re   )rt   project_rootbin_pathrr   filepathf	firstlinees           r   rU   rU      s      -[.IL$$U+H??JJx( 
	((2Hh$ #JJL	''-(i2G"N## # #G, 	 MM#a&!		sH   A
C%B+**BB+C%B(	$B++C":CC%C""C%c                     t               dgz   D ]/  }| j                  |k(  s| j                  | j                        }  | S  | S )Nz.pyi)r   suffix	with_namestem)r   r   s     r   remove_python_path_suffixr      sG    .F8+ ;;& >>$)),DK	 Kr   c                      t              j                  j                  d      ryj                  dk(  }|rj                   fd}t	         |             }|syt        |d       d   |fS )aK  
    Returns the dotted path inside a sys.path as a list of names. e.g.

    >>> transform_path_to_dotted([str(Path("/foo").absolute())], Path('/foo/bar/baz.py').absolute())
    (('bar', 'baz'), False)

    Returns (None, False) if the path doesn't really resolve to anything.
    The second return part is if it is a package.
    r&   )NF__init__c               3     K   D ]  } t              j                  |       st              t        |       d  }|j                  t        j                  j
                        s|j                  d      r|dd  }|sw|j                  t        j                  j
                        }t        |      s y t        d |D                y w)N/r   c              3   J   K   | ]  }t        j                  d d|        yw)z-stubs$ N)resub).0ss     r   	<genexpr>zMtransform_path_to_dotted.<locals>.iter_potential_solutions.<locals>.<genexpr>  s     Iaz2q 9Is   !#)	re   r~   r*   rz   r   sepsplitalltuple)rD   restr   r   sys_paths      r   iter_potential_solutionsz:transform_path_to_dotted.<locals>.iter_potential_solutions   s      	JA;**1-;'A0??277;;/4??33G8D JJrww{{3Eu:   I5III%	Js    C
AC
=AC
c                     t        |       S r   )r*   )rD   s    r   <lambda>z*transform_path_to_dotted.<locals>.<lambda>  s
    SV r   )keyr   )r   r$   r~   r   r   sorted)r   r   
is_packager   potential_solutionss   ``   r   transform_path_to_dottedr      s~     ,K8K""3' !!Z/J!((J*   8 :; %+;<Q?KKr   ) rz   r   pathlibr   importlib.machineryr   jedi.inference.cacher   jedi.inference.base_valuer   jedi.inference.helpersr   r   jedi.parser_utilsr	   jedi.file_ior
   jedir   r   rX   re   r   r9   rE   rR   r]   rV   rs   rU   r   r    r   r   <module>r      s    	 	  , = 8 = 3   !# . .('V2 b)" *"J	!<,D D :5Lr   