U kg@W@s&dZddlZddlZddlZddlZddlZejejgada da da ddZ ddZ ddZd d Zd d Zd2d dZddZddZddZddZddZddZd3ddZd4ddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Z d-d.Z!ej"j#s e!d/d0Z$e%d1kr"e$dS)5a Append module search paths for third-party packages to sys.path. **************************************************************** * This module is automatically imported during initialization. * **************************************************************** This will append site-specific paths to the module search path. On Unix (including Mac OSX), it starts with sys.prefix and sys.exec_prefix (if different) and appends lib/python3/dist-packages. On other platforms (such as Windows), it tries each of the prefixes directly, as well as with lib/site-packages appended. The resulting directories, if they exist, are appended to sys.path, and also inspected for path configuration files. For Debian and derivatives, this sys.path is augmented with directories for packages distributed within the distribution. Local addons go into /usr/local/lib/python/dist-packages, Debian addons install into /usr/lib/python3/dist-packages. /usr/lib/python/site-packages is not used. If a file named "pyvenv.cfg" exists one directory above sys.executable, sys.prefix and sys.exec_prefix are set to that directory and it is also checked for site-packages (sys.base_prefix and sys.base_exec_prefix will always be the "real" prefixes of the Python installation). If "pyvenv.cfg" (a bootstrap configuration file) contains the key "include-system-site-packages" set to anything other than "false" (case-insensitive), the system-level prefixes will still also be searched for site-packages; otherwise they won't. All of the resulting site-specific directories, if they exist, are appended to sys.path, and also inspected for path configuration files. A path configuration file is a file whose name has the form .pth; its contents are additional directories (one per line) to be added to sys.path. Non-existing directories (or non-directories) are never added to sys.path; no directory is added to sys.path more than once. Blank lines and lines beginning with '#' are skipped. Lines starting with 'import' are executed. For example, suppose sys.prefix and sys.exec_prefix are set to /usr/local and there is a directory /usr/local/lib/python2.5/site-packages with three subdirectories, foo, bar and spam, and two path configuration files, foo.pth and bar.pth. Assume foo.pth contains the following: # foo package configuration foo bar bletch and bar.pth contains: # bar package configuration bar Then the following directories are added to sys.path, in this order: /usr/local/lib/python2.5/site-packages/bar /usr/local/lib/python2.5/site-packages/foo Note that bletch is omitted because it doesn't exist; bar precedes foo because bar.pth comes alphabetically before foo.pth; and spam is omitted because it is not mentioned in either path configuration file. The readline module is also automatically configured to enable completion for systems that support it. This can be overridden in sitecustomize, usercustomize or PYTHONSTARTUP. Starting Python in isolated mode (-I) disables automatic readline configuration. After these operations, an attempt is made to import a module named sitecustomize, which can perform arbitrary additional site-specific customizations. If this import fails with an ImportError exception, it is silently ignored. NcGsBtjj|}ztj|}Wntk r0YnX|tj|fSN)ospathjoinabspathOSErrornormcase)pathsdirr /usr/lib/python3.8/site.pymakepathas  r c CsttjD]~}tt|dddddkr,qztj|j|_Wnt t t fk rZYnXztj|j |_ Wqt t t fk rYqXqdS)zESet all module __file__ and __cached__ attributes to an absolute path __loader__N __module__)_frozen_importlib_frozen_importlib_external) setsysmodulesvaluesgetattrrrr__file__AttributeErrorr TypeError __cached__)mr r r abs_pathsjsrcCsPg}t}tjD],}t|\}}||kr||||q|tjdd<|S)zK Remove duplicate entries from sys.path along with making them absoluteN)rrrr appendadd)L known_pathsr dircaser r r removeduppathszs    r"c CsVt}tjD]D}z&tj|r4t|\}}||Wq tk rNYq Yq Xq |S)zEReturn a set containing all existing file system items from sys.path.)rrrrexistsr rr)ditem_Zitemcaser r r _init_pathinfos    r'c Csr|dkrt}d}nd}tj||}ztt|}Wntk rPYdSX|t|D]\}}| drvqbzZ| drt |Wqb| }t ||\}} | |krtj |rtj||| Wqbtk rVtd|d|tjdd dl} | jtD](} | D]}td |tjdqqtd tjdYqZYqbXqbW5QRX|rnd}|S) zProcess a .pth file within the site-packages directory: For each line in the file, either combine it with sitedir to a path and add that to known_paths, or execute it if it starts with 'import '. NTF#)zimport zimport z"Error processing line {:d} of {}: )filerz z Remainder of file ignored)r'rrrio TextIOWrapper open_coder enumerate startswithexecrstripr r#rrr Exceptionprintformatstderr tracebackformat_exceptionexc_info splitlines) sitedirnamer resetfullnamefnliner r!r6recordr r r addpackagesF    rBcCs|dkrt}d}nd}t|\}}||krBtj|||zt|}Wntk rfYdSXdd|D}t |D]}t |||q~|rd}|S)zTAdd 'sitedir' argument to sys.path if missing and handle .pth files in 'sitedir'NTFcSsg|]}|dr|qS)z.pth)endswith).0r;r r r s zaddsitedir..) r'r rrrrrlistdirrsortedrB)r:r r<Z sitedircasenamesr;r r r addsitedirs$    rIcCs`tjjr dSttdr4ttdr4ttkr4dSttdr\ttdr\ttkr\dSdS)a,Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled FgetuidgeteuidNgetgidgetegidT) rflags no_user_sitehasattrrrKrJrMrLr r r r check_enableusersites rQcCsztjdd}|r|Sdd}tjdkrBtjdp6d}||dStjdkrptjrp|dd tjd tjdd S|dd S) NZPYTHONUSERBASEcWstjtjj|Sr)rr expanduserr)argsr r r joinusersz_getuserbase..joinuserntZAPPDATA~ZPythondarwinZLibraryz%d.%dz.local)renvirongetr;rplatform _framework version_info)Zenv_baserTbaser r r _getuserbases   r_cCsdtj}tjdkr,|d|d|ddStjdkrFtjrF|dS|d|dd |dd S) NrUz\Pythonrr)z\site-packagesrWz/lib/python/site-packagesz /lib/python.z/site-packages)rr]rr;r[r\)userbaseversionr r r _get_paths   rccCstdkrtatS)zReturns the `user base` directory path. The `user base` directory can be used to store data. If the global variable ``USER_BASE`` is not initialized yet, this function will also set it. N) USER_BASEr_r r r r getuserbasesrecCst}tdkrt|atS)zReturns the user-specific site-packages directory path. If the global variable ``USER_SITE`` is not initialized yet, this function will also set it. N)re USER_SITErc)rar r r getusersitepackages)srgcCs$t}tr tj|r t|||S)zAdd a per user site-package to sys.path Each user has its own python directory with site-packages in the home directory. )rgENABLE_USER_SITErrisdirrI)r user_siter r r addusersitepackages7s rkc Csg}t}|dkrt}|D]}|r||kr,q||tjdkrdtjksVtjtjkr|| tj |ddtj ddd| tj |ddtj ddd | tj |dd d | tj |ddtj ddd q| || tj |ddq|S) aReturns a list containing all global site-packages directories. For each directory present in ``prefixes`` (or the global ``PREFIXES``), this function will find its `site-packages` subdirectory depending on the system environment, and will return a list of full paths. N/Z VIRTUAL_ENVZlibZpythonz site-packagesz local/libz dist-packagesZpython3) rPREFIXESrrseprYr base_prefixprefixrrrrb)prefixesZ sitepackagesseenrqr r r getsitepackagesEs:    rtcCs(t|D]}tj|rt||q|S)zAdd site-packages to sys.path)rtrrrirI)r rrr:r r r addsitepackagesks   rucCs4tjdkrd}nd}td|t_td|t_dS)zDefine new builtins 'quit' and 'exit'. These are objects which make the interpreter exit when called. The repr of each object contains a hint at how it works. \zCtrl-Z plus ReturnzCtrl-D (i.e. EOF)quitexitN)rro _sitebuiltinsZQuitterbuiltinsrwrx)Zeofr r r setquitss  r{cCstdtjt_tjdddkr2tddt_ntddt_gg}}ttdrtj tj }| d d g| tj |tj|tjgtd d ||t_dS) z)Set 'copyright' and 'credits' in builtins copyrightNZjavacreditsz?Jython is maintained by the Jython developers (www.jython.org).z Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information.rz LICENSE.txtZLICENSElicensez'See https://www.python.org/psf/license/)ryZ_Printerrr|rzr[r~rPrrdirnamerextendrpardircurdirr)filesdirsherer r r setcopyrights$  rcCstt_dSr)ryZ_Helperrzhelpr r r r sethelpersrcCsdd}|t_dS)ajEnable default readline configuration on interactive prompts, by registering a sys.__interactivehook__. If the readline module can be imported, the hook will set the Tab key as completion key and register ~/.python_history as history file. This can be overridden in the sitecustomize or usercustomize module, or in a PYTHONSTARTUP file. csddl}zddlddl}Wntk r2YdSXtdd}|dk r\d|kr\dn dz Wntk rYnXdkrt j t j ddz Wntk rYnXfd d }||dS) Nr__doc__Zlibeditzbind ^I rl_completez tab: completerVz.python_historycs(zWntk r"YnXdSr)Zwrite_history_filerr Zhistoryreadliner r write_historyszCenablerlcompleter..register_readline..write_history)atexitr rlcompleter ImportErrorrZparse_and_bindZread_init_filerZget_current_history_lengthrrrrRZread_history_fileregister)rrZ readline_docrr rr register_readlines0      z,enablerlcompleter..register_readlineN)rZ__interactivehook__)rr r r enablerlcompleters 0rc CsHtj}tjdkr*d|kr*tjd}t_ntj}tjtj|\}}tj |}dt_ d}ddtj ||tj ||fD}|rD|d}d} t |dd \} | D]P} d | kr| d \} }} | } | } | d kr| } q| d kr| t_ qW5QRX|t_t_t|tjg| dkr8tdtjn tjgad a|S)NrWZ__PYVENV_LAUNCHER__z pyvenv.cfgcSsg|]}tj|r|qSr )rrisfile)rDZconffiler r r rEs zvenv..rZtruezutf-8)encoding=zinclude-system-site-packagesZhomeF)rrYrr[_base_executable executablersplitrrZ_homeropen partitionstriplowerrq exec_prefixrurninsertrh)r envrZexe_dirr&Z site_prefixZ conf_basenameZcandidate_confsZ virtual_confZ system_siter>r@keyvaluer r r venvsB       rc CszBz ddl}Wn0tk r>}z|jdkr,nW5d}~XYnXWnRtk r}z4tjjrltjtntj d|j j |fW5d}~XYnXdS)z,Run custom site specific code, if available.rN sitecustomizez@Error in sitecustomize; set PYTHONVERBOSE for traceback: %s: %s ) rrr;r2rrNverbose excepthookr8r5write __class____name__)rexcerrr r r execsitecustomize s   rc CszBz ddl}Wn0tk r>}z|jdkr,nW5d}~XYnXWnRtk r}z4tjjrltjtntj d|j j |fW5d}~XYnXdS)z,Run custom user specific code, if available.rN usercustomizez@Error in usercustomize; set PYTHONVERBOSE for traceback: %s: %s ) rrr;r2rrNrrr8r5rrr)rrrr r r execusercustomize!s   rcCs~tjdd}t}|tjkr$tt|}tdkr:tat|}t|}t t t tj j sjtttrztdS)zAdd standard site-specific directories to the module search path. This function is called automatically when this module is imported, unless the python interpreter was started with the -S flag. N)rrr"rrrhrQrkrur{rrrNisolatedrrr)Z orig_pathr r r r main5s" rcCs\d}tjdd}|st}t}tdtjD]}td|fq0tdtd|tj|rbdndftd |tj|rdndftd tt d g}d |kr| t d |kr| t |r(ttj |trt d n6tdkrt dn tdkrt dn t dn0d dl}t||tjd tj ft ddS)Na %s [--user-base] [--user-site] Without arguments print some useful information With arguments print the value of USER_BASE and/or USER_SITE separated by '%s'. Exit codes with --user-base or --user-site: 0 - user site directory is enabled 1 - user site directory is disabled by user 2 - uses site directory is disabled by super user or for security reasons >2 - unknown error r)z sys.path = [z %r,]zUSER_BASE: %r (%s)r#z doesn't existzUSER_SITE: %r (%s)zENABLE_USER_SITE: %rrz --user-basez --user-siteFrXrm )rargvrergr3rrrirhrxrrdrfpathseprtextwrapZdedent)rrSZ user_baserjr bufferrr r r _scriptWsD           r__main__)N)N)N)&rrrrzryr+rqrrnrhrfrdr rr"r'rBrIrQr_rcrergrkrtrur{rrrrrrrrNno_siterrr r r r sHM   *     & ;4 3