Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
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
In earlier versions of Python (up to 1.5a3), scripts or modules that
[6] Fix | Delete
needed to use site-specific modules would place ``import site''
[7] Fix | Delete
somewhere near the top of their code. Because of the automatic
[8] Fix | Delete
import, this is no longer necessary (but code that does it still
[9] Fix | Delete
works).
[10] Fix | Delete
[11] Fix | Delete
This will append site-specific paths to the module search path. On
[12] Fix | Delete
Unix (including Mac OSX), it starts with sys.prefix and
[13] Fix | Delete
sys.exec_prefix (if different) and appends
[14] Fix | Delete
lib/python<version>/site-packages as well as lib/site-python.
[15] Fix | Delete
On other platforms (such as Windows), it tries each of the
[16] Fix | Delete
prefixes directly, as well as with lib/site-packages appended. The
[17] Fix | Delete
resulting directories, if they exist, are appended to sys.path, and
[18] Fix | Delete
also inspected for path configuration files.
[19] Fix | Delete
[20] Fix | Delete
A path configuration file is a file whose name has the form
[21] Fix | Delete
<package>.pth; its contents are additional directories (one per line)
[22] Fix | Delete
to be added to sys.path. Non-existing directories (or
[23] Fix | Delete
non-directories) are never added to sys.path; no directory is added to
[24] Fix | Delete
sys.path more than once. Blank lines and lines beginning with
[25] Fix | Delete
'#' are skipped. Lines starting with 'import' are executed.
[26] Fix | Delete
[27] Fix | Delete
For example, suppose sys.prefix and sys.exec_prefix are set to
[28] Fix | Delete
/usr/local and there is a directory /usr/local/lib/python2.5/site-packages
[29] Fix | Delete
with three subdirectories, foo, bar and spam, and two path
[30] Fix | Delete
configuration files, foo.pth and bar.pth. Assume foo.pth contains the
[31] Fix | Delete
following:
[32] Fix | Delete
[33] Fix | Delete
# foo package configuration
[34] Fix | Delete
foo
[35] Fix | Delete
bar
[36] Fix | Delete
bletch
[37] Fix | Delete
[38] Fix | Delete
and bar.pth contains:
[39] Fix | Delete
[40] Fix | Delete
# bar package configuration
[41] Fix | Delete
bar
[42] Fix | Delete
[43] Fix | Delete
Then the following directories are added to sys.path, in this order:
[44] Fix | Delete
[45] Fix | Delete
/usr/local/lib/python2.5/site-packages/bar
[46] Fix | Delete
/usr/local/lib/python2.5/site-packages/foo
[47] Fix | Delete
[48] Fix | Delete
Note that bletch is omitted because it doesn't exist; bar precedes foo
[49] Fix | Delete
because bar.pth comes alphabetically before foo.pth; and spam is
[50] Fix | Delete
omitted because it is not mentioned in either path configuration file.
[51] Fix | Delete
[52] Fix | Delete
After these path manipulations, an attempt is made to import a module
[53] Fix | Delete
named sitecustomize, which can perform arbitrary additional
[54] Fix | Delete
site-specific customizations. If this import fails with an
[55] Fix | Delete
ImportError exception, it is silently ignored.
[56] Fix | Delete
[57] Fix | Delete
"""
[58] Fix | Delete
[59] Fix | Delete
import sys
[60] Fix | Delete
import os
[61] Fix | Delete
import __builtin__
[62] Fix | Delete
import traceback
[63] Fix | Delete
[64] Fix | Delete
# Prefixes for site-packages; add additional prefixes like /usr/local here
[65] Fix | Delete
PREFIXES = [sys.prefix, sys.exec_prefix]
[66] Fix | Delete
# Enable per user site-packages directory
[67] Fix | Delete
# set it to False to disable the feature or True to force the feature
[68] Fix | Delete
ENABLE_USER_SITE = None
[69] Fix | Delete
[70] Fix | Delete
# for distutils.commands.install
[71] Fix | Delete
# These values are initialized by the getuserbase() and getusersitepackages()
[72] Fix | Delete
# functions, through the main() function when Python starts.
[73] Fix | Delete
USER_SITE = None
[74] Fix | Delete
USER_BASE = None
[75] Fix | Delete
[76] Fix | Delete
[77] Fix | Delete
def makepath(*paths):
[78] Fix | Delete
dir = os.path.join(*paths)
[79] Fix | Delete
try:
[80] Fix | Delete
dir = os.path.abspath(dir)
[81] Fix | Delete
except OSError:
[82] Fix | Delete
pass
[83] Fix | Delete
return dir, os.path.normcase(dir)
[84] Fix | Delete
[85] Fix | Delete
[86] Fix | Delete
def abs__file__():
[87] Fix | Delete
"""Set all module' __file__ attribute to an absolute path"""
[88] Fix | Delete
for m in sys.modules.values():
[89] Fix | Delete
if hasattr(m, '__loader__'):
[90] Fix | Delete
continue # don't mess with a PEP 302-supplied __file__
[91] Fix | Delete
try:
[92] Fix | Delete
m.__file__ = os.path.abspath(m.__file__)
[93] Fix | Delete
except (AttributeError, OSError):
[94] Fix | Delete
pass
[95] Fix | Delete
[96] Fix | Delete
[97] Fix | Delete
def removeduppaths():
[98] Fix | Delete
""" Remove duplicate entries from sys.path along with making them
[99] Fix | Delete
absolute"""
[100] Fix | Delete
# This ensures that the initial path provided by the interpreter contains
[101] Fix | Delete
# only absolute pathnames, even if we're running from the build directory.
[102] Fix | Delete
L = []
[103] Fix | Delete
known_paths = set()
[104] Fix | Delete
for dir in sys.path:
[105] Fix | Delete
# Filter out duplicate paths (on case-insensitive file systems also
[106] Fix | Delete
# if they only differ in case); turn relative paths into absolute
[107] Fix | Delete
# paths.
[108] Fix | Delete
dir, dircase = makepath(dir)
[109] Fix | Delete
if not dircase in known_paths:
[110] Fix | Delete
L.append(dir)
[111] Fix | Delete
known_paths.add(dircase)
[112] Fix | Delete
sys.path[:] = L
[113] Fix | Delete
return known_paths
[114] Fix | Delete
[115] Fix | Delete
[116] Fix | Delete
def _init_pathinfo():
[117] Fix | Delete
"""Return a set containing all existing directory entries from sys.path"""
[118] Fix | Delete
d = set()
[119] Fix | Delete
for dir in sys.path:
[120] Fix | Delete
try:
[121] Fix | Delete
if os.path.isdir(dir):
[122] Fix | Delete
dir, dircase = makepath(dir)
[123] Fix | Delete
d.add(dircase)
[124] Fix | Delete
except TypeError:
[125] Fix | Delete
continue
[126] Fix | Delete
return d
[127] Fix | Delete
[128] Fix | Delete
[129] Fix | Delete
def addpackage(sitedir, name, known_paths):
[130] Fix | Delete
"""Process a .pth file within the site-packages directory:
[131] Fix | Delete
For each line in the file, either combine it with sitedir to a path
[132] Fix | Delete
and add that to known_paths, or execute it if it starts with 'import '.
[133] Fix | Delete
"""
[134] Fix | Delete
if known_paths is None:
[135] Fix | Delete
_init_pathinfo()
[136] Fix | Delete
reset = 1
[137] Fix | Delete
else:
[138] Fix | Delete
reset = 0
[139] Fix | Delete
fullname = os.path.join(sitedir, name)
[140] Fix | Delete
try:
[141] Fix | Delete
f = open(fullname, "rU")
[142] Fix | Delete
except IOError:
[143] Fix | Delete
return
[144] Fix | Delete
with f:
[145] Fix | Delete
for n, line in enumerate(f):
[146] Fix | Delete
if line.startswith("#"):
[147] Fix | Delete
continue
[148] Fix | Delete
try:
[149] Fix | Delete
if line.startswith(("import ", "import\t")):
[150] Fix | Delete
exec line
[151] Fix | Delete
continue
[152] Fix | Delete
line = line.rstrip()
[153] Fix | Delete
dir, dircase = makepath(sitedir, line)
[154] Fix | Delete
if not dircase in known_paths and os.path.exists(dir):
[155] Fix | Delete
sys.path.append(dir)
[156] Fix | Delete
known_paths.add(dircase)
[157] Fix | Delete
except Exception as err:
[158] Fix | Delete
print >>sys.stderr, "Error processing line {:d} of {}:\n".format(
[159] Fix | Delete
n+1, fullname)
[160] Fix | Delete
for record in traceback.format_exception(*sys.exc_info()):
[161] Fix | Delete
for line in record.splitlines():
[162] Fix | Delete
print >>sys.stderr, ' '+line
[163] Fix | Delete
print >>sys.stderr, "\nRemainder of file ignored"
[164] Fix | Delete
break
[165] Fix | Delete
if reset:
[166] Fix | Delete
known_paths = None
[167] Fix | Delete
return known_paths
[168] Fix | Delete
[169] Fix | Delete
[170] Fix | Delete
def addsitedir(sitedir, known_paths=None):
[171] Fix | Delete
"""Add 'sitedir' argument to sys.path if missing and handle .pth files in
[172] Fix | Delete
'sitedir'"""
[173] Fix | Delete
if known_paths is None:
[174] Fix | Delete
known_paths = _init_pathinfo()
[175] Fix | Delete
reset = 1
[176] Fix | Delete
else:
[177] Fix | Delete
reset = 0
[178] Fix | Delete
sitedir, sitedircase = makepath(sitedir)
[179] Fix | Delete
if not sitedircase in known_paths:
[180] Fix | Delete
sys.path.append(sitedir) # Add path component
[181] Fix | Delete
try:
[182] Fix | Delete
names = os.listdir(sitedir)
[183] Fix | Delete
except os.error:
[184] Fix | Delete
return
[185] Fix | Delete
dotpth = os.extsep + "pth"
[186] Fix | Delete
names = [name for name in names if name.endswith(dotpth)]
[187] Fix | Delete
for name in sorted(names):
[188] Fix | Delete
addpackage(sitedir, name, known_paths)
[189] Fix | Delete
if reset:
[190] Fix | Delete
known_paths = None
[191] Fix | Delete
return known_paths
[192] Fix | Delete
[193] Fix | Delete
[194] Fix | Delete
def check_enableusersite():
[195] Fix | Delete
"""Check if user site directory is safe for inclusion
[196] Fix | Delete
[197] Fix | Delete
The function tests for the command line flag (including environment var),
[198] Fix | Delete
process uid/gid equal to effective uid/gid.
[199] Fix | Delete
[200] Fix | Delete
None: Disabled for security reasons
[201] Fix | Delete
False: Disabled by user (command line option)
[202] Fix | Delete
True: Safe and enabled
[203] Fix | Delete
"""
[204] Fix | Delete
if sys.flags.no_user_site:
[205] Fix | Delete
return False
[206] Fix | Delete
[207] Fix | Delete
if hasattr(os, "getuid") and hasattr(os, "geteuid"):
[208] Fix | Delete
# check process uid == effective uid
[209] Fix | Delete
if os.geteuid() != os.getuid():
[210] Fix | Delete
return None
[211] Fix | Delete
if hasattr(os, "getgid") and hasattr(os, "getegid"):
[212] Fix | Delete
# check process gid == effective gid
[213] Fix | Delete
if os.getegid() != os.getgid():
[214] Fix | Delete
return None
[215] Fix | Delete
[216] Fix | Delete
return True
[217] Fix | Delete
[218] Fix | Delete
def getuserbase():
[219] Fix | Delete
"""Returns the `user base` directory path.
[220] Fix | Delete
[221] Fix | Delete
The `user base` directory can be used to store data. If the global
[222] Fix | Delete
variable ``USER_BASE`` is not initialized yet, this function will also set
[223] Fix | Delete
it.
[224] Fix | Delete
"""
[225] Fix | Delete
global USER_BASE
[226] Fix | Delete
if USER_BASE is not None:
[227] Fix | Delete
return USER_BASE
[228] Fix | Delete
from sysconfig import get_config_var
[229] Fix | Delete
USER_BASE = get_config_var('userbase')
[230] Fix | Delete
return USER_BASE
[231] Fix | Delete
[232] Fix | Delete
def getusersitepackages():
[233] Fix | Delete
"""Returns the user-specific site-packages directory path.
[234] Fix | Delete
[235] Fix | Delete
If the global variable ``USER_SITE`` is not initialized yet, this
[236] Fix | Delete
function will also set it.
[237] Fix | Delete
"""
[238] Fix | Delete
global USER_SITE
[239] Fix | Delete
user_base = getuserbase() # this will also set USER_BASE
[240] Fix | Delete
[241] Fix | Delete
if USER_SITE is not None:
[242] Fix | Delete
return USER_SITE
[243] Fix | Delete
[244] Fix | Delete
from sysconfig import get_path
[245] Fix | Delete
import os
[246] Fix | Delete
[247] Fix | Delete
if sys.platform == 'darwin':
[248] Fix | Delete
from sysconfig import get_config_var
[249] Fix | Delete
if get_config_var('PYTHONFRAMEWORK'):
[250] Fix | Delete
USER_SITE = get_path('purelib', 'osx_framework_user')
[251] Fix | Delete
return USER_SITE
[252] Fix | Delete
[253] Fix | Delete
USER_SITE = get_path('purelib', '%s_user' % os.name)
[254] Fix | Delete
return USER_SITE
[255] Fix | Delete
[256] Fix | Delete
def addusersitepackages(known_paths):
[257] Fix | Delete
"""Add a per user site-package to sys.path
[258] Fix | Delete
[259] Fix | Delete
Each user has its own python directory with site-packages in the
[260] Fix | Delete
home directory.
[261] Fix | Delete
"""
[262] Fix | Delete
# get the per user site-package path
[263] Fix | Delete
# this call will also make sure USER_BASE and USER_SITE are set
[264] Fix | Delete
user_site = getusersitepackages()
[265] Fix | Delete
[266] Fix | Delete
if ENABLE_USER_SITE and os.path.isdir(user_site):
[267] Fix | Delete
addsitedir(user_site, known_paths)
[268] Fix | Delete
return known_paths
[269] Fix | Delete
[270] Fix | Delete
def getsitepackages():
[271] Fix | Delete
"""Returns a list containing all global site-packages directories
[272] Fix | Delete
(and possibly site-python).
[273] Fix | Delete
[274] Fix | Delete
For each directory present in the global ``PREFIXES``, this function
[275] Fix | Delete
will find its `site-packages` subdirectory depending on the system
[276] Fix | Delete
environment, and will return a list of full paths.
[277] Fix | Delete
"""
[278] Fix | Delete
sitepackages = []
[279] Fix | Delete
seen = set()
[280] Fix | Delete
[281] Fix | Delete
for prefix in PREFIXES:
[282] Fix | Delete
if not prefix or prefix in seen:
[283] Fix | Delete
continue
[284] Fix | Delete
seen.add(prefix)
[285] Fix | Delete
[286] Fix | Delete
if sys.platform in ('os2emx', 'riscos'):
[287] Fix | Delete
sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
[288] Fix | Delete
elif os.sep == '/':
[289] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib64",
[290] Fix | Delete
"python" + sys.version[:3],
[291] Fix | Delete
"site-packages"))
[292] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib",
[293] Fix | Delete
"python" + sys.version[:3],
[294] Fix | Delete
"site-packages"))
[295] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib", "site-python"))
[296] Fix | Delete
else:
[297] Fix | Delete
sitepackages.append(prefix)
[298] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib64", "site-packages"))
[299] Fix | Delete
sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
[300] Fix | Delete
return sitepackages
[301] Fix | Delete
[302] Fix | Delete
def addsitepackages(known_paths):
[303] Fix | Delete
"""Add site-packages (and possibly site-python) to sys.path"""
[304] Fix | Delete
for sitedir in getsitepackages():
[305] Fix | Delete
if os.path.isdir(sitedir):
[306] Fix | Delete
addsitedir(sitedir, known_paths)
[307] Fix | Delete
[308] Fix | Delete
return known_paths
[309] Fix | Delete
[310] Fix | Delete
def setBEGINLIBPATH():
[311] Fix | Delete
"""The OS/2 EMX port has optional extension modules that do double duty
[312] Fix | Delete
as DLLs (and must use the .DLL file extension) for other extensions.
[313] Fix | Delete
The library search path needs to be amended so these will be found
[314] Fix | Delete
during module import. Use BEGINLIBPATH so that these are at the start
[315] Fix | Delete
of the library search path.
[316] Fix | Delete
[317] Fix | Delete
"""
[318] Fix | Delete
dllpath = os.path.join(sys.prefix, "Lib", "lib-dynload")
[319] Fix | Delete
libpath = os.environ['BEGINLIBPATH'].split(';')
[320] Fix | Delete
if libpath[-1]:
[321] Fix | Delete
libpath.append(dllpath)
[322] Fix | Delete
else:
[323] Fix | Delete
libpath[-1] = dllpath
[324] Fix | Delete
os.environ['BEGINLIBPATH'] = ';'.join(libpath)
[325] Fix | Delete
[326] Fix | Delete
[327] Fix | Delete
def setquit():
[328] Fix | Delete
"""Define new builtins 'quit' and 'exit'.
[329] Fix | Delete
[330] Fix | Delete
These are objects which make the interpreter exit when called.
[331] Fix | Delete
The repr of each object contains a hint at how it works.
[332] Fix | Delete
[333] Fix | Delete
"""
[334] Fix | Delete
if os.sep == ':':
[335] Fix | Delete
eof = 'Cmd-Q'
[336] Fix | Delete
elif os.sep == '\\':
[337] Fix | Delete
eof = 'Ctrl-Z plus Return'
[338] Fix | Delete
else:
[339] Fix | Delete
eof = 'Ctrl-D (i.e. EOF)'
[340] Fix | Delete
[341] Fix | Delete
class Quitter(object):
[342] Fix | Delete
def __init__(self, name):
[343] Fix | Delete
self.name = name
[344] Fix | Delete
def __repr__(self):
[345] Fix | Delete
return 'Use %s() or %s to exit' % (self.name, eof)
[346] Fix | Delete
def __call__(self, code=None):
[347] Fix | Delete
# Shells like IDLE catch the SystemExit, but listen when their
[348] Fix | Delete
# stdin wrapper is closed.
[349] Fix | Delete
try:
[350] Fix | Delete
sys.stdin.close()
[351] Fix | Delete
except:
[352] Fix | Delete
pass
[353] Fix | Delete
raise SystemExit(code)
[354] Fix | Delete
__builtin__.quit = Quitter('quit')
[355] Fix | Delete
__builtin__.exit = Quitter('exit')
[356] Fix | Delete
[357] Fix | Delete
[358] Fix | Delete
class _Printer(object):
[359] Fix | Delete
"""interactive prompt objects for printing the license text, a list of
[360] Fix | Delete
contributors and the copyright notice."""
[361] Fix | Delete
[362] Fix | Delete
MAXLINES = 23
[363] Fix | Delete
[364] Fix | Delete
def __init__(self, name, data, files=(), dirs=()):
[365] Fix | Delete
self.__name = name
[366] Fix | Delete
self.__data = data
[367] Fix | Delete
self.__files = files
[368] Fix | Delete
self.__dirs = dirs
[369] Fix | Delete
self.__lines = None
[370] Fix | Delete
[371] Fix | Delete
def __setup(self):
[372] Fix | Delete
if self.__lines:
[373] Fix | Delete
return
[374] Fix | Delete
data = None
[375] Fix | Delete
for dir in self.__dirs:
[376] Fix | Delete
for filename in self.__files:
[377] Fix | Delete
filename = os.path.join(dir, filename)
[378] Fix | Delete
try:
[379] Fix | Delete
fp = file(filename, "rU")
[380] Fix | Delete
data = fp.read()
[381] Fix | Delete
fp.close()
[382] Fix | Delete
break
[383] Fix | Delete
except IOError:
[384] Fix | Delete
pass
[385] Fix | Delete
if data:
[386] Fix | Delete
break
[387] Fix | Delete
if not data:
[388] Fix | Delete
data = self.__data
[389] Fix | Delete
self.__lines = data.split('\n')
[390] Fix | Delete
self.__linecnt = len(self.__lines)
[391] Fix | Delete
[392] Fix | Delete
def __repr__(self):
[393] Fix | Delete
self.__setup()
[394] Fix | Delete
if len(self.__lines) <= self.MAXLINES:
[395] Fix | Delete
return "\n".join(self.__lines)
[396] Fix | Delete
else:
[397] Fix | Delete
return "Type %s() to see the full %s text" % ((self.__name,)*2)
[398] Fix | Delete
[399] Fix | Delete
def __call__(self):
[400] Fix | Delete
self.__setup()
[401] Fix | Delete
prompt = 'Hit Return for more, or q (and Return) to quit: '
[402] Fix | Delete
lineno = 0
[403] Fix | Delete
while 1:
[404] Fix | Delete
try:
[405] Fix | Delete
for i in range(lineno, lineno + self.MAXLINES):
[406] Fix | Delete
print self.__lines[i]
[407] Fix | Delete
except IndexError:
[408] Fix | Delete
break
[409] Fix | Delete
else:
[410] Fix | Delete
lineno += self.MAXLINES
[411] Fix | Delete
key = None
[412] Fix | Delete
while key is None:
[413] Fix | Delete
key = raw_input(prompt)
[414] Fix | Delete
if key not in ('', 'q'):
[415] Fix | Delete
key = None
[416] Fix | Delete
if key == 'q':
[417] Fix | Delete
break
[418] Fix | Delete
[419] Fix | Delete
def setcopyright():
[420] Fix | Delete
"""Set 'copyright' and 'credits' in __builtin__"""
[421] Fix | Delete
__builtin__.copyright = _Printer("copyright", sys.copyright)
[422] Fix | Delete
if sys.platform[:4] == 'java':
[423] Fix | Delete
__builtin__.credits = _Printer(
[424] Fix | Delete
"credits",
[425] Fix | Delete
"Jython is maintained by the Jython developers (www.jython.org).")
[426] Fix | Delete
else:
[427] Fix | Delete
__builtin__.credits = _Printer("credits", """\
[428] Fix | Delete
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
[429] Fix | Delete
for supporting Python development. See www.python.org for more information.""")
[430] Fix | Delete
here = os.path.dirname(os.__file__)
[431] Fix | Delete
__builtin__.license = _Printer(
[432] Fix | Delete
"license", "See https://www.python.org/psf/license/",
[433] Fix | Delete
["LICENSE.txt", "LICENSE"],
[434] Fix | Delete
[os.path.join(here, os.pardir), here, os.curdir])
[435] Fix | Delete
[436] Fix | Delete
[437] Fix | Delete
class _Helper(object):
[438] Fix | Delete
"""Define the builtin 'help'.
[439] Fix | Delete
This is a wrapper around pydoc.help (with a twist).
[440] Fix | Delete
[441] Fix | Delete
"""
[442] Fix | Delete
[443] Fix | Delete
def __repr__(self):
[444] Fix | Delete
return "Type help() for interactive help, " \
[445] Fix | Delete
"or help(object) for help about object."
[446] Fix | Delete
def __call__(self, *args, **kwds):
[447] Fix | Delete
import pydoc
[448] Fix | Delete
return pydoc.help(*args, **kwds)
[449] Fix | Delete
[450] Fix | Delete
def sethelper():
[451] Fix | Delete
__builtin__.help = _Helper()
[452] Fix | Delete
[453] Fix | Delete
def aliasmbcs():
[454] Fix | Delete
"""On Windows, some default encodings are not provided by Python,
[455] Fix | Delete
while they are always available as "mbcs" in each locale. Make
[456] Fix | Delete
them usable by aliasing to "mbcs" in such a case."""
[457] Fix | Delete
if sys.platform == 'win32':
[458] Fix | Delete
import locale, codecs
[459] Fix | Delete
enc = locale.getdefaultlocale()[1]
[460] Fix | Delete
if enc.startswith('cp'): # "cp***" ?
[461] Fix | Delete
try:
[462] Fix | Delete
codecs.lookup(enc)
[463] Fix | Delete
except LookupError:
[464] Fix | Delete
import encodings
[465] Fix | Delete
encodings._cache[enc] = encodings._unknown
[466] Fix | Delete
encodings.aliases.aliases[enc] = 'mbcs'
[467] Fix | Delete
[468] Fix | Delete
def setencoding():
[469] Fix | Delete
"""Set the string encoding used by the Unicode implementation. The
[470] Fix | Delete
default is 'ascii', but if you're willing to experiment, you can
[471] Fix | Delete
change this."""
[472] Fix | Delete
encoding = "ascii" # Default value set by _PyUnicode_Init()
[473] Fix | Delete
if 0:
[474] Fix | Delete
# Enable to support locale aware default string encodings.
[475] Fix | Delete
import locale
[476] Fix | Delete
loc = locale.getdefaultlocale()
[477] Fix | Delete
if loc[1]:
[478] Fix | Delete
encoding = loc[1]
[479] Fix | Delete
if 0:
[480] Fix | Delete
# Enable to switch off string to Unicode coercion and implicit
[481] Fix | Delete
# Unicode to string conversion.
[482] Fix | Delete
encoding = "undefined"
[483] Fix | Delete
if encoding != "ascii":
[484] Fix | Delete
# On Non-Unicode builds this will raise an AttributeError...
[485] Fix | Delete
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
[486] Fix | Delete
[487] Fix | Delete
[488] Fix | Delete
def execsitecustomize():
[489] Fix | Delete
"""Run custom site specific code, if available."""
[490] Fix | Delete
try:
[491] Fix | Delete
import sitecustomize
[492] Fix | Delete
except ImportError:
[493] Fix | Delete
pass
[494] Fix | Delete
except Exception:
[495] Fix | Delete
if sys.flags.verbose:
[496] Fix | Delete
sys.excepthook(*sys.exc_info())
[497] Fix | Delete
else:
[498] Fix | Delete
print >>sys.stderr, \
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function