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