[W@sdZddlZddlZddlZddlZejejgadada da ddZ ddZ ddZ d d Zd d Zdd dZddZddZddZddZdddZdddZddZddZdd Zd!d"Zd#d$Zd%Zd&d'Zd(d)Zd*d+Zd,d-Z ej!j"s{e nd.d/Z#e$d0kre#ndS)1a 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 as well as lib/site-python. 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 and site-python (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 overriden in sitecustomize, usercustomize or PYTHONSTARTUP. 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. Nc GsStjj|}ytjj|}Wntk r<YnX|tjj|fS)N)ospathjoinabspathOSErrornormcase)Zpathsdirr /usr/lib/python3.4/site.pymakepath_s  r cCsxttjjD]}tt|dddddkrFqnytjj|j|_Wnt t fk r|YnXytjj|j |_ Wqt t fk rYqXqWdS)zESet all module __file__ and __cached__ attributes to an absolute path __loader__N __module___frozen_importlib) setsysmodulesvaluesgetattrrrr__file__AttributeErrorr __cached__)mr r r abs_pathshs rcCsug}t}xLtjD]A}t|\}}||kr|j||j|qqW|tjdd<|S)zK Remove duplicate entries from sys.path along with making them absoluteN)rrrr appendadd)L known_pathsrdircaser r r removeduppathsxs   rc Csqt}xatjD]V}y8tjj|rPt|\}}|j|nWqtk rhwYqXqW|S)zDReturn a set containing all existing directory entries from sys.path)rrrrisdirr r TypeError)drrr r r _init_pathinfos   r"c Cs|dkrt}d}nd}tjj||}yt|d}Wntk rddSYnX|_xWt|D]I\}}|jdrqyny|jd rt|wyn|j }t ||\}} | |krtjj |rt jj ||j| nWqytk rtdj|d|d t jddl} xK| jt jD]4} x+| jD]}td |d t jqWqqWtd d t jPYqyXqyWWdQX|rd}n|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 '. Nrr#import import z"Error processing line {:d} of {}: filez z Remainder of file ignored)r&r')r"rrropenr enumerate startswithexecrstripr existsrrr Exceptionprintformatstderr tracebackformat_exceptionexc_info splitlines) sitedirnamerresetfullnamefnlinerrr3recordr r r addpackagesD           r?c Cs|dkrt}d}nd}t|\}}||krbtjj||j|nytj|}Wntk rdSYnXdd|D}x$t |D]}t |||qW|rd}n|S)zTAdd 'sitedir' argument to sys.path if missing and handle .pth files in 'sitedir'Nr#rcSs%g|]}|jdr|qS)z.pth)endswith).0r8r r r s zaddsitedir..) r"r rrrrrlistdirrsortedr?)r7rr9Z sitedircasenamesr8r r r addsitedirs$       rFcCstjjrdSttdrMttdrMtjtjkrMdSnttdrttdrtjtjkrdSndS)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_sitehasattrrrHrGrJrIr r r r check_enableusersites rNcCs0tdk rtSddlm}|datS)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. Nr)get_config_varZuserbase) USER_BASE sysconfigrO)rOr r r getuserbases   rRcCst}tdk rtSddlm}tjdkrjddlm}|drj|ddatSn|dd tjatS) zReturns the user-specific site-packages directory path. If the global variable ``USER_SITE`` is not initialized yet, this function will also set it. Nr)get_pathdarwin)rOPYTHONFRAMEWORKZpurelibZosx_framework_userz%s_user) rR USER_SITErQrSrplatformrOrr8) user_baserSrOr r r getusersitepackagess   rYcCst}tr1tjj|r1t||ntrx_dD]T}tjjt|dtj ddd}tjj|r>t||q>q>Wn|S)zAdd a per user site-package to sys.path Each user has its own python directory with site-packages in the home directory. lib local/libpythonNz dist-packages)rZr[) rYENABLE_USER_SITErrrrFrrPrversion)r user_siteZ dist_libdirr r r addusersitepackagess   rac Csg}t}|dkr$t}nx|D]}| s+||krJq+n|j|tjdkrgdtjkstjtjkr|j tj j |ddtj dddn|j tj j |ddtj ddd |j tj j |dd d |j tj j |ddtj ddd |j tj j |dd n,|j ||j tj j |ddtj d kr+d dlm}|d}|r|j tj j d|tj dddqq+q+W|S)a=Returns a list containing all global site-packages directories (and possibly site-python). 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_ENVrZr\r]z site-packagesz local/libz dist-packagesZpython3z dist-pythonrTr)rOrUz/Library)rPREFIXESrrsepenvironr base_prefixprefixrrrr_rWrQrO)prefixesZ sitepackagesseenrgrOZ frameworkr r r getsitepackages,sB     !    "  $rjcCshxat|D]S}tjj|r d|krPddl}|jdtnt||q q W|S)z8Add site-packages (and possibly site-python) to sys.pathz site-pythonrNz>"site-python" directories will not be supported in 3.5 anymore)rjrrrwarningswarnDeprecationWarningrF)rrhr7rkr r r addsitepackages]s    rncCsdtjdkrd}ntjdkr0d}nd}tjd|t_tjd|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. :zCmd-Q\zCtrl-Z plus ReturnzCtrl-D (i.e. EOF)quitexitN)rrd _sitebuiltinsZQuitterbuiltinsrqrr)Zeofr r r setquitjs  rucCstjdtjt_tjdddkrItjddt_ntjddt_gg}}ttdrtj j tj }|j d d g|j tj j |tj|tjgntjd 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/)rsZ_PrinterrrvrtrWrxrMrrdirnamerextendrpardircurdirry)Zfilesdirsherer r r setcopyright|s    .rcCstjt_dS)N)rsZ_Helperrthelpr r r r sethelpersrcCsdd}|t_dS)aiEnable 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 overriden in the sitecustomize or usercustomize module, or in a PYTHONSTARTUP file. cSsddl}yddl}ddl}Wntk r@dSYnXt|dd}|dk r{d|kr{|jdn |jdy|jWntk rYnX|jdkrt j j t j j dd}y|j |Wntk rYnX|j|j|ndS) Nr__doc__Zlibeditzbind ^I rl_completez tab: complete~z.python_history)atexitreadline rlcompleter ImportErrorrZparse_and_bindZread_init_filerZget_current_history_lengthrrr expanduserZread_history_fileIOErrorregisterZwrite_history_file)rrrZ readline_docZhistoryr r r register_readlines,        z,enablerlcompleter..register_readlineN)rZ__interactivehook__)rr r r enablerlcompleters 'rc Cstjdkrddl}ddl}|jd}|jdry|j|Wqtk rddl}|j |j |(\w|[-_])+)\s*=\s*(?P.*)\s*$c Cstj}tjdkr4d|kr4tjd}n tj}tjjtjj|\}}tjj|}dt_ d}ddtjj ||tjj ||fD}|rddl }|j t } |d} d} t| } x| D]} | j} | j| }|r|j}|dj|d }}|d kri|j} q|d kr|t_ qqqWWdQX|t_t_t|tjg| dkrtjdtjqtjgad an|S) NrTZ__PYVENV_LAUNCHER__z pyvenv.cfgcSs(g|]}tjj|r|qSr )rrisfile)rAZconffiler r r rBs zvenv..rZtruekeyvaluezinclude-system-site-packagesZhomeF)rrerrW executablersplitrrzZ_homerrecompile CONFIG_LINEr)stripmatch groupdictlowerrg exec_prefixrnrcinsertr^)renvrZexe_dir_Z site_prefixZ conf_basenameZcandidate_confsrZ config_lineZ virtual_confZ system_siter;r=rr!rrr r r venvsD  $            rcCsyddl}Wn~tk r$Ynmtk r}zMtjjdr^tjtjn tj j d|j j |fWYdd}~XnXdS)z,Run custom site specific code, if available.rN PYTHONVERBOSEz@Error in sitecustomize; set PYTHONVERBOSE for traceback: %s: %s ) sitecustomizerr/rregetr excepthookr5r2write __class____name__)rerrr r r execsitecustomizes  rcCsyddl}Wn~tk r$Ynmtk r}zMtjjdr^tjtjn tj j d|j j |fWYdd}~XnXdS)z,Run custom user specific code, if available.rNrz@Error in usercustomize; set PYTHONVERBOSE for traceback: %s: %s ) usercustomizerr/rrerrrr5r2rrr)rrr r r execusercustomizes  rcCstt}t|}tdkr4tant|}t|}ttt t t t trt ndS)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)rrrr^rNrarnrurrrrrr)rr r r main/s      rcCsd}tjdd}|st}t}tdx"tjD]}td|fqEWtdtd|tjj|rdndftd |tjj|rdndftd ttj d ng}d |kr|j t nd |kr|j t n|rttj j|trPtj d qtdkrltj dqtdkrtj dqtj dn@d dl}t|j|tjd tj ftj 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-siteFr] )rargvrRrYr0rrrr^rrrrPrVpathseprtextwrapZdedent)rargsrXr`rbufferrr r r _scriptLs@     # #     'r__main__)%rrrrtrsrgrrcr^rVrPr rrr"r?rFrNrRrYrarjrnrurrrrrrrrrrKno_siterrr r r r KsF       *    1    2  5      3