uBFjDZdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z ddl m Z mZddlmZmZmZddlZe rddlmZed d Zgd Zd d gZdZejjdejjZGddeZGddZ dZ!Gdde Z"GddZ#Gdde#e"Z$Gdde#e Z%d5dZ&dZ'd Z(d!Z)d"Z*ed#$d%Z+d6d&d&d'd(Z,dd)d*Z-dd)d+Z.d&dd,d-Z/d7d.Z0ej1d/krd0Z2d1Z3d2Z4d3Z5d4Z6dS)8z Environments are a way to activate different Python versions or Virtualenvs for static analysis. The Python binary in that environment is going to be executed. N) namedtuple)which) TYPE_CHECKINGAny)memoize_method time_cache)CompiledSubprocessInferenceStateSameProcessInferenceStateSubprocess)InferenceState VersionInfozmajor minor micro)z3.14z3.13z3.12z3.11z3.10z/usr/binz/usr/local/bin CONDA_PREFIX.ceZdZdZdS)InvalidPythonEnvironmentz If you see this exception, the Python executable or Virtualenv you have been trying to use is probably not a correct Python version. N)__name__ __module__ __qualname____doc__BC:\PYTHON\_runtimes\venv\Lib\site-packages\jedi/api/environment.pyrrsrrcPeZdZUeed<eed<edZedZdS)_BaseEnvironment version_info executablecb|jjd|jj}tj|S)Nrversion)rmajorminorparso load_grammar)selfversion_strings r get_grammarz_BaseEnvironment.get_grammar*s5$($5$;$;$;T=N=T=TU!.9999rcr |jS#t$r#t|j|_|jcYSwxYwN)_hashAttributeError_calculate_sha256_for_filerr$s r_sha256z_BaseEnvironment._sha256/sI :    3DODDDJ:    s  *66N) rrrr__annotations__rr&propertyr-rrrrr&s_OOO::^:XrrcXtjtjtjddfSN)sysrprefixrrrr _get_infor58s%   ! rcPeZdZdZdZd dZdZdZdddefd Z e d Z dS) Environmentz This class is supposed to be created by internal Jedi architecture. You should not create it directly. Please use create_environment or the other functions instead. It is then returned by that function. NcJ||_||_|dSr()_start_executable _env_vars_get_subprocess)r$renv_varss r__init__zEnvironment.__init__Hs)!+! rc|j|jjs|jS t|j|j|_|jdt }n,#t$r}td|jd|d}~wwxYw|d|_ |d|_ t|d|_ |jS)Nr<z&Could not get version information for : r) _subprocess is_crashedr r9r:_sendr5 Exceptionrrpath _VersionInfor)r$infoexcs rr;zEnvironment._get_subprocessNs   '0@0K '# # 1$2H;?> K K KD #))$ ::DD   *****C  q' G  )$q'2 sAA B'BBcdd|jD}d|jjd|d|jdS)Nrc34K|]}t|VdSr()str).0is r z'Environment.__repr__..ns(==a3q66======r)joinr __class__rrG)r$rs r__repr__zEnvironment.__repr__msI((==4+<=====#'>#:#:#:GGGTYYYOOrinference_stater returncFt||Sr()r r;r$rVs rget_inference_state_subprocessz*Environment.get_inference_state_subprocessqs (9M9M9O9OPPPrcN|S)z The sys path for this environment. Does not include potential modifications from e.g. appending to :data:`sys.path`. :returns: list of str )r; get_sys_pathr,s rr\zEnvironment.get_sys_pathws"##%%22444rr() rrrrrCr=r;rUr rZrr\rrrr7r7@s K    >PPPQ)Q "QQQQ  5 5^ 5 5 5rr7ceZdZdZdS)_SameEnvironmentMixinctjx|_|_tj|_t tjdd|_d|_dSr1)r3rr9r4rGrHrr:r,s rr=z_SameEnvironmentMixin.__init__s@36>AJ (#*:2A2*>?rN)rrrr=rrrr^r^s#rr^ceZdZdS)SameEnvironmentN)rrrrrrrarasDrrac$eZdZdddefdZdZdS)InterpreterEnvironmentrVr rWc t|Sr()r rYs rrZz5InterpreterEnvironment.get_inference_state_subprocesss)999rctjSr()r3rGr,s rr\z#InterpreterEnvironment.get_sys_paths xrN)rrrr rZr\rrrrcrcsI:): #:::: rrc VIRTUAL_ENVc>tj|}|r{tj|tjt jkrtS t|dS#t$rYdSwxYwdS)zGet virtualenv environment from VIRTUAL_ENV environment variable. It uses `safe=False` with ``create_environment``, because the environment variable is considered to be safe / controlled by the user solely. FsafeN) osenvirongetrGrealpathr3r4_try_get_same_envcreate_environmentr)env_varvars r_get_virtual_env_from_varrrs *.. ! !C  7  C BG$4$4SZ$@$@ @ @$&& & %c666 6'    DD   s;B BBctj}t|d5tfddD]}|| dddn #1swxYwY|S)NrbcBtjSr()readfilecmpBUFSIZE)fsrz,_calculate_sha256_for_file..s!&&"9"9rr)hashlibsha256openiterupdate hexdigest)rGr|blockrys @rr+r+s ^  F dD  !Q99993?? ! !E MM%  !!!!!!!!!!!!!!!!     s,AA"%A"crt}||Stt}||StS)a| Tries to return an active Virtualenv or conda environment. If there is no VIRTUAL_ENV variable or no CONDA_PREFIX variable set set it will return the latest Python version installed on the system. This makes it possible to use as many new Python features as possible when using autocompletion and other functionality. :returns: :class:`.Environment` )rr _CONDA_VARrn) virtual_env conda_envs rget_default_environmentrs@,--K)*55I   rc0t}tj|jdstjdkrd}n>dtj ddtj ddtj dzdf}|D]\}tj tj |}tj |rt|cS]tS|S) Npythonnt)zScripts\python.exe python.exez bin/pythonrrrAz bin/python%s)rarjrGbasenamerlower startswithnamer3rrrS exec_prefixisfiler7rc)envcheckscheckguesss rrnrns   C 7  CN + + 1 1 3 3 > >x H H ( 7d??;FF &)%5a%8%8%8#+a..I#"21"56F  * *EGLL%88Ew~~e$$ *"5))))) *&''' Jrctjdp#tjt}t }|rltj|tj|jkr'tt S|S)Nrf)rjrkrlr_get_cached_default_environmentrGrm clear_cache)rq environments rget_cached_default_environmentrs *.. ' ' E2:>>*+E+EC133K  1rw$$(8(89I(J(JJJ'33555.000 riX)secondsc\ tS#t$rtcYSwxYwr()rrrcrrrrrsB(&((( #((( &''''' (s ++T)riuse_environment_varsc#K|g}t}|rbt}||V||jtt}||V||j|D]}t j|s"t j|}t j|D]o}t j ||}||vr'|| t||}t|V`#t$rYlwxYwdS)a  :param paths: A list of paths in your file system to be scanned for Virtualenvs. It will search in these paths and potentially execute the Python binaries. :param safe: Default True. In case this is False, it will allow this function to execute potential `python` environments. An attacker might be able to drop an executable in a path this function is searching by default. If the executable has not been installed by root, it will not be executed. :param use_environment_vars: Default True. If True, the VIRTUAL_ENV variable will be checked if it contains a valid VirtualEnv. CONDA_PREFIX will be checked to see if it contains a valid conda environment. :yields: :class:`.Environment` Nrh) setrraddrGrrjisdirabspathlistdirrS_get_executable_pathr7r) pathsrir _used_pathsrr directoryrGrs rfind_virtualenvsrsm" }%%K ,011  "    OOK, - - --j99  OOO OOIN + + + w}}Y''  GOOI.. Jy))  D7<< 400D{"" OOD ! ! ! 1$TBBB !*------+      s "D00 D=<D=r?c#fKtD]&} t||V#t$rY#wxYwdS)a& Ignores virtualenvs and returns the Python versions that were installed on your system. This might return nothing, if you're running Python e.g. from a portable version. The environments are sorted from latest to oldest Python version. :yields: :class:`.Environment` r?N)_SUPPORTED_PYTHONSget_system_environmentr)r<r%s rfind_system_environmentsrHsb- ((KKK K K K K'    D s ! ..c2td|z}|r-|tjkrtSt |Stjdkr5t |D]%} t ||cS#t$rY"wxYwtd|z)z Return the first Python environment found for a string of the form 'X.Y' where X and Y are the major and minor versions of Python. :raises: :exc:`.InvalidPythonEnvironment` :returns: :class:`.Environment` rwin32r?z Cannot find executable python%s.)rr3rrar7platform&_get_executables_from_windows_registryr)rr<exes rrr[s 7" # #C  #. "$$ $3 |w9'BB  C "3::::::+     "#E#O P PPs$A77 BB)rir<ctj|r!t||t ||St t |||S)z Make it possible to manually create an Environment object by specifying a Virtualenv path or an executable path and optional environment variables. :raises: :exc:`.InvalidPythonEnvironment` :returns: :class:`.Environment` r?rh)rjrGr _assert_safer7r)rGrir<s rrorors^ w~~d4T4   4(3333 +Dt<<> TS_@`@`a7<<eX667KK 7>>& ! !  E ''@6'IJJJ Mrrc#Kddl}gd}|j|jfD]}|D]}||} |||5}||dd}t j|d}t j |r|Vdddn #1swxYwY#t$rYwxYwdS)Nr)z0SOFTWARE\Python\PythonCore\{version}\InstallPathz>#..&"%III &&&&&&&&&&&&&&& $D   s6C A B8, C8B< <C?B< C CCcJ|rt|stddSdS)Nz(The python binary is potentially unsafe.)_is_safer)executable_pathris rrrsB 8H_--8& 688 88888rctj|}t|rdSt D]+}|j|krdS|jt|krdS,dS)NTF)rjrGrm_is_unix_safe_simplerrr-r+)r real_pathrs rrrs  11II&&t 011    !Y . .44  ".s1@@q9''**@@@@@@rr)_is_unix_adminany _SAFE_PATHSrjstatst_uid)ruids` rrrsTA@@@@K@@@@@@ ')   #C !8OrcT tjdkS#t$rYdSwxYw)NrF)rjgetuidr*rrrrrs:y{{a uus  '')rfr()T)7rrjr3r{rw collectionsrshutilrtypingrr jedi.cacherr"jedi.inference.compiled.subprocessr r r r"jedi.inferencer rHrrrrr r!_CURRENT_VERSIONrFrrr5r7r^rarcrrr+rrnrrrrrrorrrrrrrrrrrs """"""%%%%%%%%111111118888888888 .------z-)<== ===+,  !.444c6F6L6LMy$D5D5D5D5D5"D5D5D5N     +[   24D**%%%P    G(((3D33333l*.&15QQQQQ.&*D Q Q Q Q Q&<7.888 8&r