Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python2....
File: imputil.py
"""
[0] Fix | Delete
Import utilities
[1] Fix | Delete
[2] Fix | Delete
Exported classes:
[3] Fix | Delete
ImportManager Manage the import process
[4] Fix | Delete
[5] Fix | Delete
Importer Base class for replacing standard import functions
[6] Fix | Delete
BuiltinImporter Emulate the import mechanism for builtin and frozen modules
[7] Fix | Delete
[8] Fix | Delete
DynLoadSuffixImporter
[9] Fix | Delete
"""
[10] Fix | Delete
from warnings import warnpy3k
[11] Fix | Delete
warnpy3k("the imputil module has been removed in Python 3.0", stacklevel=2)
[12] Fix | Delete
del warnpy3k
[13] Fix | Delete
[14] Fix | Delete
# note: avoid importing non-builtin modules
[15] Fix | Delete
import imp ### not available in Jython?
[16] Fix | Delete
import sys
[17] Fix | Delete
import __builtin__
[18] Fix | Delete
[19] Fix | Delete
# for the DirectoryImporter
[20] Fix | Delete
import struct
[21] Fix | Delete
import marshal
[22] Fix | Delete
[23] Fix | Delete
__all__ = ["ImportManager","Importer","BuiltinImporter"]
[24] Fix | Delete
[25] Fix | Delete
_StringType = type('')
[26] Fix | Delete
_ModuleType = type(sys) ### doesn't work in Jython...
[27] Fix | Delete
[28] Fix | Delete
class ImportManager:
[29] Fix | Delete
"Manage the import process."
[30] Fix | Delete
[31] Fix | Delete
def install(self, namespace=vars(__builtin__)):
[32] Fix | Delete
"Install this ImportManager into the specified namespace."
[33] Fix | Delete
[34] Fix | Delete
if isinstance(namespace, _ModuleType):
[35] Fix | Delete
namespace = vars(namespace)
[36] Fix | Delete
[37] Fix | Delete
# Note: we have no notion of "chaining"
[38] Fix | Delete
[39] Fix | Delete
# Record the previous import hook, then install our own.
[40] Fix | Delete
self.previous_importer = namespace['__import__']
[41] Fix | Delete
self.namespace = namespace
[42] Fix | Delete
namespace['__import__'] = self._import_hook
[43] Fix | Delete
[44] Fix | Delete
### fix this
[45] Fix | Delete
#namespace['reload'] = self._reload_hook
[46] Fix | Delete
[47] Fix | Delete
def uninstall(self):
[48] Fix | Delete
"Restore the previous import mechanism."
[49] Fix | Delete
self.namespace['__import__'] = self.previous_importer
[50] Fix | Delete
[51] Fix | Delete
def add_suffix(self, suffix, importFunc):
[52] Fix | Delete
assert hasattr(importFunc, '__call__')
[53] Fix | Delete
self.fs_imp.add_suffix(suffix, importFunc)
[54] Fix | Delete
[55] Fix | Delete
######################################################################
[56] Fix | Delete
#
[57] Fix | Delete
# PRIVATE METHODS
[58] Fix | Delete
#
[59] Fix | Delete
[60] Fix | Delete
clsFilesystemImporter = None
[61] Fix | Delete
[62] Fix | Delete
def __init__(self, fs_imp=None):
[63] Fix | Delete
# we're definitely going to be importing something in the future,
[64] Fix | Delete
# so let's just load the OS-related facilities.
[65] Fix | Delete
if not _os_stat:
[66] Fix | Delete
_os_bootstrap()
[67] Fix | Delete
[68] Fix | Delete
# This is the Importer that we use for grabbing stuff from the
[69] Fix | Delete
# filesystem. It defines one more method (import_from_dir) for our use.
[70] Fix | Delete
if fs_imp is None:
[71] Fix | Delete
cls = self.clsFilesystemImporter or _FilesystemImporter
[72] Fix | Delete
fs_imp = cls()
[73] Fix | Delete
self.fs_imp = fs_imp
[74] Fix | Delete
[75] Fix | Delete
# Initialize the set of suffixes that we recognize and import.
[76] Fix | Delete
# The default will import dynamic-load modules first, followed by
[77] Fix | Delete
# .py files (or a .py file's cached bytecode)
[78] Fix | Delete
for desc in imp.get_suffixes():
[79] Fix | Delete
if desc[2] == imp.C_EXTENSION:
[80] Fix | Delete
self.add_suffix(desc[0],
[81] Fix | Delete
DynLoadSuffixImporter(desc).import_file)
[82] Fix | Delete
self.add_suffix('.py', py_suffix_importer)
[83] Fix | Delete
[84] Fix | Delete
def _import_hook(self, fqname, globals=None, locals=None, fromlist=None):
[85] Fix | Delete
"""Python calls this hook to locate and import a module."""
[86] Fix | Delete
[87] Fix | Delete
parts = fqname.split('.')
[88] Fix | Delete
[89] Fix | Delete
# determine the context of this import
[90] Fix | Delete
parent = self._determine_import_context(globals)
[91] Fix | Delete
[92] Fix | Delete
# if there is a parent, then its importer should manage this import
[93] Fix | Delete
if parent:
[94] Fix | Delete
module = parent.__importer__._do_import(parent, parts, fromlist)
[95] Fix | Delete
if module:
[96] Fix | Delete
return module
[97] Fix | Delete
[98] Fix | Delete
# has the top module already been imported?
[99] Fix | Delete
try:
[100] Fix | Delete
top_module = sys.modules[parts[0]]
[101] Fix | Delete
except KeyError:
[102] Fix | Delete
[103] Fix | Delete
# look for the topmost module
[104] Fix | Delete
top_module = self._import_top_module(parts[0])
[105] Fix | Delete
if not top_module:
[106] Fix | Delete
# the topmost module wasn't found at all.
[107] Fix | Delete
raise ImportError, 'No module named ' + fqname
[108] Fix | Delete
[109] Fix | Delete
# fast-path simple imports
[110] Fix | Delete
if len(parts) == 1:
[111] Fix | Delete
if not fromlist:
[112] Fix | Delete
return top_module
[113] Fix | Delete
[114] Fix | Delete
if not top_module.__dict__.get('__ispkg__'):
[115] Fix | Delete
# __ispkg__ isn't defined (the module was not imported by us),
[116] Fix | Delete
# or it is zero.
[117] Fix | Delete
#
[118] Fix | Delete
# In the former case, there is no way that we could import
[119] Fix | Delete
# sub-modules that occur in the fromlist (but we can't raise an
[120] Fix | Delete
# error because it may just be names) because we don't know how
[121] Fix | Delete
# to deal with packages that were imported by other systems.
[122] Fix | Delete
#
[123] Fix | Delete
# In the latter case (__ispkg__ == 0), there can't be any sub-
[124] Fix | Delete
# modules present, so we can just return.
[125] Fix | Delete
#
[126] Fix | Delete
# In both cases, since len(parts) == 1, the top_module is also
[127] Fix | Delete
# the "bottom" which is the defined return when a fromlist
[128] Fix | Delete
# exists.
[129] Fix | Delete
return top_module
[130] Fix | Delete
[131] Fix | Delete
importer = top_module.__dict__.get('__importer__')
[132] Fix | Delete
if importer:
[133] Fix | Delete
return importer._finish_import(top_module, parts[1:], fromlist)
[134] Fix | Delete
[135] Fix | Delete
# Grrr, some people "import os.path" or do "from os.path import ..."
[136] Fix | Delete
if len(parts) == 2 and hasattr(top_module, parts[1]):
[137] Fix | Delete
if fromlist:
[138] Fix | Delete
return getattr(top_module, parts[1])
[139] Fix | Delete
else:
[140] Fix | Delete
return top_module
[141] Fix | Delete
[142] Fix | Delete
# If the importer does not exist, then we have to bail. A missing
[143] Fix | Delete
# importer means that something else imported the module, and we have
[144] Fix | Delete
# no knowledge of how to get sub-modules out of the thing.
[145] Fix | Delete
raise ImportError, 'No module named ' + fqname
[146] Fix | Delete
[147] Fix | Delete
def _determine_import_context(self, globals):
[148] Fix | Delete
"""Returns the context in which a module should be imported.
[149] Fix | Delete
[150] Fix | Delete
The context could be a loaded (package) module and the imported module
[151] Fix | Delete
will be looked for within that package. The context could also be None,
[152] Fix | Delete
meaning there is no context -- the module should be looked for as a
[153] Fix | Delete
"top-level" module.
[154] Fix | Delete
"""
[155] Fix | Delete
[156] Fix | Delete
if not globals or not globals.get('__importer__'):
[157] Fix | Delete
# globals does not refer to one of our modules or packages. That
[158] Fix | Delete
# implies there is no relative import context (as far as we are
[159] Fix | Delete
# concerned), and it should just pick it off the standard path.
[160] Fix | Delete
return None
[161] Fix | Delete
[162] Fix | Delete
# The globals refer to a module or package of ours. It will define
[163] Fix | Delete
# the context of the new import. Get the module/package fqname.
[164] Fix | Delete
parent_fqname = globals['__name__']
[165] Fix | Delete
[166] Fix | Delete
# if a package is performing the import, then return itself (imports
[167] Fix | Delete
# refer to pkg contents)
[168] Fix | Delete
if globals['__ispkg__']:
[169] Fix | Delete
parent = sys.modules[parent_fqname]
[170] Fix | Delete
assert globals is parent.__dict__
[171] Fix | Delete
return parent
[172] Fix | Delete
[173] Fix | Delete
i = parent_fqname.rfind('.')
[174] Fix | Delete
[175] Fix | Delete
# a module outside of a package has no particular import context
[176] Fix | Delete
if i == -1:
[177] Fix | Delete
return None
[178] Fix | Delete
[179] Fix | Delete
# if a module in a package is performing the import, then return the
[180] Fix | Delete
# package (imports refer to siblings)
[181] Fix | Delete
parent_fqname = parent_fqname[:i]
[182] Fix | Delete
parent = sys.modules[parent_fqname]
[183] Fix | Delete
assert parent.__name__ == parent_fqname
[184] Fix | Delete
return parent
[185] Fix | Delete
[186] Fix | Delete
def _import_top_module(self, name):
[187] Fix | Delete
# scan sys.path looking for a location in the filesystem that contains
[188] Fix | Delete
# the module, or an Importer object that can import the module.
[189] Fix | Delete
for item in sys.path:
[190] Fix | Delete
if isinstance(item, _StringType):
[191] Fix | Delete
module = self.fs_imp.import_from_dir(item, name)
[192] Fix | Delete
else:
[193] Fix | Delete
module = item.import_top(name)
[194] Fix | Delete
if module:
[195] Fix | Delete
return module
[196] Fix | Delete
return None
[197] Fix | Delete
[198] Fix | Delete
def _reload_hook(self, module):
[199] Fix | Delete
"Python calls this hook to reload a module."
[200] Fix | Delete
[201] Fix | Delete
# reloading of a module may or may not be possible (depending on the
[202] Fix | Delete
# importer), but at least we can validate that it's ours to reload
[203] Fix | Delete
importer = module.__dict__.get('__importer__')
[204] Fix | Delete
if not importer:
[205] Fix | Delete
### oops. now what...
[206] Fix | Delete
pass
[207] Fix | Delete
[208] Fix | Delete
# okay. it is using the imputil system, and we must delegate it, but
[209] Fix | Delete
# we don't know what to do (yet)
[210] Fix | Delete
### we should blast the module dict and do another get_code(). need to
[211] Fix | Delete
### flesh this out and add proper docco...
[212] Fix | Delete
raise SystemError, "reload not yet implemented"
[213] Fix | Delete
[214] Fix | Delete
[215] Fix | Delete
class Importer:
[216] Fix | Delete
"Base class for replacing standard import functions."
[217] Fix | Delete
[218] Fix | Delete
def import_top(self, name):
[219] Fix | Delete
"Import a top-level module."
[220] Fix | Delete
return self._import_one(None, name, name)
[221] Fix | Delete
[222] Fix | Delete
######################################################################
[223] Fix | Delete
#
[224] Fix | Delete
# PRIVATE METHODS
[225] Fix | Delete
#
[226] Fix | Delete
def _finish_import(self, top, parts, fromlist):
[227] Fix | Delete
# if "a.b.c" was provided, then load the ".b.c" portion down from
[228] Fix | Delete
# below the top-level module.
[229] Fix | Delete
bottom = self._load_tail(top, parts)
[230] Fix | Delete
[231] Fix | Delete
# if the form is "import a.b.c", then return "a"
[232] Fix | Delete
if not fromlist:
[233] Fix | Delete
# no fromlist: return the top of the import tree
[234] Fix | Delete
return top
[235] Fix | Delete
[236] Fix | Delete
# the top module was imported by self.
[237] Fix | Delete
#
[238] Fix | Delete
# this means that the bottom module was also imported by self (just
[239] Fix | Delete
# now, or in the past and we fetched it from sys.modules).
[240] Fix | Delete
#
[241] Fix | Delete
# since we imported/handled the bottom module, this means that we can
[242] Fix | Delete
# also handle its fromlist (and reliably use __ispkg__).
[243] Fix | Delete
[244] Fix | Delete
# if the bottom node is a package, then (potentially) import some
[245] Fix | Delete
# modules.
[246] Fix | Delete
#
[247] Fix | Delete
# note: if it is not a package, then "fromlist" refers to names in
[248] Fix | Delete
# the bottom module rather than modules.
[249] Fix | Delete
# note: for a mix of names and modules in the fromlist, we will
[250] Fix | Delete
# import all modules and insert those into the namespace of
[251] Fix | Delete
# the package module. Python will pick up all fromlist names
[252] Fix | Delete
# from the bottom (package) module; some will be modules that
[253] Fix | Delete
# we imported and stored in the namespace, others are expected
[254] Fix | Delete
# to be present already.
[255] Fix | Delete
if bottom.__ispkg__:
[256] Fix | Delete
self._import_fromlist(bottom, fromlist)
[257] Fix | Delete
[258] Fix | Delete
# if the form is "from a.b import c, d" then return "b"
[259] Fix | Delete
return bottom
[260] Fix | Delete
[261] Fix | Delete
def _import_one(self, parent, modname, fqname):
[262] Fix | Delete
"Import a single module."
[263] Fix | Delete
[264] Fix | Delete
# has the module already been imported?
[265] Fix | Delete
try:
[266] Fix | Delete
return sys.modules[fqname]
[267] Fix | Delete
except KeyError:
[268] Fix | Delete
pass
[269] Fix | Delete
[270] Fix | Delete
# load the module's code, or fetch the module itself
[271] Fix | Delete
result = self.get_code(parent, modname, fqname)
[272] Fix | Delete
if result is None:
[273] Fix | Delete
return None
[274] Fix | Delete
[275] Fix | Delete
module = self._process_result(result, fqname)
[276] Fix | Delete
[277] Fix | Delete
# insert the module into its parent
[278] Fix | Delete
if parent:
[279] Fix | Delete
setattr(parent, modname, module)
[280] Fix | Delete
return module
[281] Fix | Delete
[282] Fix | Delete
def _process_result(self, result, fqname):
[283] Fix | Delete
ispkg, code, values = result
[284] Fix | Delete
# did get_code() return an actual module? (rather than a code object)
[285] Fix | Delete
is_module = isinstance(code, _ModuleType)
[286] Fix | Delete
[287] Fix | Delete
# use the returned module, or create a new one to exec code into
[288] Fix | Delete
if is_module:
[289] Fix | Delete
module = code
[290] Fix | Delete
else:
[291] Fix | Delete
module = imp.new_module(fqname)
[292] Fix | Delete
[293] Fix | Delete
### record packages a bit differently??
[294] Fix | Delete
module.__importer__ = self
[295] Fix | Delete
module.__ispkg__ = ispkg
[296] Fix | Delete
[297] Fix | Delete
# insert additional values into the module (before executing the code)
[298] Fix | Delete
module.__dict__.update(values)
[299] Fix | Delete
[300] Fix | Delete
# the module is almost ready... make it visible
[301] Fix | Delete
sys.modules[fqname] = module
[302] Fix | Delete
[303] Fix | Delete
# execute the code within the module's namespace
[304] Fix | Delete
if not is_module:
[305] Fix | Delete
try:
[306] Fix | Delete
exec code in module.__dict__
[307] Fix | Delete
except:
[308] Fix | Delete
if fqname in sys.modules:
[309] Fix | Delete
del sys.modules[fqname]
[310] Fix | Delete
raise
[311] Fix | Delete
[312] Fix | Delete
# fetch from sys.modules instead of returning module directly.
[313] Fix | Delete
# also make module's __name__ agree with fqname, in case
[314] Fix | Delete
# the "exec code in module.__dict__" played games on us.
[315] Fix | Delete
module = sys.modules[fqname]
[316] Fix | Delete
module.__name__ = fqname
[317] Fix | Delete
return module
[318] Fix | Delete
[319] Fix | Delete
def _load_tail(self, m, parts):
[320] Fix | Delete
"""Import the rest of the modules, down from the top-level module.
[321] Fix | Delete
[322] Fix | Delete
Returns the last module in the dotted list of modules.
[323] Fix | Delete
"""
[324] Fix | Delete
for part in parts:
[325] Fix | Delete
fqname = "%s.%s" % (m.__name__, part)
[326] Fix | Delete
m = self._import_one(m, part, fqname)
[327] Fix | Delete
if not m:
[328] Fix | Delete
raise ImportError, "No module named " + fqname
[329] Fix | Delete
return m
[330] Fix | Delete
[331] Fix | Delete
def _import_fromlist(self, package, fromlist):
[332] Fix | Delete
'Import any sub-modules in the "from" list.'
[333] Fix | Delete
[334] Fix | Delete
# if '*' is present in the fromlist, then look for the '__all__'
[335] Fix | Delete
# variable to find additional items (modules) to import.
[336] Fix | Delete
if '*' in fromlist:
[337] Fix | Delete
fromlist = list(fromlist) + \
[338] Fix | Delete
list(package.__dict__.get('__all__', []))
[339] Fix | Delete
[340] Fix | Delete
for sub in fromlist:
[341] Fix | Delete
# if the name is already present, then don't try to import it (it
[342] Fix | Delete
# might not be a module!).
[343] Fix | Delete
if sub != '*' and not hasattr(package, sub):
[344] Fix | Delete
subname = "%s.%s" % (package.__name__, sub)
[345] Fix | Delete
submod = self._import_one(package, sub, subname)
[346] Fix | Delete
if not submod:
[347] Fix | Delete
raise ImportError, "cannot import name " + subname
[348] Fix | Delete
[349] Fix | Delete
def _do_import(self, parent, parts, fromlist):
[350] Fix | Delete
"""Attempt to import the module relative to parent.
[351] Fix | Delete
[352] Fix | Delete
This method is used when the import context specifies that <self>
[353] Fix | Delete
imported the parent module.
[354] Fix | Delete
"""
[355] Fix | Delete
top_name = parts[0]
[356] Fix | Delete
top_fqname = parent.__name__ + '.' + top_name
[357] Fix | Delete
top_module = self._import_one(parent, top_name, top_fqname)
[358] Fix | Delete
if not top_module:
[359] Fix | Delete
# this importer and parent could not find the module (relatively)
[360] Fix | Delete
return None
[361] Fix | Delete
[362] Fix | Delete
return self._finish_import(top_module, parts[1:], fromlist)
[363] Fix | Delete
[364] Fix | Delete
######################################################################
[365] Fix | Delete
#
[366] Fix | Delete
# METHODS TO OVERRIDE
[367] Fix | Delete
#
[368] Fix | Delete
def get_code(self, parent, modname, fqname):
[369] Fix | Delete
"""Find and retrieve the code for the given module.
[370] Fix | Delete
[371] Fix | Delete
parent specifies a parent module to define a context for importing. It
[372] Fix | Delete
may be None, indicating no particular context for the search.
[373] Fix | Delete
[374] Fix | Delete
modname specifies a single module (not dotted) within the parent.
[375] Fix | Delete
[376] Fix | Delete
fqname specifies the fully-qualified module name. This is a
[377] Fix | Delete
(potentially) dotted name from the "root" of the module namespace
[378] Fix | Delete
down to the modname.
[379] Fix | Delete
If there is no parent, then modname==fqname.
[380] Fix | Delete
[381] Fix | Delete
This method should return None, or a 3-tuple.
[382] Fix | Delete
[383] Fix | Delete
* If the module was not found, then None should be returned.
[384] Fix | Delete
[385] Fix | Delete
* The first item of the 2- or 3-tuple should be the integer 0 or 1,
[386] Fix | Delete
specifying whether the module that was found is a package or not.
[387] Fix | Delete
[388] Fix | Delete
* The second item is the code object for the module (it will be
[389] Fix | Delete
executed within the new module's namespace). This item can also
[390] Fix | Delete
be a fully-loaded module object (e.g. loaded from a shared lib).
[391] Fix | Delete
[392] Fix | Delete
* The third item is a dictionary of name/value pairs that will be
[393] Fix | Delete
inserted into new module before the code object is executed. This
[394] Fix | Delete
is provided in case the module's code expects certain values (such
[395] Fix | Delete
as where the module was found). When the second item is a module
[396] Fix | Delete
object, then these names/values will be inserted *after* the module
[397] Fix | Delete
has been loaded/initialized.
[398] Fix | Delete
"""
[399] Fix | Delete
raise RuntimeError, "get_code not implemented"
[400] Fix | Delete
[401] Fix | Delete
[402] Fix | Delete
######################################################################
[403] Fix | Delete
#
[404] Fix | Delete
# Some handy stuff for the Importers
[405] Fix | Delete
#
[406] Fix | Delete
[407] Fix | Delete
# byte-compiled file suffix character
[408] Fix | Delete
_suffix_char = __debug__ and 'c' or 'o'
[409] Fix | Delete
[410] Fix | Delete
# byte-compiled file suffix
[411] Fix | Delete
_suffix = '.py' + _suffix_char
[412] Fix | Delete
[413] Fix | Delete
def _compile(pathname, timestamp):
[414] Fix | Delete
"""Compile (and cache) a Python source file.
[415] Fix | Delete
[416] Fix | Delete
The file specified by <pathname> is compiled to a code object and
[417] Fix | Delete
returned.
[418] Fix | Delete
[419] Fix | Delete
Presuming the appropriate privileges exist, the bytecodes will be
[420] Fix | Delete
saved back to the filesystem for future imports. The source file's
[421] Fix | Delete
modification timestamp must be provided as a Long value.
[422] Fix | Delete
"""
[423] Fix | Delete
codestring = open(pathname, 'rU').read()
[424] Fix | Delete
if codestring and codestring[-1] != '\n':
[425] Fix | Delete
codestring = codestring + '\n'
[426] Fix | Delete
code = __builtin__.compile(codestring, pathname, 'exec')
[427] Fix | Delete
[428] Fix | Delete
# try to cache the compiled code
[429] Fix | Delete
try:
[430] Fix | Delete
f = open(pathname + _suffix_char, 'wb')
[431] Fix | Delete
except IOError:
[432] Fix | Delete
pass
[433] Fix | Delete
else:
[434] Fix | Delete
f.write('\0\0\0\0')
[435] Fix | Delete
f.write(struct.pack('<I', timestamp))
[436] Fix | Delete
marshal.dump(code, f)
[437] Fix | Delete
f.flush()
[438] Fix | Delete
f.seek(0, 0)
[439] Fix | Delete
f.write(imp.get_magic())
[440] Fix | Delete
f.close()
[441] Fix | Delete
[442] Fix | Delete
return code
[443] Fix | Delete
[444] Fix | Delete
_os_stat = _os_path_join = None
[445] Fix | Delete
def _os_bootstrap():
[446] Fix | Delete
"Set up 'os' module replacement functions for use during import bootstrap."
[447] Fix | Delete
[448] Fix | Delete
names = sys.builtin_module_names
[449] Fix | Delete
[450] Fix | Delete
join = None
[451] Fix | Delete
if 'posix' in names:
[452] Fix | Delete
sep = '/'
[453] Fix | Delete
from posix import stat
[454] Fix | Delete
elif 'nt' in names:
[455] Fix | Delete
sep = '\\'
[456] Fix | Delete
from nt import stat
[457] Fix | Delete
elif 'dos' in names:
[458] Fix | Delete
sep = '\\'
[459] Fix | Delete
from dos import stat
[460] Fix | Delete
elif 'os2' in names:
[461] Fix | Delete
sep = '\\'
[462] Fix | Delete
from os2 import stat
[463] Fix | Delete
else:
[464] Fix | Delete
raise ImportError, 'no os specific module found'
[465] Fix | Delete
[466] Fix | Delete
if join is None:
[467] Fix | Delete
def join(a, b, sep=sep):
[468] Fix | Delete
if a == '':
[469] Fix | Delete
return b
[470] Fix | Delete
lastchar = a[-1:]
[471] Fix | Delete
if lastchar == '/' or lastchar == sep:
[472] Fix | Delete
return a + b
[473] Fix | Delete
return a + sep + b
[474] Fix | Delete
[475] Fix | Delete
global _os_stat
[476] Fix | Delete
_os_stat = stat
[477] Fix | Delete
[478] Fix | Delete
global _os_path_join
[479] Fix | Delete
_os_path_join = join
[480] Fix | Delete
[481] Fix | Delete
def _os_path_isdir(pathname):
[482] Fix | Delete
"Local replacement for os.path.isdir()."
[483] Fix | Delete
try:
[484] Fix | Delete
s = _os_stat(pathname)
[485] Fix | Delete
except OSError:
[486] Fix | Delete
return None
[487] Fix | Delete
return (s.st_mode & 0170000) == 0040000
[488] Fix | Delete
[489] Fix | Delete
def _timestamp(pathname):
[490] Fix | Delete
"Return the file modification time as a Long."
[491] Fix | Delete
try:
[492] Fix | Delete
s = _os_stat(pathname)
[493] Fix | Delete
except OSError:
[494] Fix | Delete
return None
[495] Fix | Delete
return long(s.st_mtime)
[496] Fix | Delete
[497] Fix | Delete
[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