Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: pkgutil.py
"""Utilities to support packages."""
[0] Fix | Delete
[1] Fix | Delete
import os
[2] Fix | Delete
import sys
[3] Fix | Delete
import imp
[4] Fix | Delete
import os.path
[5] Fix | Delete
from types import ModuleType
[6] Fix | Delete
[7] Fix | Delete
__all__ = [
[8] Fix | Delete
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
[9] Fix | Delete
'walk_packages', 'iter_modules', 'get_data',
[10] Fix | Delete
'ImpImporter', 'ImpLoader', 'read_code', 'extend_path',
[11] Fix | Delete
]
[12] Fix | Delete
[13] Fix | Delete
def read_code(stream):
[14] Fix | Delete
# This helper is needed in order for the PEP 302 emulation to
[15] Fix | Delete
# correctly handle compiled files
[16] Fix | Delete
import marshal
[17] Fix | Delete
[18] Fix | Delete
magic = stream.read(4)
[19] Fix | Delete
if magic != imp.get_magic():
[20] Fix | Delete
return None
[21] Fix | Delete
[22] Fix | Delete
stream.read(4) # Skip timestamp
[23] Fix | Delete
return marshal.load(stream)
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
def simplegeneric(func):
[27] Fix | Delete
"""Make a trivial single-dispatch generic function"""
[28] Fix | Delete
registry = {}
[29] Fix | Delete
def wrapper(*args, **kw):
[30] Fix | Delete
ob = args[0]
[31] Fix | Delete
try:
[32] Fix | Delete
cls = ob.__class__
[33] Fix | Delete
except AttributeError:
[34] Fix | Delete
cls = type(ob)
[35] Fix | Delete
try:
[36] Fix | Delete
mro = cls.__mro__
[37] Fix | Delete
except AttributeError:
[38] Fix | Delete
try:
[39] Fix | Delete
class cls(cls, object):
[40] Fix | Delete
pass
[41] Fix | Delete
mro = cls.__mro__[1:]
[42] Fix | Delete
except TypeError:
[43] Fix | Delete
mro = object, # must be an ExtensionClass or some such :(
[44] Fix | Delete
for t in mro:
[45] Fix | Delete
if t in registry:
[46] Fix | Delete
return registry[t](*args, **kw)
[47] Fix | Delete
else:
[48] Fix | Delete
return func(*args, **kw)
[49] Fix | Delete
try:
[50] Fix | Delete
wrapper.__name__ = func.__name__
[51] Fix | Delete
except (TypeError, AttributeError):
[52] Fix | Delete
pass # Python 2.3 doesn't allow functions to be renamed
[53] Fix | Delete
[54] Fix | Delete
def register(typ, func=None):
[55] Fix | Delete
if func is None:
[56] Fix | Delete
return lambda f: register(typ, f)
[57] Fix | Delete
registry[typ] = func
[58] Fix | Delete
return func
[59] Fix | Delete
[60] Fix | Delete
wrapper.__dict__ = func.__dict__
[61] Fix | Delete
wrapper.__doc__ = func.__doc__
[62] Fix | Delete
wrapper.register = register
[63] Fix | Delete
return wrapper
[64] Fix | Delete
[65] Fix | Delete
[66] Fix | Delete
def walk_packages(path=None, prefix='', onerror=None):
[67] Fix | Delete
"""Yields (module_loader, name, ispkg) for all modules recursively
[68] Fix | Delete
on path, or, if path is None, all accessible modules.
[69] Fix | Delete
[70] Fix | Delete
'path' should be either None or a list of paths to look for
[71] Fix | Delete
modules in.
[72] Fix | Delete
[73] Fix | Delete
'prefix' is a string to output on the front of every module name
[74] Fix | Delete
on output.
[75] Fix | Delete
[76] Fix | Delete
Note that this function must import all *packages* (NOT all
[77] Fix | Delete
modules!) on the given path, in order to access the __path__
[78] Fix | Delete
attribute to find submodules.
[79] Fix | Delete
[80] Fix | Delete
'onerror' is a function which gets called with one argument (the
[81] Fix | Delete
name of the package which was being imported) if any exception
[82] Fix | Delete
occurs while trying to import a package. If no onerror function is
[83] Fix | Delete
supplied, ImportErrors are caught and ignored, while all other
[84] Fix | Delete
exceptions are propagated, terminating the search.
[85] Fix | Delete
[86] Fix | Delete
Examples:
[87] Fix | Delete
[88] Fix | Delete
# list all modules python can access
[89] Fix | Delete
walk_packages()
[90] Fix | Delete
[91] Fix | Delete
# list all submodules of ctypes
[92] Fix | Delete
walk_packages(ctypes.__path__, ctypes.__name__+'.')
[93] Fix | Delete
"""
[94] Fix | Delete
[95] Fix | Delete
def seen(p, m={}):
[96] Fix | Delete
if p in m:
[97] Fix | Delete
return True
[98] Fix | Delete
m[p] = True
[99] Fix | Delete
[100] Fix | Delete
for importer, name, ispkg in iter_modules(path, prefix):
[101] Fix | Delete
yield importer, name, ispkg
[102] Fix | Delete
[103] Fix | Delete
if ispkg:
[104] Fix | Delete
try:
[105] Fix | Delete
__import__(name)
[106] Fix | Delete
except ImportError:
[107] Fix | Delete
if onerror is not None:
[108] Fix | Delete
onerror(name)
[109] Fix | Delete
except Exception:
[110] Fix | Delete
if onerror is not None:
[111] Fix | Delete
onerror(name)
[112] Fix | Delete
else:
[113] Fix | Delete
raise
[114] Fix | Delete
else:
[115] Fix | Delete
path = getattr(sys.modules[name], '__path__', None) or []
[116] Fix | Delete
[117] Fix | Delete
# don't traverse path items we've seen before
[118] Fix | Delete
path = [p for p in path if not seen(p)]
[119] Fix | Delete
[120] Fix | Delete
for item in walk_packages(path, name+'.', onerror):
[121] Fix | Delete
yield item
[122] Fix | Delete
[123] Fix | Delete
[124] Fix | Delete
def iter_modules(path=None, prefix=''):
[125] Fix | Delete
"""Yields (module_loader, name, ispkg) for all submodules on path,
[126] Fix | Delete
or, if path is None, all top-level modules on sys.path.
[127] Fix | Delete
[128] Fix | Delete
'path' should be either None or a list of paths to look for
[129] Fix | Delete
modules in.
[130] Fix | Delete
[131] Fix | Delete
'prefix' is a string to output on the front of every module name
[132] Fix | Delete
on output.
[133] Fix | Delete
"""
[134] Fix | Delete
[135] Fix | Delete
if path is None:
[136] Fix | Delete
importers = iter_importers()
[137] Fix | Delete
else:
[138] Fix | Delete
importers = map(get_importer, path)
[139] Fix | Delete
[140] Fix | Delete
yielded = {}
[141] Fix | Delete
for i in importers:
[142] Fix | Delete
for name, ispkg in iter_importer_modules(i, prefix):
[143] Fix | Delete
if name not in yielded:
[144] Fix | Delete
yielded[name] = 1
[145] Fix | Delete
yield i, name, ispkg
[146] Fix | Delete
[147] Fix | Delete
[148] Fix | Delete
#@simplegeneric
[149] Fix | Delete
def iter_importer_modules(importer, prefix=''):
[150] Fix | Delete
if not hasattr(importer, 'iter_modules'):
[151] Fix | Delete
return []
[152] Fix | Delete
return importer.iter_modules(prefix)
[153] Fix | Delete
[154] Fix | Delete
iter_importer_modules = simplegeneric(iter_importer_modules)
[155] Fix | Delete
[156] Fix | Delete
[157] Fix | Delete
class ImpImporter:
[158] Fix | Delete
"""PEP 302 Importer that wraps Python's "classic" import algorithm
[159] Fix | Delete
[160] Fix | Delete
ImpImporter(dirname) produces a PEP 302 importer that searches that
[161] Fix | Delete
directory. ImpImporter(None) produces a PEP 302 importer that searches
[162] Fix | Delete
the current sys.path, plus any modules that are frozen or built-in.
[163] Fix | Delete
[164] Fix | Delete
Note that ImpImporter does not currently support being used by placement
[165] Fix | Delete
on sys.meta_path.
[166] Fix | Delete
"""
[167] Fix | Delete
[168] Fix | Delete
def __init__(self, path=None):
[169] Fix | Delete
self.path = path
[170] Fix | Delete
[171] Fix | Delete
def find_module(self, fullname, path=None):
[172] Fix | Delete
# Note: we ignore 'path' argument since it is only used via meta_path
[173] Fix | Delete
subname = fullname.split(".")[-1]
[174] Fix | Delete
if subname != fullname and self.path is None:
[175] Fix | Delete
return None
[176] Fix | Delete
if self.path is None:
[177] Fix | Delete
path = None
[178] Fix | Delete
else:
[179] Fix | Delete
path = [os.path.realpath(self.path)]
[180] Fix | Delete
try:
[181] Fix | Delete
file, filename, etc = imp.find_module(subname, path)
[182] Fix | Delete
except ImportError:
[183] Fix | Delete
return None
[184] Fix | Delete
return ImpLoader(fullname, file, filename, etc)
[185] Fix | Delete
[186] Fix | Delete
def iter_modules(self, prefix=''):
[187] Fix | Delete
if self.path is None or not os.path.isdir(self.path):
[188] Fix | Delete
return
[189] Fix | Delete
[190] Fix | Delete
yielded = {}
[191] Fix | Delete
import inspect
[192] Fix | Delete
try:
[193] Fix | Delete
filenames = os.listdir(self.path)
[194] Fix | Delete
except OSError:
[195] Fix | Delete
# ignore unreadable directories like import does
[196] Fix | Delete
filenames = []
[197] Fix | Delete
filenames.sort() # handle packages before same-named modules
[198] Fix | Delete
[199] Fix | Delete
for fn in filenames:
[200] Fix | Delete
modname = inspect.getmodulename(fn)
[201] Fix | Delete
if modname=='__init__' or modname in yielded:
[202] Fix | Delete
continue
[203] Fix | Delete
[204] Fix | Delete
path = os.path.join(self.path, fn)
[205] Fix | Delete
ispkg = False
[206] Fix | Delete
[207] Fix | Delete
if not modname and os.path.isdir(path) and '.' not in fn:
[208] Fix | Delete
modname = fn
[209] Fix | Delete
try:
[210] Fix | Delete
dircontents = os.listdir(path)
[211] Fix | Delete
except OSError:
[212] Fix | Delete
# ignore unreadable directories like import does
[213] Fix | Delete
dircontents = []
[214] Fix | Delete
for fn in dircontents:
[215] Fix | Delete
subname = inspect.getmodulename(fn)
[216] Fix | Delete
if subname=='__init__':
[217] Fix | Delete
ispkg = True
[218] Fix | Delete
break
[219] Fix | Delete
else:
[220] Fix | Delete
continue # not a package
[221] Fix | Delete
[222] Fix | Delete
if modname and '.' not in modname:
[223] Fix | Delete
yielded[modname] = 1
[224] Fix | Delete
yield prefix + modname, ispkg
[225] Fix | Delete
[226] Fix | Delete
[227] Fix | Delete
class ImpLoader:
[228] Fix | Delete
"""PEP 302 Loader that wraps Python's "classic" import algorithm
[229] Fix | Delete
"""
[230] Fix | Delete
code = source = None
[231] Fix | Delete
[232] Fix | Delete
def __init__(self, fullname, file, filename, etc):
[233] Fix | Delete
self.file = file
[234] Fix | Delete
self.filename = filename
[235] Fix | Delete
self.fullname = fullname
[236] Fix | Delete
self.etc = etc
[237] Fix | Delete
[238] Fix | Delete
def load_module(self, fullname):
[239] Fix | Delete
self._reopen()
[240] Fix | Delete
try:
[241] Fix | Delete
mod = imp.load_module(fullname, self.file, self.filename, self.etc)
[242] Fix | Delete
finally:
[243] Fix | Delete
if self.file:
[244] Fix | Delete
self.file.close()
[245] Fix | Delete
# Note: we don't set __loader__ because we want the module to look
[246] Fix | Delete
# normal; i.e. this is just a wrapper for standard import machinery
[247] Fix | Delete
return mod
[248] Fix | Delete
[249] Fix | Delete
def get_data(self, pathname):
[250] Fix | Delete
with open(pathname, "rb") as file:
[251] Fix | Delete
return file.read()
[252] Fix | Delete
[253] Fix | Delete
def _reopen(self):
[254] Fix | Delete
if self.file and self.file.closed:
[255] Fix | Delete
mod_type = self.etc[2]
[256] Fix | Delete
if mod_type==imp.PY_SOURCE:
[257] Fix | Delete
self.file = open(self.filename, 'rU')
[258] Fix | Delete
elif mod_type in (imp.PY_COMPILED, imp.C_EXTENSION):
[259] Fix | Delete
self.file = open(self.filename, 'rb')
[260] Fix | Delete
[261] Fix | Delete
def _fix_name(self, fullname):
[262] Fix | Delete
if fullname is None:
[263] Fix | Delete
fullname = self.fullname
[264] Fix | Delete
elif fullname != self.fullname:
[265] Fix | Delete
raise ImportError("Loader for module %s cannot handle "
[266] Fix | Delete
"module %s" % (self.fullname, fullname))
[267] Fix | Delete
return fullname
[268] Fix | Delete
[269] Fix | Delete
def is_package(self, fullname):
[270] Fix | Delete
fullname = self._fix_name(fullname)
[271] Fix | Delete
return self.etc[2]==imp.PKG_DIRECTORY
[272] Fix | Delete
[273] Fix | Delete
def get_code(self, fullname=None):
[274] Fix | Delete
fullname = self._fix_name(fullname)
[275] Fix | Delete
if self.code is None:
[276] Fix | Delete
mod_type = self.etc[2]
[277] Fix | Delete
if mod_type==imp.PY_SOURCE:
[278] Fix | Delete
source = self.get_source(fullname)
[279] Fix | Delete
self.code = compile(source, self.filename, 'exec')
[280] Fix | Delete
elif mod_type==imp.PY_COMPILED:
[281] Fix | Delete
self._reopen()
[282] Fix | Delete
try:
[283] Fix | Delete
self.code = read_code(self.file)
[284] Fix | Delete
finally:
[285] Fix | Delete
self.file.close()
[286] Fix | Delete
elif mod_type==imp.PKG_DIRECTORY:
[287] Fix | Delete
self.code = self._get_delegate().get_code()
[288] Fix | Delete
return self.code
[289] Fix | Delete
[290] Fix | Delete
def get_source(self, fullname=None):
[291] Fix | Delete
fullname = self._fix_name(fullname)
[292] Fix | Delete
if self.source is None:
[293] Fix | Delete
mod_type = self.etc[2]
[294] Fix | Delete
if mod_type==imp.PY_SOURCE:
[295] Fix | Delete
self._reopen()
[296] Fix | Delete
try:
[297] Fix | Delete
self.source = self.file.read()
[298] Fix | Delete
finally:
[299] Fix | Delete
self.file.close()
[300] Fix | Delete
elif mod_type==imp.PY_COMPILED:
[301] Fix | Delete
if os.path.exists(self.filename[:-1]):
[302] Fix | Delete
f = open(self.filename[:-1], 'rU')
[303] Fix | Delete
self.source = f.read()
[304] Fix | Delete
f.close()
[305] Fix | Delete
elif mod_type==imp.PKG_DIRECTORY:
[306] Fix | Delete
self.source = self._get_delegate().get_source()
[307] Fix | Delete
return self.source
[308] Fix | Delete
[309] Fix | Delete
[310] Fix | Delete
def _get_delegate(self):
[311] Fix | Delete
return ImpImporter(self.filename).find_module('__init__')
[312] Fix | Delete
[313] Fix | Delete
def get_filename(self, fullname=None):
[314] Fix | Delete
fullname = self._fix_name(fullname)
[315] Fix | Delete
mod_type = self.etc[2]
[316] Fix | Delete
if self.etc[2]==imp.PKG_DIRECTORY:
[317] Fix | Delete
return self._get_delegate().get_filename()
[318] Fix | Delete
elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION):
[319] Fix | Delete
return self.filename
[320] Fix | Delete
return None
[321] Fix | Delete
[322] Fix | Delete
[323] Fix | Delete
try:
[324] Fix | Delete
import zipimport
[325] Fix | Delete
from zipimport import zipimporter
[326] Fix | Delete
[327] Fix | Delete
def iter_zipimport_modules(importer, prefix=''):
[328] Fix | Delete
dirlist = zipimport._zip_directory_cache[importer.archive].keys()
[329] Fix | Delete
dirlist.sort()
[330] Fix | Delete
_prefix = importer.prefix
[331] Fix | Delete
plen = len(_prefix)
[332] Fix | Delete
yielded = {}
[333] Fix | Delete
import inspect
[334] Fix | Delete
for fn in dirlist:
[335] Fix | Delete
if not fn.startswith(_prefix):
[336] Fix | Delete
continue
[337] Fix | Delete
[338] Fix | Delete
fn = fn[plen:].split(os.sep)
[339] Fix | Delete
[340] Fix | Delete
if len(fn)==2 and fn[1].startswith('__init__.py'):
[341] Fix | Delete
if fn[0] not in yielded:
[342] Fix | Delete
yielded[fn[0]] = 1
[343] Fix | Delete
yield fn[0], True
[344] Fix | Delete
[345] Fix | Delete
if len(fn)!=1:
[346] Fix | Delete
continue
[347] Fix | Delete
[348] Fix | Delete
modname = inspect.getmodulename(fn[0])
[349] Fix | Delete
if modname=='__init__':
[350] Fix | Delete
continue
[351] Fix | Delete
[352] Fix | Delete
if modname and '.' not in modname and modname not in yielded:
[353] Fix | Delete
yielded[modname] = 1
[354] Fix | Delete
yield prefix + modname, False
[355] Fix | Delete
[356] Fix | Delete
iter_importer_modules.register(zipimporter, iter_zipimport_modules)
[357] Fix | Delete
[358] Fix | Delete
except ImportError:
[359] Fix | Delete
pass
[360] Fix | Delete
[361] Fix | Delete
[362] Fix | Delete
def get_importer(path_item):
[363] Fix | Delete
"""Retrieve a PEP 302 importer for the given path item
[364] Fix | Delete
[365] Fix | Delete
The returned importer is cached in sys.path_importer_cache
[366] Fix | Delete
if it was newly created by a path hook.
[367] Fix | Delete
[368] Fix | Delete
If there is no importer, a wrapper around the basic import
[369] Fix | Delete
machinery is returned. This wrapper is never inserted into
[370] Fix | Delete
the importer cache (None is inserted instead).
[371] Fix | Delete
[372] Fix | Delete
The cache (or part of it) can be cleared manually if a
[373] Fix | Delete
rescan of sys.path_hooks is necessary.
[374] Fix | Delete
"""
[375] Fix | Delete
try:
[376] Fix | Delete
importer = sys.path_importer_cache[path_item]
[377] Fix | Delete
except KeyError:
[378] Fix | Delete
for path_hook in sys.path_hooks:
[379] Fix | Delete
try:
[380] Fix | Delete
importer = path_hook(path_item)
[381] Fix | Delete
break
[382] Fix | Delete
except ImportError:
[383] Fix | Delete
pass
[384] Fix | Delete
else:
[385] Fix | Delete
importer = None
[386] Fix | Delete
sys.path_importer_cache.setdefault(path_item, importer)
[387] Fix | Delete
[388] Fix | Delete
if importer is None:
[389] Fix | Delete
try:
[390] Fix | Delete
importer = ImpImporter(path_item)
[391] Fix | Delete
except ImportError:
[392] Fix | Delete
importer = None
[393] Fix | Delete
return importer
[394] Fix | Delete
[395] Fix | Delete
[396] Fix | Delete
def iter_importers(fullname=""):
[397] Fix | Delete
"""Yield PEP 302 importers for the given module name
[398] Fix | Delete
[399] Fix | Delete
If fullname contains a '.', the importers will be for the package
[400] Fix | Delete
containing fullname, otherwise they will be importers for sys.meta_path,
[401] Fix | Delete
sys.path, and Python's "classic" import machinery, in that order. If
[402] Fix | Delete
the named module is in a package, that package is imported as a side
[403] Fix | Delete
effect of invoking this function.
[404] Fix | Delete
[405] Fix | Delete
Non PEP 302 mechanisms (e.g. the Windows registry) used by the
[406] Fix | Delete
standard import machinery to find files in alternative locations
[407] Fix | Delete
are partially supported, but are searched AFTER sys.path. Normally,
[408] Fix | Delete
these locations are searched BEFORE sys.path, preventing sys.path
[409] Fix | Delete
entries from shadowing them.
[410] Fix | Delete
[411] Fix | Delete
For this to cause a visible difference in behaviour, there must
[412] Fix | Delete
be a module or package name that is accessible via both sys.path
[413] Fix | Delete
and one of the non PEP 302 file system mechanisms. In this case,
[414] Fix | Delete
the emulation will find the former version, while the builtin
[415] Fix | Delete
import mechanism will find the latter.
[416] Fix | Delete
[417] Fix | Delete
Items of the following types can be affected by this discrepancy:
[418] Fix | Delete
imp.C_EXTENSION, imp.PY_SOURCE, imp.PY_COMPILED, imp.PKG_DIRECTORY
[419] Fix | Delete
"""
[420] Fix | Delete
if fullname.startswith('.'):
[421] Fix | Delete
raise ImportError("Relative module names not supported")
[422] Fix | Delete
if '.' in fullname:
[423] Fix | Delete
# Get the containing package's __path__
[424] Fix | Delete
pkg = '.'.join(fullname.split('.')[:-1])
[425] Fix | Delete
if pkg not in sys.modules:
[426] Fix | Delete
__import__(pkg)
[427] Fix | Delete
path = getattr(sys.modules[pkg], '__path__', None) or []
[428] Fix | Delete
else:
[429] Fix | Delete
for importer in sys.meta_path:
[430] Fix | Delete
yield importer
[431] Fix | Delete
path = sys.path
[432] Fix | Delete
for item in path:
[433] Fix | Delete
yield get_importer(item)
[434] Fix | Delete
if '.' not in fullname:
[435] Fix | Delete
yield ImpImporter()
[436] Fix | Delete
[437] Fix | Delete
def get_loader(module_or_name):
[438] Fix | Delete
"""Get a PEP 302 "loader" object for module_or_name
[439] Fix | Delete
[440] Fix | Delete
If the module or package is accessible via the normal import
[441] Fix | Delete
mechanism, a wrapper around the relevant part of that machinery
[442] Fix | Delete
is returned. Returns None if the module cannot be found or imported.
[443] Fix | Delete
If the named module is not already imported, its containing package
[444] Fix | Delete
(if any) is imported, in order to establish the package __path__.
[445] Fix | Delete
[446] Fix | Delete
This function uses iter_importers(), and is thus subject to the same
[447] Fix | Delete
limitations regarding platform-specific special import locations such
[448] Fix | Delete
as the Windows registry.
[449] Fix | Delete
"""
[450] Fix | Delete
if module_or_name in sys.modules:
[451] Fix | Delete
module_or_name = sys.modules[module_or_name]
[452] Fix | Delete
if isinstance(module_or_name, ModuleType):
[453] Fix | Delete
module = module_or_name
[454] Fix | Delete
loader = getattr(module, '__loader__', None)
[455] Fix | Delete
if loader is not None:
[456] Fix | Delete
return loader
[457] Fix | Delete
fullname = module.__name__
[458] Fix | Delete
else:
[459] Fix | Delete
fullname = module_or_name
[460] Fix | Delete
return find_loader(fullname)
[461] Fix | Delete
[462] Fix | Delete
def find_loader(fullname):
[463] Fix | Delete
"""Find a PEP 302 "loader" object for fullname
[464] Fix | Delete
[465] Fix | Delete
If fullname contains dots, path must be the containing package's __path__.
[466] Fix | Delete
Returns None if the module cannot be found or imported. This function uses
[467] Fix | Delete
iter_importers(), and is thus subject to the same limitations regarding
[468] Fix | Delete
platform-specific special import locations such as the Windows registry.
[469] Fix | Delete
"""
[470] Fix | Delete
for importer in iter_importers(fullname):
[471] Fix | Delete
loader = importer.find_module(fullname)
[472] Fix | Delete
if loader is not None:
[473] Fix | Delete
return loader
[474] Fix | Delete
[475] Fix | Delete
return None
[476] Fix | Delete
[477] Fix | Delete
[478] Fix | Delete
def extend_path(path, name):
[479] Fix | Delete
"""Extend a package's path.
[480] Fix | Delete
[481] Fix | Delete
Intended use is to place the following code in a package's __init__.py:
[482] Fix | Delete
[483] Fix | Delete
from pkgutil import extend_path
[484] Fix | Delete
__path__ = extend_path(__path__, __name__)
[485] Fix | Delete
[486] Fix | Delete
This will add to the package's __path__ all subdirectories of
[487] Fix | Delete
directories on sys.path named after the package. This is useful
[488] Fix | Delete
if one wants to distribute different parts of a single logical
[489] Fix | Delete
package as multiple directories.
[490] Fix | Delete
[491] Fix | Delete
It also looks for *.pkg files beginning where * matches the name
[492] Fix | Delete
argument. This feature is similar to *.pth files (see site.py),
[493] Fix | Delete
except that it doesn't special-case lines starting with 'import'.
[494] Fix | Delete
A *.pkg file is trusted at face value: apart from checking for
[495] Fix | Delete
duplicates, all entries found in a *.pkg file are added to the
[496] Fix | Delete
path, regardless of whether they are exist the filesystem. (This
[497] Fix | Delete
is a feature.)
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function