Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python2....
File: ihooks.py
"""Import hook support.
[0] Fix | Delete
[1] Fix | Delete
Consistent use of this module will make it possible to change the
[2] Fix | Delete
different mechanisms involved in loading modules independently.
[3] Fix | Delete
[4] Fix | Delete
While the built-in module imp exports interfaces to the built-in
[5] Fix | Delete
module searching and loading algorithm, and it is possible to replace
[6] Fix | Delete
the built-in function __import__ in order to change the semantics of
[7] Fix | Delete
the import statement, until now it has been difficult to combine the
[8] Fix | Delete
effect of different __import__ hacks, like loading modules from URLs
[9] Fix | Delete
by rimport.py, or restricted execution by rexec.py.
[10] Fix | Delete
[11] Fix | Delete
This module defines three new concepts:
[12] Fix | Delete
[13] Fix | Delete
1) A "file system hooks" class provides an interface to a filesystem.
[14] Fix | Delete
[15] Fix | Delete
One hooks class is defined (Hooks), which uses the interface provided
[16] Fix | Delete
by standard modules os and os.path. It should be used as the base
[17] Fix | Delete
class for other hooks classes.
[18] Fix | Delete
[19] Fix | Delete
2) A "module loader" class provides an interface to search for a
[20] Fix | Delete
module in a search path and to load it. It defines a method which
[21] Fix | Delete
searches for a module in a single directory; by overriding this method
[22] Fix | Delete
one can redefine the details of the search. If the directory is None,
[23] Fix | Delete
built-in and frozen modules are searched instead.
[24] Fix | Delete
[25] Fix | Delete
Two module loader class are defined, both implementing the search
[26] Fix | Delete
strategy used by the built-in __import__ function: ModuleLoader uses
[27] Fix | Delete
the imp module's find_module interface, while HookableModuleLoader
[28] Fix | Delete
uses a file system hooks class to interact with the file system. Both
[29] Fix | Delete
use the imp module's load_* interfaces to actually load the module.
[30] Fix | Delete
[31] Fix | Delete
3) A "module importer" class provides an interface to import a
[32] Fix | Delete
module, as well as interfaces to reload and unload a module. It also
[33] Fix | Delete
provides interfaces to install and uninstall itself instead of the
[34] Fix | Delete
default __import__ and reload (and unload) functions.
[35] Fix | Delete
[36] Fix | Delete
One module importer class is defined (ModuleImporter), which uses a
[37] Fix | Delete
module loader instance passed in (by default HookableModuleLoader is
[38] Fix | Delete
instantiated).
[39] Fix | Delete
[40] Fix | Delete
The classes defined here should be used as base classes for extended
[41] Fix | Delete
functionality along those lines.
[42] Fix | Delete
[43] Fix | Delete
If a module importer class supports dotted names, its import_module()
[44] Fix | Delete
must return a different value depending on whether it is called on
[45] Fix | Delete
behalf of a "from ... import ..." statement or not. (This is caused
[46] Fix | Delete
by the way the __import__ hook is used by the Python interpreter.) It
[47] Fix | Delete
would also do wise to install a different version of reload().
[48] Fix | Delete
[49] Fix | Delete
"""
[50] Fix | Delete
from warnings import warnpy3k, warn
[51] Fix | Delete
warnpy3k("the ihooks module has been removed in Python 3.0", stacklevel=2)
[52] Fix | Delete
del warnpy3k
[53] Fix | Delete
[54] Fix | Delete
import __builtin__
[55] Fix | Delete
import imp
[56] Fix | Delete
import os
[57] Fix | Delete
import sys
[58] Fix | Delete
[59] Fix | Delete
__all__ = ["BasicModuleLoader","Hooks","ModuleLoader","FancyModuleLoader",
[60] Fix | Delete
"BasicModuleImporter","ModuleImporter","install","uninstall"]
[61] Fix | Delete
[62] Fix | Delete
VERBOSE = 0
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
from imp import C_EXTENSION, PY_SOURCE, PY_COMPILED
[66] Fix | Delete
from imp import C_BUILTIN, PY_FROZEN, PKG_DIRECTORY
[67] Fix | Delete
BUILTIN_MODULE = C_BUILTIN
[68] Fix | Delete
FROZEN_MODULE = PY_FROZEN
[69] Fix | Delete
[70] Fix | Delete
[71] Fix | Delete
class _Verbose:
[72] Fix | Delete
[73] Fix | Delete
def __init__(self, verbose = VERBOSE):
[74] Fix | Delete
self.verbose = verbose
[75] Fix | Delete
[76] Fix | Delete
def get_verbose(self):
[77] Fix | Delete
return self.verbose
[78] Fix | Delete
[79] Fix | Delete
def set_verbose(self, verbose):
[80] Fix | Delete
self.verbose = verbose
[81] Fix | Delete
[82] Fix | Delete
# XXX The following is an experimental interface
[83] Fix | Delete
[84] Fix | Delete
def note(self, *args):
[85] Fix | Delete
if self.verbose:
[86] Fix | Delete
self.message(*args)
[87] Fix | Delete
[88] Fix | Delete
def message(self, format, *args):
[89] Fix | Delete
if args:
[90] Fix | Delete
print format%args
[91] Fix | Delete
else:
[92] Fix | Delete
print format
[93] Fix | Delete
[94] Fix | Delete
[95] Fix | Delete
class BasicModuleLoader(_Verbose):
[96] Fix | Delete
[97] Fix | Delete
"""Basic module loader.
[98] Fix | Delete
[99] Fix | Delete
This provides the same functionality as built-in import. It
[100] Fix | Delete
doesn't deal with checking sys.modules -- all it provides is
[101] Fix | Delete
find_module() and a load_module(), as well as find_module_in_dir()
[102] Fix | Delete
which searches just one directory, and can be overridden by a
[103] Fix | Delete
derived class to change the module search algorithm when the basic
[104] Fix | Delete
dependency on sys.path is unchanged.
[105] Fix | Delete
[106] Fix | Delete
The interface is a little more convenient than imp's:
[107] Fix | Delete
find_module(name, [path]) returns None or 'stuff', and
[108] Fix | Delete
load_module(name, stuff) loads the module.
[109] Fix | Delete
[110] Fix | Delete
"""
[111] Fix | Delete
[112] Fix | Delete
def find_module(self, name, path = None):
[113] Fix | Delete
if path is None:
[114] Fix | Delete
path = [None] + self.default_path()
[115] Fix | Delete
for dir in path:
[116] Fix | Delete
stuff = self.find_module_in_dir(name, dir)
[117] Fix | Delete
if stuff: return stuff
[118] Fix | Delete
return None
[119] Fix | Delete
[120] Fix | Delete
def default_path(self):
[121] Fix | Delete
return sys.path
[122] Fix | Delete
[123] Fix | Delete
def find_module_in_dir(self, name, dir):
[124] Fix | Delete
if dir is None:
[125] Fix | Delete
return self.find_builtin_module(name)
[126] Fix | Delete
else:
[127] Fix | Delete
try:
[128] Fix | Delete
return imp.find_module(name, [dir])
[129] Fix | Delete
except ImportError:
[130] Fix | Delete
return None
[131] Fix | Delete
[132] Fix | Delete
def find_builtin_module(self, name):
[133] Fix | Delete
# XXX frozen packages?
[134] Fix | Delete
if imp.is_builtin(name):
[135] Fix | Delete
return None, '', ('', '', BUILTIN_MODULE)
[136] Fix | Delete
if imp.is_frozen(name):
[137] Fix | Delete
return None, '', ('', '', FROZEN_MODULE)
[138] Fix | Delete
return None
[139] Fix | Delete
[140] Fix | Delete
def load_module(self, name, stuff):
[141] Fix | Delete
file, filename, info = stuff
[142] Fix | Delete
try:
[143] Fix | Delete
return imp.load_module(name, file, filename, info)
[144] Fix | Delete
finally:
[145] Fix | Delete
if file: file.close()
[146] Fix | Delete
[147] Fix | Delete
[148] Fix | Delete
class Hooks(_Verbose):
[149] Fix | Delete
[150] Fix | Delete
"""Hooks into the filesystem and interpreter.
[151] Fix | Delete
[152] Fix | Delete
By deriving a subclass you can redefine your filesystem interface,
[153] Fix | Delete
e.g. to merge it with the URL space.
[154] Fix | Delete
[155] Fix | Delete
This base class behaves just like the native filesystem.
[156] Fix | Delete
[157] Fix | Delete
"""
[158] Fix | Delete
[159] Fix | Delete
# imp interface
[160] Fix | Delete
def get_suffixes(self): return imp.get_suffixes()
[161] Fix | Delete
def new_module(self, name): return imp.new_module(name)
[162] Fix | Delete
def is_builtin(self, name): return imp.is_builtin(name)
[163] Fix | Delete
def init_builtin(self, name): return imp.init_builtin(name)
[164] Fix | Delete
def is_frozen(self, name): return imp.is_frozen(name)
[165] Fix | Delete
def init_frozen(self, name): return imp.init_frozen(name)
[166] Fix | Delete
def get_frozen_object(self, name): return imp.get_frozen_object(name)
[167] Fix | Delete
def load_source(self, name, filename, file=None):
[168] Fix | Delete
return imp.load_source(name, filename, file)
[169] Fix | Delete
def load_compiled(self, name, filename, file=None):
[170] Fix | Delete
return imp.load_compiled(name, filename, file)
[171] Fix | Delete
def load_dynamic(self, name, filename, file=None):
[172] Fix | Delete
return imp.load_dynamic(name, filename, file)
[173] Fix | Delete
def load_package(self, name, filename, file=None):
[174] Fix | Delete
return imp.load_module(name, file, filename, ("", "", PKG_DIRECTORY))
[175] Fix | Delete
[176] Fix | Delete
def add_module(self, name):
[177] Fix | Delete
d = self.modules_dict()
[178] Fix | Delete
if name in d: return d[name]
[179] Fix | Delete
d[name] = m = self.new_module(name)
[180] Fix | Delete
return m
[181] Fix | Delete
[182] Fix | Delete
# sys interface
[183] Fix | Delete
def modules_dict(self): return sys.modules
[184] Fix | Delete
def default_path(self): return sys.path
[185] Fix | Delete
[186] Fix | Delete
def path_split(self, x): return os.path.split(x)
[187] Fix | Delete
def path_join(self, x, y): return os.path.join(x, y)
[188] Fix | Delete
def path_isabs(self, x): return os.path.isabs(x)
[189] Fix | Delete
# etc.
[190] Fix | Delete
[191] Fix | Delete
def path_exists(self, x): return os.path.exists(x)
[192] Fix | Delete
def path_isdir(self, x): return os.path.isdir(x)
[193] Fix | Delete
def path_isfile(self, x): return os.path.isfile(x)
[194] Fix | Delete
def path_islink(self, x): return os.path.islink(x)
[195] Fix | Delete
# etc.
[196] Fix | Delete
[197] Fix | Delete
def openfile(self, *x): return open(*x)
[198] Fix | Delete
openfile_error = IOError
[199] Fix | Delete
def listdir(self, x): return os.listdir(x)
[200] Fix | Delete
listdir_error = os.error
[201] Fix | Delete
# etc.
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
class ModuleLoader(BasicModuleLoader):
[205] Fix | Delete
[206] Fix | Delete
"""Default module loader; uses file system hooks.
[207] Fix | Delete
[208] Fix | Delete
By defining suitable hooks, you might be able to load modules from
[209] Fix | Delete
other sources than the file system, e.g. from compressed or
[210] Fix | Delete
encrypted files, tar files or (if you're brave!) URLs.
[211] Fix | Delete
[212] Fix | Delete
"""
[213] Fix | Delete
[214] Fix | Delete
def __init__(self, hooks = None, verbose = VERBOSE):
[215] Fix | Delete
BasicModuleLoader.__init__(self, verbose)
[216] Fix | Delete
self.hooks = hooks or Hooks(verbose)
[217] Fix | Delete
[218] Fix | Delete
def default_path(self):
[219] Fix | Delete
return self.hooks.default_path()
[220] Fix | Delete
[221] Fix | Delete
def modules_dict(self):
[222] Fix | Delete
return self.hooks.modules_dict()
[223] Fix | Delete
[224] Fix | Delete
def get_hooks(self):
[225] Fix | Delete
return self.hooks
[226] Fix | Delete
[227] Fix | Delete
def set_hooks(self, hooks):
[228] Fix | Delete
self.hooks = hooks
[229] Fix | Delete
[230] Fix | Delete
def find_builtin_module(self, name):
[231] Fix | Delete
# XXX frozen packages?
[232] Fix | Delete
if self.hooks.is_builtin(name):
[233] Fix | Delete
return None, '', ('', '', BUILTIN_MODULE)
[234] Fix | Delete
if self.hooks.is_frozen(name):
[235] Fix | Delete
return None, '', ('', '', FROZEN_MODULE)
[236] Fix | Delete
return None
[237] Fix | Delete
[238] Fix | Delete
def find_module_in_dir(self, name, dir, allow_packages=1):
[239] Fix | Delete
if dir is None:
[240] Fix | Delete
return self.find_builtin_module(name)
[241] Fix | Delete
if allow_packages:
[242] Fix | Delete
fullname = self.hooks.path_join(dir, name)
[243] Fix | Delete
if self.hooks.path_isdir(fullname):
[244] Fix | Delete
stuff = self.find_module_in_dir("__init__", fullname, 0)
[245] Fix | Delete
if stuff:
[246] Fix | Delete
file = stuff[0]
[247] Fix | Delete
if file: file.close()
[248] Fix | Delete
return None, fullname, ('', '', PKG_DIRECTORY)
[249] Fix | Delete
for info in self.hooks.get_suffixes():
[250] Fix | Delete
suff, mode, type = info
[251] Fix | Delete
fullname = self.hooks.path_join(dir, name+suff)
[252] Fix | Delete
try:
[253] Fix | Delete
fp = self.hooks.openfile(fullname, mode)
[254] Fix | Delete
return fp, fullname, info
[255] Fix | Delete
except self.hooks.openfile_error:
[256] Fix | Delete
pass
[257] Fix | Delete
return None
[258] Fix | Delete
[259] Fix | Delete
def load_module(self, name, stuff):
[260] Fix | Delete
file, filename, info = stuff
[261] Fix | Delete
(suff, mode, type) = info
[262] Fix | Delete
try:
[263] Fix | Delete
if type == BUILTIN_MODULE:
[264] Fix | Delete
return self.hooks.init_builtin(name)
[265] Fix | Delete
if type == FROZEN_MODULE:
[266] Fix | Delete
return self.hooks.init_frozen(name)
[267] Fix | Delete
if type == C_EXTENSION:
[268] Fix | Delete
m = self.hooks.load_dynamic(name, filename, file)
[269] Fix | Delete
elif type == PY_SOURCE:
[270] Fix | Delete
m = self.hooks.load_source(name, filename, file)
[271] Fix | Delete
elif type == PY_COMPILED:
[272] Fix | Delete
m = self.hooks.load_compiled(name, filename, file)
[273] Fix | Delete
elif type == PKG_DIRECTORY:
[274] Fix | Delete
m = self.hooks.load_package(name, filename, file)
[275] Fix | Delete
else:
[276] Fix | Delete
raise ImportError, "Unrecognized module type (%r) for %s" % \
[277] Fix | Delete
(type, name)
[278] Fix | Delete
finally:
[279] Fix | Delete
if file: file.close()
[280] Fix | Delete
m.__file__ = filename
[281] Fix | Delete
return m
[282] Fix | Delete
[283] Fix | Delete
[284] Fix | Delete
class FancyModuleLoader(ModuleLoader):
[285] Fix | Delete
[286] Fix | Delete
"""Fancy module loader -- parses and execs the code itself."""
[287] Fix | Delete
[288] Fix | Delete
def load_module(self, name, stuff):
[289] Fix | Delete
file, filename, (suff, mode, type) = stuff
[290] Fix | Delete
realfilename = filename
[291] Fix | Delete
path = None
[292] Fix | Delete
[293] Fix | Delete
if type == PKG_DIRECTORY:
[294] Fix | Delete
initstuff = self.find_module_in_dir("__init__", filename, 0)
[295] Fix | Delete
if not initstuff:
[296] Fix | Delete
raise ImportError, "No __init__ module in package %s" % name
[297] Fix | Delete
initfile, initfilename, initinfo = initstuff
[298] Fix | Delete
initsuff, initmode, inittype = initinfo
[299] Fix | Delete
if inittype not in (PY_COMPILED, PY_SOURCE):
[300] Fix | Delete
if initfile: initfile.close()
[301] Fix | Delete
raise ImportError, \
[302] Fix | Delete
"Bad type (%r) for __init__ module in package %s" % (
[303] Fix | Delete
inittype, name)
[304] Fix | Delete
path = [filename]
[305] Fix | Delete
file = initfile
[306] Fix | Delete
realfilename = initfilename
[307] Fix | Delete
type = inittype
[308] Fix | Delete
[309] Fix | Delete
if type == FROZEN_MODULE:
[310] Fix | Delete
code = self.hooks.get_frozen_object(name)
[311] Fix | Delete
elif type == PY_COMPILED:
[312] Fix | Delete
import marshal
[313] Fix | Delete
file.seek(8)
[314] Fix | Delete
code = marshal.load(file)
[315] Fix | Delete
elif type == PY_SOURCE:
[316] Fix | Delete
data = file.read()
[317] Fix | Delete
code = compile(data, realfilename, 'exec')
[318] Fix | Delete
else:
[319] Fix | Delete
return ModuleLoader.load_module(self, name, stuff)
[320] Fix | Delete
[321] Fix | Delete
m = self.hooks.add_module(name)
[322] Fix | Delete
if path:
[323] Fix | Delete
m.__path__ = path
[324] Fix | Delete
m.__file__ = filename
[325] Fix | Delete
try:
[326] Fix | Delete
exec code in m.__dict__
[327] Fix | Delete
except:
[328] Fix | Delete
d = self.hooks.modules_dict()
[329] Fix | Delete
if name in d:
[330] Fix | Delete
del d[name]
[331] Fix | Delete
raise
[332] Fix | Delete
return m
[333] Fix | Delete
[334] Fix | Delete
[335] Fix | Delete
class BasicModuleImporter(_Verbose):
[336] Fix | Delete
[337] Fix | Delete
"""Basic module importer; uses module loader.
[338] Fix | Delete
[339] Fix | Delete
This provides basic import facilities but no package imports.
[340] Fix | Delete
[341] Fix | Delete
"""
[342] Fix | Delete
[343] Fix | Delete
def __init__(self, loader = None, verbose = VERBOSE):
[344] Fix | Delete
_Verbose.__init__(self, verbose)
[345] Fix | Delete
self.loader = loader or ModuleLoader(None, verbose)
[346] Fix | Delete
self.modules = self.loader.modules_dict()
[347] Fix | Delete
[348] Fix | Delete
def get_loader(self):
[349] Fix | Delete
return self.loader
[350] Fix | Delete
[351] Fix | Delete
def set_loader(self, loader):
[352] Fix | Delete
self.loader = loader
[353] Fix | Delete
[354] Fix | Delete
def get_hooks(self):
[355] Fix | Delete
return self.loader.get_hooks()
[356] Fix | Delete
[357] Fix | Delete
def set_hooks(self, hooks):
[358] Fix | Delete
return self.loader.set_hooks(hooks)
[359] Fix | Delete
[360] Fix | Delete
def import_module(self, name, globals={}, locals={}, fromlist=[]):
[361] Fix | Delete
name = str(name)
[362] Fix | Delete
if name in self.modules:
[363] Fix | Delete
return self.modules[name] # Fast path
[364] Fix | Delete
stuff = self.loader.find_module(name)
[365] Fix | Delete
if not stuff:
[366] Fix | Delete
raise ImportError, "No module named %s" % name
[367] Fix | Delete
return self.loader.load_module(name, stuff)
[368] Fix | Delete
[369] Fix | Delete
def reload(self, module, path = None):
[370] Fix | Delete
name = str(module.__name__)
[371] Fix | Delete
stuff = self.loader.find_module(name, path)
[372] Fix | Delete
if not stuff:
[373] Fix | Delete
raise ImportError, "Module %s not found for reload" % name
[374] Fix | Delete
return self.loader.load_module(name, stuff)
[375] Fix | Delete
[376] Fix | Delete
def unload(self, module):
[377] Fix | Delete
del self.modules[str(module.__name__)]
[378] Fix | Delete
# XXX Should this try to clear the module's namespace?
[379] Fix | Delete
[380] Fix | Delete
def install(self):
[381] Fix | Delete
self.save_import_module = __builtin__.__import__
[382] Fix | Delete
self.save_reload = __builtin__.reload
[383] Fix | Delete
if not hasattr(__builtin__, 'unload'):
[384] Fix | Delete
__builtin__.unload = None
[385] Fix | Delete
self.save_unload = __builtin__.unload
[386] Fix | Delete
__builtin__.__import__ = self.import_module
[387] Fix | Delete
__builtin__.reload = self.reload
[388] Fix | Delete
__builtin__.unload = self.unload
[389] Fix | Delete
[390] Fix | Delete
def uninstall(self):
[391] Fix | Delete
__builtin__.__import__ = self.save_import_module
[392] Fix | Delete
__builtin__.reload = self.save_reload
[393] Fix | Delete
__builtin__.unload = self.save_unload
[394] Fix | Delete
if not __builtin__.unload:
[395] Fix | Delete
del __builtin__.unload
[396] Fix | Delete
[397] Fix | Delete
[398] Fix | Delete
class ModuleImporter(BasicModuleImporter):
[399] Fix | Delete
[400] Fix | Delete
"""A module importer that supports packages."""
[401] Fix | Delete
[402] Fix | Delete
def import_module(self, name, globals=None, locals=None, fromlist=None,
[403] Fix | Delete
level=-1):
[404] Fix | Delete
parent = self.determine_parent(globals, level)
[405] Fix | Delete
q, tail = self.find_head_package(parent, str(name))
[406] Fix | Delete
m = self.load_tail(q, tail)
[407] Fix | Delete
if not fromlist:
[408] Fix | Delete
return q
[409] Fix | Delete
if hasattr(m, "__path__"):
[410] Fix | Delete
self.ensure_fromlist(m, fromlist)
[411] Fix | Delete
return m
[412] Fix | Delete
[413] Fix | Delete
def determine_parent(self, globals, level=-1):
[414] Fix | Delete
if not globals or not level:
[415] Fix | Delete
return None
[416] Fix | Delete
pkgname = globals.get('__package__')
[417] Fix | Delete
if pkgname is not None:
[418] Fix | Delete
if not pkgname and level > 0:
[419] Fix | Delete
raise ValueError, 'Attempted relative import in non-package'
[420] Fix | Delete
else:
[421] Fix | Delete
# __package__ not set, figure it out and set it
[422] Fix | Delete
modname = globals.get('__name__')
[423] Fix | Delete
if modname is None:
[424] Fix | Delete
return None
[425] Fix | Delete
if "__path__" in globals:
[426] Fix | Delete
# __path__ is set so modname is already the package name
[427] Fix | Delete
pkgname = modname
[428] Fix | Delete
else:
[429] Fix | Delete
# normal module, work out package name if any
[430] Fix | Delete
if '.' not in modname:
[431] Fix | Delete
if level > 0:
[432] Fix | Delete
raise ValueError, ('Attempted relative import in '
[433] Fix | Delete
'non-package')
[434] Fix | Delete
globals['__package__'] = None
[435] Fix | Delete
return None
[436] Fix | Delete
pkgname = modname.rpartition('.')[0]
[437] Fix | Delete
globals['__package__'] = pkgname
[438] Fix | Delete
if level > 0:
[439] Fix | Delete
dot = len(pkgname)
[440] Fix | Delete
for x in range(level, 1, -1):
[441] Fix | Delete
try:
[442] Fix | Delete
dot = pkgname.rindex('.', 0, dot)
[443] Fix | Delete
except ValueError:
[444] Fix | Delete
raise ValueError('attempted relative import beyond '
[445] Fix | Delete
'top-level package')
[446] Fix | Delete
pkgname = pkgname[:dot]
[447] Fix | Delete
try:
[448] Fix | Delete
return sys.modules[pkgname]
[449] Fix | Delete
except KeyError:
[450] Fix | Delete
if level < 1:
[451] Fix | Delete
warn("Parent module '%s' not found while handling "
[452] Fix | Delete
"absolute import" % pkgname, RuntimeWarning, 1)
[453] Fix | Delete
return None
[454] Fix | Delete
else:
[455] Fix | Delete
raise SystemError, ("Parent module '%s' not loaded, cannot "
[456] Fix | Delete
"perform relative import" % pkgname)
[457] Fix | Delete
[458] Fix | Delete
def find_head_package(self, parent, name):
[459] Fix | Delete
if '.' in name:
[460] Fix | Delete
i = name.find('.')
[461] Fix | Delete
head = name[:i]
[462] Fix | Delete
tail = name[i+1:]
[463] Fix | Delete
else:
[464] Fix | Delete
head = name
[465] Fix | Delete
tail = ""
[466] Fix | Delete
if parent:
[467] Fix | Delete
qname = "%s.%s" % (parent.__name__, head)
[468] Fix | Delete
else:
[469] Fix | Delete
qname = head
[470] Fix | Delete
q = self.import_it(head, qname, parent)
[471] Fix | Delete
if q: return q, tail
[472] Fix | Delete
if parent:
[473] Fix | Delete
qname = head
[474] Fix | Delete
parent = None
[475] Fix | Delete
q = self.import_it(head, qname, parent)
[476] Fix | Delete
if q: return q, tail
[477] Fix | Delete
raise ImportError, "No module named '%s'" % qname
[478] Fix | Delete
[479] Fix | Delete
def load_tail(self, q, tail):
[480] Fix | Delete
m = q
[481] Fix | Delete
while tail:
[482] Fix | Delete
i = tail.find('.')
[483] Fix | Delete
if i < 0: i = len(tail)
[484] Fix | Delete
head, tail = tail[:i], tail[i+1:]
[485] Fix | Delete
mname = "%s.%s" % (m.__name__, head)
[486] Fix | Delete
m = self.import_it(head, mname, m)
[487] Fix | Delete
if not m:
[488] Fix | Delete
raise ImportError, "No module named '%s'" % mname
[489] Fix | Delete
return m
[490] Fix | Delete
[491] Fix | Delete
def ensure_fromlist(self, m, fromlist, recursive=0):
[492] Fix | Delete
for sub in fromlist:
[493] Fix | Delete
if sub == "*":
[494] Fix | Delete
if not recursive:
[495] Fix | Delete
try:
[496] Fix | Delete
all = m.__all__
[497] Fix | Delete
except AttributeError:
[498] Fix | Delete
pass
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function