B °-_€Xã@sdZddlZddlZddlZddlZejejgadada da dd„Z dd„Z dd„Z d d „Zd d „Zd2d d„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd3dd„Zd4dd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Z ej!j"se ƒd/d0„Z#e$d1kre#ƒ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|Ž}ytj |¡}Wntk r0YnX|tj |¡fS)N)ÚosÚpathÚjoinÚabspathÚOSErrorÚnormcase)ÚpathsÚdir©r ú/usr/lib/python3.7/site.pyÚmakepath`s  r c Cs–xttj ¡ƒD]~}tt|ddƒddƒdkr.qytj |j¡|_Wnt t t fk r\YnXytj |j ¡|_ Wqt t t fk rŒYqXqWdS)zESet all module __file__ and __cached__ attributes to an absolute pathÚ __loader__NÚ __module__)Ú_frozen_importlibÚ_frozen_importlib_external) ÚsetÚsysÚmodulesÚvaluesÚgetattrrrrÚ__file__ÚAttributeErrorrÚ TypeErrorÚ __cached__)Úmr r r Ú abs_pathsisrcCsTg}tƒ}x6tjD],}t|ƒ\}}||kr| |¡| |¡qW|tjdd…<|S)zK Remove duplicate entries from sys.path along with making them absoluteN)rrrr ÚappendÚadd)ÚLÚ known_pathsr Údircaser r r Úremoveduppathsys   r!c CsXtƒ}xLtjD]B}y&tj |¡r6t|ƒ\}}| |¡Wqtk rNwYqXqW|S)zEReturn a set containing all existing file system items from sys.path.)rrrrÚexistsr rr)ÚdÚitemÚ_Zitemcaser r r Ú_init_pathinfoŒs    r&c Csp|dkrtƒ}d}nd}tj ||¡}yt|dƒ}Wntk rHdSX| xt|ƒD]ö\}}| d¡rrq^yX| d¡rˆt|ƒw^|  ¡}t ||ƒ\}} | |krÈtj  |¡rÈt j  |¡| | ¡Wq^tk rRtd |d|¡t jd d dl} x>| jt  ¡ŽD],} x$|  ¡D]}td |t jd qWqWtd t jd PYq^Xq^WWdQRX|rld}|S) zÖProcess 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Úrú#)zimport zimport z"Error processing line {:d} of {}: é)Úfilerz z Remainder of file ignored)r&rrrÚopenrÚ enumerateÚ startswithÚexecÚrstripr r"rrrÚ ExceptionÚprintÚformatÚstderrÚ tracebackÚformat_exceptionÚexc_infoÚ splitlines) ÚsitedirÚnamerÚresetÚfullnameÚfÚnÚliner r r4Úrecordr r r Ú addpackage™sD    r@cCsž|dkrtƒ}d}nd}t|ƒ\}}||krBtj |¡| |¡yt |¡}Wntk rddSXdd„|Dƒ}xt |ƒD]}t |||ƒq~W|ršd}|S)zTAdd 'sitedir' argument to sys.path if missing and handle .pth files in 'sitedir'NTFcSsg|]}| d¡r|‘qS)z.pth)Úendswith)Ú.0r9r r r ú Ószaddsitedir..) r&r rrrrrÚlistdirrÚsortedr@)r8rr:Z sitedircaseÚnamesr9r r r Ú addsitedirÃs$   rGcCs`tjjr dSttdƒr4ttdƒr4t ¡t ¡kr4dSttdƒr\ttdƒr\t ¡t ¡kr\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 FÚgetuidÚgeteuidNÚgetgidÚgetegidT) rÚflagsÚ no_user_siteÚhasattrrrIrHrKrJr r r r Úcheck_enableusersiteÛs rOcCsztj dd¡}|r|Sdd„}tjdkrBtj d¡p6d}||dƒStjdkrptjrp|dd tjd tjdd …ƒS|dd ƒS) NZPYTHONUSERBASEcWstj tjj|Ž¡S)N)rrÚ expanduserr)Úargsr r r Újoinusersz_getuserbase..joinuserÚntZAPPDATAú~ZPythonÚdarwinZLibraryz%d.%déz.local)rÚenvironÚgetr9rÚplatformÚ _frameworkÚ version_info)Zenv_baserRÚbaser r r Ú _getuserbaseûs   r]cCsdtj}tjdkr,|›d|d›|d›dStjdkrFtjrF|›dS|›d|d›d |d›d S) NrSz\Pythonrr)z\site-packagesrUz/lib/python/site-packagesz /lib/pythonÚ.z/site-packages)rr[rr9rYrZ)ÚuserbaseÚversionr r r Ú _get_paths   racCstdkrtƒatS)zËReturns 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 Ú getuserbasesrccCstƒ}tdkrt|ƒatS)z¢Returns the user-specific site-packages directory path. If the global variable ``USER_SITE`` is not initialized yet, this function will also set it. N)rcÚ USER_SITEra)r_r r r Úgetusersitepackages(srecCs$tƒ}tr tj |¡r t||ƒ|S)z†Add a per user site-package to sys.path Each user has its own python directory with site-packages in the home directory. )reÚENABLE_USER_SITErrÚisdirrG)rÚ user_siter r r Úaddusersitepackages6s ric Cs g}tƒ}|dkrt}xð|D]è}|r||kr.q| |¡tjdkrädtjksXtjtjkr~|  tj   |ddtj dd…d¡¡|  tj   |ddtj dd…d ¡¡|  tj   |dd d ¡¡|  tj   |ddtj dd…d ¡¡q|  |¡|  tj   |dd¡¡qW|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_ENVZlibZpythonéz site-packagesz local/libz dist-packagesZpython3) rÚPREFIXESrrÚseprWrÚ base_prefixÚprefixrrrr`)ÚprefixesZ sitepackagesÚseenror r r ÚgetsitepackagesDs2      rrcCs,x&t|ƒD]}tj |¡r t||ƒq W|S)zAdd site-packages to sys.path)rrrrrgrG)rrpr8r r r Úaddsitepackagesjs rscCs4tjdkrd}nd}t d|¡t_t d|¡t_dS)z­Define 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)ÚquitÚexitN)rrmÚ _sitebuiltinsZQuitterÚbuiltinsrurv)Zeofr r r Úsetquitrs  rycCs¤t dtj¡t_tjdd…dkr2t dd¡t_nt dd¡t_gg}}ttdƒrŽtj   tj ¡}|  d d g¡|  tj   |tj¡|tjg¡t d d ||¡t_dS) z)Set 'copyright' and 'credits' in builtinsÚ copyrightNéZjavaÚcreditsz?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.txtZLICENSEÚlicensez'See https://www.python.org/psf/license/)rwZ_PrinterrrzrxrYr|rNrrÚdirnamerÚextendrÚpardirÚcurdirr})ZfilesÚdirsÚherer r r Ú setcopyright‚s    r„cCst ¡t_dS)N)rwZ_HelperrxÚhelpr r r r Ú sethelperšsr†cCsdd„}|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. csèddl}yddl‰ddl}Wntk r0dSXtˆddƒ}|dk rZd|krZˆ d¡n ˆ d¡y ˆ ¡Wntk r„YnXˆ ¡dkrät j   t j   d¡d¡‰yˆ  ˆ¡Wntk rÊYnX‡‡fd d „}| |¡dS) NrÚ__doc__ÚZlibeditzbind ^I rl_completez tab: completerTz.python_historyc s,yˆ ˆ¡Wnttfk r&YnXdS)N)Zwrite_history_fileÚFileNotFoundErrorÚPermissionErrorr )ÚhistoryÚreadliner r Ú write_historyÌszCenablerlcompleter..register_readline..write_history)ÚatexitrŒÚ rlcompleterÚ ImportErrorrZparse_and_bindZread_init_filerZget_current_history_lengthrrrrPZread_history_fileÚregister)rŽrZ readline_docrr )r‹rŒr Úregister_readline¦s.      z,enablerlcompleter..register_readlineN)rZ__interactivehook__)r’r r r Úenablerlcompleters 0r“c Cs„tj}tjdkr*d|kr*tjd}t_n.Ztruezutf-8)Úencodingú=zinclude-system-site-packagesZhomeF)rrWrrYZ_base_executableÚ executableÚ_winapiZGetModuleFileNamerÚsplitrr~Z_homerr+Ú partitionÚstripÚlowerroÚ exec_prefixrsrlÚinsertrf)rÚenvr—r˜Zexe_dirr%Z site_prefixZ conf_basenameZcandidate_confsZ virtual_confZ system_siter<r>ÚkeyÚvaluer r r ÚvenvØsH          r¢c CsšyBy ddl}Wn0tk r>}z|jdkr,n‚Wdd}~XYnXWnRtk r”}z4tjjrltjt ¡Žntj   d|j j |f¡Wdd}~XYnXdS)z,Run custom site specific code, if available.rNÚ sitecustomizez@Error in sitecustomize; set PYTHONVERBOSE for traceback: %s: %s ) r£rr9r0rrLÚverboseÚ excepthookr6r3ÚwriteÚ __class__Ú__name__)r£ÚexcÚerrr r r Úexecsitecustomizes  r«c CsšyBy ddl}Wn0tk r>}z|jdkr,n‚Wdd}~XYnXWnRtk r”}z4tjjrltjt ¡Žntj   d|j j |f¡Wdd}~XYnXdS)z,Run custom user specific code, if available.rNÚ usercustomizez@Error in usercustomize; set PYTHONVERBOSE for traceback: %s: %s ) r¬rr9r0rrLr¤r¥r6r3r¦r§r¨)r¬r©rªr r r Úexecusercustomize's  r­cCs~tjdd…}tƒ}|tjkr$tƒt|ƒ}tdkr:tƒat|ƒ}t|ƒ}t ƒt ƒt ƒtj j sjtƒtƒtrztƒdS)zÏAdd 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!rr¢rfrOrirsryr„r†rLÚisolatedr“r«r­)Z orig_pathrr r r Úmain;s" r¯cCs`d}tjdd…}|s¦tƒ}tƒ}tdƒxtjD]}td|fƒq2Wtdƒtd|tj |¡rfdndfƒtd |tj |¡r†dndfƒtd tƒt  d ¡g}d |kr¼|  t ¡d |krÎ|  t ¡|r,ttj  |¡ƒtrôt  d ¡n6tdkr t  d¡n tdkr t  d¡n t  d¡n0d dl}t| |tjd tj f¡ƒt  d¡dS)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-siteFrVrké )rÚargvrcrer1rrrgrfrvrrbrdÚpathseprÚtextwrapZdedent)r…rQZ user_baserhr Úbufferr´r r r Ú_script]s@           r¶Ú__main__)N)N)N)%r‡rrrxrwrorrlrfrdrbr rr!r&r@rGrOr]rarcrerirrrsryr„r†r“r¢r«r­r¯rLÚno_siter¶r¨r r r r ÚLsF   *     & ;; 3