Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: site.py
"""Append module search paths for third-party packages to sys.path.
[0] Fix | Delete
[1] Fix | Delete
****************************************************************
[2] Fix | Delete
* This module is automatically imported during initialization. *
[3] Fix | Delete
****************************************************************
[4] Fix | Delete
[5] Fix | Delete
This will append site-specific paths to the module search path. On
[6] Fix | Delete
Unix (including Mac OSX), it starts with sys.prefix and
[7] Fix | Delete
sys.exec_prefix (if different) and appends
[8] Fix | Delete
lib/python<version>/site-packages.
[9] Fix | Delete
On other platforms (such as Windows), it tries each of the
[10] Fix | Delete
prefixes directly, as well as with lib/site-packages appended. The
[11] Fix | Delete
resulting directories, if they exist, are appended to sys.path, and
[12] Fix | Delete
also inspected for path configuration files.
[13] Fix | Delete
[14] Fix | Delete
If a file named "pyvenv.cfg" exists one directory above sys.executable,
[15] Fix | Delete
sys.prefix and sys.exec_prefix are set to that directory and
[16] Fix | Delete
it is also checked for site-packages (sys.base_prefix and
[17] Fix | Delete
sys.base_exec_prefix will always be the "real" prefixes of the Python
[18] Fix | Delete
installation). If "pyvenv.cfg" (a bootstrap configuration file) contains
[19] Fix | Delete
the key "include-system-site-packages" set to anything other than "false"
[20] Fix | Delete
(case-insensitive), the system-level prefixes will still also be
[21] Fix | Delete
searched for site-packages; otherwise they won't.
[22] Fix | Delete
[23] Fix | Delete
All of the resulting site-specific directories, if they exist, are
[24] Fix | Delete
appended to sys.path, and also inspected for path configuration
[25] Fix | Delete
files.
[26] Fix | Delete
[27] Fix | Delete
A path configuration file is a file whose name has the form
[28] Fix | Delete
<package>.pth; its contents are additional directories (one per line)
[29] Fix | Delete
to be added to sys.path. Non-existing directories (or
[30] Fix | Delete
non-directories) are never added to sys.path; no directory is added to
[31] Fix | Delete
sys.path more than once. Blank lines and lines beginning with
[32] Fix | Delete
'#' are skipped. Lines starting with 'import' are executed.
[33] Fix | Delete
[34] Fix | Delete
For example, suppose sys.prefix and sys.exec_prefix are set to
[35] Fix | Delete
/usr/local and there is a directory /usr/local/lib/python2.5/site-packages
[36] Fix | Delete
with three subdirectories, foo, bar and spam, and two path
[37] Fix | Delete
configuration files, foo.pth and bar.pth. Assume foo.pth contains the
[38] Fix | Delete
following:
[39] Fix | Delete
[40] Fix | Delete
# foo package configuration
[41] Fix | Delete
foo
[42] Fix | Delete
bar
[43] Fix | Delete
bletch
[44] Fix | Delete
[45] Fix | Delete
and bar.pth contains:
[46] Fix | Delete
[47] Fix | Delete
# bar package configuration
[48] Fix | Delete
bar
[49] Fix | Delete
[50] Fix | Delete
Then the following directories are added to sys.path, in this order:
[51] Fix | Delete
[52] Fix | Delete
/usr/local/lib/python2.5/site-packages/bar
[53] Fix | Delete
/usr/local/lib/python2.5/site-packages/foo
[54] Fix | Delete
[55] Fix | Delete
Note that bletch is omitted because it doesn't exist; bar precedes foo
[56] Fix | Delete
because bar.pth comes alphabetically before foo.pth; and spam is
[57] Fix | Delete
omitted because it is not mentioned in either path configuration file.
[58] Fix | Delete
[59] Fix | Delete
The readline module is also automatically configured to enable
[60] Fix | Delete
completion for systems that support it. This can be overridden in
[61] Fix | Delete
sitecustomize, usercustomize or PYTHONSTARTUP. Starting Python in
[62] Fix | Delete
isolated mode (-I) disables automatic readline configuration.
[63] Fix | Delete
[64] Fix | Delete
After these operations, an attempt is made to import a module
[65] Fix | Delete
named sitecustomize, which can perform arbitrary additional
[66] Fix | Delete
site-specific customizations. If this import fails with an
[67] Fix | Delete
ImportError exception, it is silently ignored.
[68] Fix | Delete
"""
[69] Fix | Delete
[70] Fix | Delete
import sys
[71] Fix | Delete
import os
[72] Fix | Delete
import builtins
[73] Fix | Delete
import _sitebuiltins
[74] Fix | Delete
[75] Fix | Delete
# Prefixes for site-packages; add additional prefixes like /usr/local here
[76] Fix | Delete
PREFIXES = [sys.prefix, sys.exec_prefix]
[77] Fix | Delete
# Enable per user site-packages directory
[78] Fix | Delete
# set it to False to disable the feature or True to force the feature
[79] Fix | Delete
ENABLE_USER_SITE = None
[80] Fix | Delete
[81] Fix | Delete
# for distutils.commands.install
[82] Fix | Delete
# These values are initialized by the getuserbase() and getusersitepackages()
[83] Fix | Delete
# functions, through the main() function when Python starts.
[84] Fix | Delete
USER_SITE = None
[85] Fix | Delete
USER_BASE = None
[86] Fix | Delete
[87] Fix | Delete
[88] Fix | Delete
def makepath(*paths):
[89] Fix | Delete
dir = os.path.join(*paths)
[90] Fix | Delete
try:
[91] Fix | Delete
dir = os.path.abspath(dir)
[92] Fix | Delete
except OSError:
[93] Fix | Delete
pass
[94] Fix | Delete
return dir, os.path.normcase(dir)
[95] Fix | Delete
[96] Fix | Delete
[97] Fix | Delete
def abs_paths():
[98] Fix | Delete
"""Set all module __file__ and __cached__ attributes to an absolute path"""
[99] Fix | Delete
for m in set(sys.modules.values()):
[100] Fix | Delete
if (getattr(getattr(m, '__loader__', None), '__module__', None) not in
[101] Fix | Delete
('_frozen_importlib', '_frozen_importlib_external')):
[102] Fix | Delete
continue # don't mess with a PEP 302-supplied __file__
[103] Fix | Delete
try:
[104] Fix | Delete
m.__file__ = os.path.abspath(m.__file__)
[105] Fix | Delete
except (AttributeError, OSError, TypeError):
[106] Fix | Delete
pass
[107] Fix | Delete
try:
[108] Fix | Delete
m.__cached__ = os.path.abspath(m.__cached__)
[109] Fix | Delete
except (AttributeError, OSError, TypeError):
[110] Fix | Delete
pass
[111] Fix | Delete
[112] Fix | Delete
[113] Fix | Delete
def removeduppaths():
[114] Fix | Delete
""" Remove duplicate entries from sys.path along with making them
[115] Fix | Delete
absolute"""
[116] Fix | Delete
# This ensures that the initial path provided by the interpreter contains
[117] Fix | Delete
# only absolute pathnames, even if we're running from the build directory.
[118] Fix | Delete
L = []
[119] Fix | Delete
known_paths = set()
[120] Fix | Delete
for dir in sys.path:
[121] Fix | Delete
# Filter out duplicate paths (on case-insensitive file systems also
[122] Fix | Delete
# if they only differ in case); turn relative paths into absolute
[123] Fix | Delete
# paths.
[124] Fix | Delete
dir, dircase = makepath(dir)
[125] Fix | Delete
if not dircase in known_paths:
[126] Fix | Delete
L.append(dir)
[127] Fix | Delete
known_paths.add(dircase)
[128] Fix | Delete
sys.path[:] = L
[129] Fix | Delete
return known_paths
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
def _init_pathinfo():
[133] Fix | Delete
"""Return a set containing all existing file system items from sys.path."""
[134] Fix | Delete
d = set()
[135] Fix | Delete
for item in sys.path:
[136] Fix | Delete
try:
[137] Fix | Delete
if os.path.exists(item):
[138] Fix | Delete
_, itemcase = makepath(item)
[139] Fix | Delete
d.add(itemcase)
[140] Fix | Delete
except TypeError:
[141] Fix | Delete
continue
[142] Fix | Delete
return d
[143] Fix | Delete
[144] Fix | Delete
[145] Fix | Delete
def addpackage(sitedir, name, known_paths):
[146] Fix | Delete
"""Process a .pth file within the site-packages directory:
[147] Fix | Delete
For each line in the file, either combine it with sitedir to a path
[148] Fix | Delete
and add that to known_paths, or execute it if it starts with 'import '.
[149] Fix | Delete
"""
[150] Fix | Delete
if known_paths is None:
[151] Fix | Delete
known_paths = _init_pathinfo()
[152] Fix | Delete
reset = True
[153] Fix | Delete
else:
[154] Fix | Delete
reset = False
[155] Fix | Delete
fullname = os.path.join(sitedir, name)
[156] Fix | Delete
try:
[157] Fix | Delete
f = open(fullname, "r")
[158] Fix | Delete
except OSError:
[159] Fix | Delete
return
[160] Fix | Delete
with f:
[161] Fix | Delete
for n, line in enumerate(f):
[162] Fix | Delete
if line.startswith("#"):
[163] Fix | Delete
continue
[164] Fix | Delete
try:
[165] Fix | Delete
if line.startswith(("import ", "import\t")):
[166] Fix | Delete
exec(line)
[167] Fix | Delete
continue
[168] Fix | Delete
line = line.rstrip()
[169] Fix | Delete
dir, dircase = makepath(sitedir, line)
[170] Fix | Delete
if not dircase in known_paths and os.path.exists(dir):
[171] Fix | Delete
sys.path.append(dir)
[172] Fix | Delete
known_paths.add(dircase)
[173] Fix | Delete
except Exception:
[174] Fix | Delete
print("Error processing line {:d} of {}:\n".format(n+1, fullname),
[175] Fix | Delete
file=sys.stderr)
[176] Fix | Delete
import traceback
[177] Fix | Delete
for record in traceback.format_exception(*sys.exc_info()):
[178] Fix | Delete
for line in record.splitlines():
[179] Fix | Delete
print(' '+line, file=sys.stderr)
[180] Fix | Delete
print("\nRemainder of file ignored", file=sys.stderr)
[181] Fix | Delete
break
[182] Fix | Delete
if reset:
[183] Fix | Delete
known_paths = None
[184] Fix | Delete
return known_paths
[185] Fix | Delete
[186] Fix | Delete
[187] Fix | Delete
def addsitedir(sitedir, known_paths=None):
[188] Fix | Delete
"""Add 'sitedir' argument to sys.path if missing and handle .pth files in
[189] Fix | Delete
'sitedir'"""
[190] Fix | Delete
if known_paths is None:
[191] Fix | Delete
known_paths = _init_pathinfo()
[192] Fix | Delete
reset = True
[193] Fix | Delete
else:
[194] Fix | Delete
reset = False
[195] Fix | Delete
sitedir, sitedircase = makepath(sitedir)
[196] Fix | Delete
if not sitedircase in known_paths:
[197] Fix | Delete
sys.path.append(sitedir) # Add path component
[198] Fix | Delete
known_paths.add(sitedircase)
[199] Fix | Delete
try:
[200] Fix | Delete
names = os.listdir(sitedir)
[201] Fix | Delete
except OSError:
[202] Fix | Delete
return
[203] Fix | Delete
names = [name for name in names if name.endswith(".pth")]
[204] Fix | Delete
for name in sorted(names):
[205] Fix | Delete
addpackage(sitedir, name, known_paths)
[206] Fix | Delete
if reset:
[207] Fix | Delete
known_paths = None
[208] Fix | Delete
return known_paths
[209] Fix | Delete
[210] Fix | Delete
[211] Fix | Delete
def check_enableusersite():
[212] Fix | Delete
"""Check if user site directory is safe for inclusion
[213] Fix | Delete
[214] Fix | Delete
The function tests for the command line flag (including environment var),
[215] Fix | Delete
process uid/gid equal to effective uid/gid.
[216] Fix | Delete
[217] Fix | Delete
None: Disabled for security reasons
[218] Fix | Delete
False: Disabled by user (command line option)
[219] Fix | Delete
True: Safe and enabled
[220] Fix | Delete
"""
[221] Fix | Delete
if sys.flags.no_user_site:
[222] Fix | Delete
return False
[223] Fix | Delete
[224] Fix | Delete
if hasattr(os, "getuid") and hasattr(os, "geteuid"):
[225] Fix | Delete
# check process uid == effective uid
[226] Fix | Delete
if os.geteuid() != os.getuid():
[227] Fix | Delete
return None
[228] Fix | Delete
if hasattr(os, "getgid") and hasattr(os, "getegid"):
[229] Fix | Delete
# check process gid == effective gid
[230] Fix | Delete
if os.getegid() != os.getgid():
[231] Fix | Delete
return None
[232] Fix | Delete
[233] Fix | Delete
return True
[234] Fix | Delete
[235] Fix | Delete
def getuserbase():
[236] Fix | Delete
"""Returns the `user base` directory path.
[237] Fix | Delete
[238] Fix | Delete
The `user base` directory can be used to store data. If the global
[239] Fix | Delete
variable ``USER_BASE`` is not initialized yet, this function will also set
[240] Fix | Delete
it.
[241] Fix | Delete
"""
[242] Fix | Delete
global USER_BASE
[243] Fix | Delete
if USER_BASE is not None:
[244] Fix | Delete
return USER_BASE
[245] Fix | Delete
from sysconfig import get_config_var
[246] Fix | Delete
USER_BASE = get_config_var('userbase')
[247] Fix | Delete
return USER_BASE
[248] Fix | Delete
[249] Fix | Delete
def getusersitepackages():
[250] Fix | Delete
"""Returns the user-specific site-packages directory path.
[251] Fix | Delete
[252] Fix | Delete
If the global variable ``USER_SITE`` is not initialized yet, this
[253] Fix | Delete
function will also set it.
[254] Fix | Delete
"""
[255] Fix | Delete
global USER_SITE
[256] Fix | Delete
user_base = getuserbase() # this will also set USER_BASE
[257] Fix | Delete
[258] Fix | Delete
if USER_SITE is not None:
[259] Fix | Delete
return USER_SITE
[260] Fix | Delete
[261] Fix | Delete
from sysconfig import get_path
[262] Fix | Delete
[263] Fix | Delete
if sys.platform == 'darwin':
[264] Fix | Delete
from sysconfig import get_config_var
[265] Fix | Delete
if get_config_var('PYTHONFRAMEWORK'):
[266] Fix | Delete
USER_SITE = get_path('purelib', 'osx_framework_user')
[267] Fix | Delete
return USER_SITE
[268] Fix | Delete
[269] Fix | Delete
USER_SITE = get_path('purelib', '%s_user' % os.name)
[270] Fix | Delete
return USER_SITE
[271] Fix | Delete
[272] Fix | Delete
def addusersitepackages(known_paths):
[273] Fix | Delete
"""Add a per user site-package to sys.path
[274] Fix | Delete
[275] Fix | Delete
Each user has its own python directory with site-packages in the
[276] Fix | Delete
home directory.
[277] Fix | Delete
"""
[278] Fix | Delete
# get the per user site-package path
[279] Fix | Delete
# this call will also make sure USER_BASE and USER_SITE are set
[280] Fix | Delete
user_site = getusersitepackages()
[281] Fix | Delete
[282] Fix | Delete
if ENABLE_USER_SITE and os.path.isdir(user_site):
[283] Fix | Delete
addsitedir(user_site, known_paths)
[284] Fix | Delete
return known_paths
[285] Fix | Delete
[286] Fix | Delete
def getsitepackages(prefixes=None):
[287] Fix | Delete
"""Returns a list containing all global site-packages directories.
[288] Fix | Delete
[289] Fix | Delete
For each directory present in ``prefixes`` (or the global ``PREFIXES``),
[290] Fix | Delete
this function will find its `site-packages` subdirectory depending on the
[291] Fix | Delete
system environment, and will return a list of full paths.
[292] Fix | Delete
"""
[293] Fix | Delete
sitepackages = []
[294] Fix | Delete
seen = set()
[295] Fix | Delete
[296] Fix | Delete
if prefixes is None:
[297] Fix | Delete
prefixes = PREFIXES
[298] Fix | Delete
[299] Fix | Delete
for prefix in prefixes:
[300] Fix | Delete
if not prefix or prefix in seen:
[301] Fix | Delete
continue
[302] Fix | Delete
seen.add(prefix)
[303] Fix | Delete
[304] Fix | Delete
if os.sep == '/':
[305] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib64",
[306] Fix | Delete
"python" + sys.version[:3],
[307] Fix | Delete
"site-packages"))
[308] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib",
[309] Fix | Delete
"python%d.%d" % sys.version_info[:2],
[310] Fix | Delete
"site-packages"))
[311] Fix | Delete
else:
[312] Fix | Delete
sitepackages.append(prefix)
[313] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib64", "site-packages"))
[314] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
[315] Fix | Delete
if sys.platform == "darwin":
[316] Fix | Delete
# for framework builds *only* we add the standard Apple
[317] Fix | Delete
# locations.
[318] Fix | Delete
from sysconfig import get_config_var
[319] Fix | Delete
framework = get_config_var("PYTHONFRAMEWORK")
[320] Fix | Delete
if framework:
[321] Fix | Delete
sitepackages.append(
[322] Fix | Delete
os.path.join("/Library", framework,
[323] Fix | Delete
'%d.%d' % sys.version_info[:2], "site-packages"))
[324] Fix | Delete
return sitepackages
[325] Fix | Delete
[326] Fix | Delete
def addsitepackages(known_paths, prefixes=None):
[327] Fix | Delete
"""Add site-packages to sys.path
[328] Fix | Delete
[329] Fix | Delete
'/usr/local' is included in PREFIXES if RPM build is not detected
[330] Fix | Delete
to make packages installed into this location visible.
[331] Fix | Delete
[332] Fix | Delete
"""
[333] Fix | Delete
if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
[334] Fix | Delete
PREFIXES.insert(0, "/usr/local")
[335] Fix | Delete
for sitedir in getsitepackages(prefixes):
[336] Fix | Delete
if os.path.isdir(sitedir):
[337] Fix | Delete
addsitedir(sitedir, known_paths)
[338] Fix | Delete
[339] Fix | Delete
return known_paths
[340] Fix | Delete
[341] Fix | Delete
def setquit():
[342] Fix | Delete
"""Define new builtins 'quit' and 'exit'.
[343] Fix | Delete
[344] Fix | Delete
These are objects which make the interpreter exit when called.
[345] Fix | Delete
The repr of each object contains a hint at how it works.
[346] Fix | Delete
[347] Fix | Delete
"""
[348] Fix | Delete
if os.sep == '\\':
[349] Fix | Delete
eof = 'Ctrl-Z plus Return'
[350] Fix | Delete
else:
[351] Fix | Delete
eof = 'Ctrl-D (i.e. EOF)'
[352] Fix | Delete
[353] Fix | Delete
builtins.quit = _sitebuiltins.Quitter('quit', eof)
[354] Fix | Delete
builtins.exit = _sitebuiltins.Quitter('exit', eof)
[355] Fix | Delete
[356] Fix | Delete
[357] Fix | Delete
def setcopyright():
[358] Fix | Delete
"""Set 'copyright' and 'credits' in builtins"""
[359] Fix | Delete
builtins.copyright = _sitebuiltins._Printer("copyright", sys.copyright)
[360] Fix | Delete
if sys.platform[:4] == 'java':
[361] Fix | Delete
builtins.credits = _sitebuiltins._Printer(
[362] Fix | Delete
"credits",
[363] Fix | Delete
"Jython is maintained by the Jython developers (www.jython.org).")
[364] Fix | Delete
else:
[365] Fix | Delete
builtins.credits = _sitebuiltins._Printer("credits", """\
[366] Fix | Delete
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
[367] Fix | Delete
for supporting Python development. See www.python.org for more information.""")
[368] Fix | Delete
files, dirs = [], []
[369] Fix | Delete
# Not all modules are required to have a __file__ attribute. See
[370] Fix | Delete
# PEP 420 for more details.
[371] Fix | Delete
if hasattr(os, '__file__'):
[372] Fix | Delete
here = os.path.dirname(os.__file__)
[373] Fix | Delete
files.extend(["LICENSE.txt", "LICENSE"])
[374] Fix | Delete
dirs.extend([os.path.join(here, os.pardir), here, os.curdir])
[375] Fix | Delete
builtins.license = _sitebuiltins._Printer(
[376] Fix | Delete
"license",
[377] Fix | Delete
"See https://www.python.org/psf/license/",
[378] Fix | Delete
files, dirs)
[379] Fix | Delete
[380] Fix | Delete
[381] Fix | Delete
def sethelper():
[382] Fix | Delete
builtins.help = _sitebuiltins._Helper()
[383] Fix | Delete
[384] Fix | Delete
def enablerlcompleter():
[385] Fix | Delete
"""Enable default readline configuration on interactive prompts, by
[386] Fix | Delete
registering a sys.__interactivehook__.
[387] Fix | Delete
[388] Fix | Delete
If the readline module can be imported, the hook will set the Tab key
[389] Fix | Delete
as completion key and register ~/.python_history as history file.
[390] Fix | Delete
This can be overridden in the sitecustomize or usercustomize module,
[391] Fix | Delete
or in a PYTHONSTARTUP file.
[392] Fix | Delete
"""
[393] Fix | Delete
def register_readline():
[394] Fix | Delete
import atexit
[395] Fix | Delete
try:
[396] Fix | Delete
import readline
[397] Fix | Delete
import rlcompleter
[398] Fix | Delete
except ImportError:
[399] Fix | Delete
return
[400] Fix | Delete
[401] Fix | Delete
# Reading the initialization (config) file may not be enough to set a
[402] Fix | Delete
# completion key, so we set one first and then read the file.
[403] Fix | Delete
readline_doc = getattr(readline, '__doc__', '')
[404] Fix | Delete
if readline_doc is not None and 'libedit' in readline_doc:
[405] Fix | Delete
readline.parse_and_bind('bind ^I rl_complete')
[406] Fix | Delete
else:
[407] Fix | Delete
readline.parse_and_bind('tab: complete')
[408] Fix | Delete
[409] Fix | Delete
try:
[410] Fix | Delete
readline.read_init_file()
[411] Fix | Delete
except OSError:
[412] Fix | Delete
# An OSError here could have many causes, but the most likely one
[413] Fix | Delete
# is that there's no .inputrc file (or .editrc file in the case of
[414] Fix | Delete
# Mac OS X + libedit) in the expected location. In that case, we
[415] Fix | Delete
# want to ignore the exception.
[416] Fix | Delete
pass
[417] Fix | Delete
[418] Fix | Delete
if readline.get_current_history_length() == 0:
[419] Fix | Delete
# If no history was loaded, default to .python_history.
[420] Fix | Delete
# The guard is necessary to avoid doubling history size at
[421] Fix | Delete
# each interpreter exit when readline was already configured
[422] Fix | Delete
# through a PYTHONSTARTUP hook, see:
[423] Fix | Delete
# http://bugs.python.org/issue5845#msg198636
[424] Fix | Delete
history = os.path.join(os.path.expanduser('~'),
[425] Fix | Delete
'.python_history')
[426] Fix | Delete
try:
[427] Fix | Delete
readline.read_history_file(history)
[428] Fix | Delete
except IOError:
[429] Fix | Delete
pass
[430] Fix | Delete
[431] Fix | Delete
def write_history():
[432] Fix | Delete
try:
[433] Fix | Delete
readline.write_history_file(history)
[434] Fix | Delete
except (FileNotFoundError, PermissionError):
[435] Fix | Delete
# home directory does not exist or is not writable
[436] Fix | Delete
# https://bugs.python.org/issue19891
[437] Fix | Delete
pass
[438] Fix | Delete
[439] Fix | Delete
atexit.register(write_history)
[440] Fix | Delete
[441] Fix | Delete
sys.__interactivehook__ = register_readline
[442] Fix | Delete
[443] Fix | Delete
def venv(known_paths):
[444] Fix | Delete
global PREFIXES, ENABLE_USER_SITE
[445] Fix | Delete
[446] Fix | Delete
env = os.environ
[447] Fix | Delete
if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in env:
[448] Fix | Delete
executable = os.environ['__PYVENV_LAUNCHER__']
[449] Fix | Delete
else:
[450] Fix | Delete
executable = sys.executable
[451] Fix | Delete
exe_dir, _ = os.path.split(os.path.abspath(executable))
[452] Fix | Delete
site_prefix = os.path.dirname(exe_dir)
[453] Fix | Delete
sys._home = None
[454] Fix | Delete
conf_basename = 'pyvenv.cfg'
[455] Fix | Delete
candidate_confs = [
[456] Fix | Delete
conffile for conffile in (
[457] Fix | Delete
os.path.join(exe_dir, conf_basename),
[458] Fix | Delete
os.path.join(site_prefix, conf_basename)
[459] Fix | Delete
)
[460] Fix | Delete
if os.path.isfile(conffile)
[461] Fix | Delete
]
[462] Fix | Delete
[463] Fix | Delete
if candidate_confs:
[464] Fix | Delete
virtual_conf = candidate_confs[0]
[465] Fix | Delete
system_site = "true"
[466] Fix | Delete
# Issue 25185: Use UTF-8, as that's what the venv module uses when
[467] Fix | Delete
# writing the file.
[468] Fix | Delete
with open(virtual_conf, encoding='utf-8') as f:
[469] Fix | Delete
for line in f:
[470] Fix | Delete
if '=' in line:
[471] Fix | Delete
key, _, value = line.partition('=')
[472] Fix | Delete
key = key.strip().lower()
[473] Fix | Delete
value = value.strip()
[474] Fix | Delete
if key == 'include-system-site-packages':
[475] Fix | Delete
system_site = value.lower()
[476] Fix | Delete
elif key == 'home':
[477] Fix | Delete
sys._home = value
[478] Fix | Delete
[479] Fix | Delete
sys.prefix = sys.exec_prefix = site_prefix
[480] Fix | Delete
[481] Fix | Delete
# Doing this here ensures venv takes precedence over user-site
[482] Fix | Delete
addsitepackages(known_paths, [sys.prefix])
[483] Fix | Delete
[484] Fix | Delete
# addsitepackages will process site_prefix again if its in PREFIXES,
[485] Fix | Delete
# but that's ok; known_paths will prevent anything being added twice
[486] Fix | Delete
if system_site == "true":
[487] Fix | Delete
PREFIXES.insert(0, sys.prefix)
[488] Fix | Delete
else:
[489] Fix | Delete
PREFIXES = [sys.prefix]
[490] Fix | Delete
ENABLE_USER_SITE = False
[491] Fix | Delete
[492] Fix | Delete
return known_paths
[493] Fix | Delete
[494] Fix | Delete
[495] Fix | Delete
def execsitecustomize():
[496] Fix | Delete
"""Run custom site specific code, if available."""
[497] Fix | Delete
try:
[498] Fix | Delete
try:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function