/usr/share/pyshared/sqlobject/util/moduleloader.py is in python-sqlobject 0.12.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import sys
import imp
def load_module(module_name):
mod = __import__(module_name)
components = module_name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
def load_module_from_name(filename, module_name):
if sys.modules.has_key(module_name):
return sys.modules[module_name]
init_filename = os.path.join(os.path.dirname(filename), '__init__.py')
if not os.path.exists(init_filename):
try:
f = open(init_filename, 'w')
except (OSError, IOError), e:
raise IOError(
'Cannot write __init__.py file into directory %s (%s)\n'
% (os.path.dirname(filename), e))
f.write('#\n')
f.close()
fp = None
if sys.modules.has_key(module_name):
return sys.modules[module_name]
if '.' in module_name:
parent_name = '.'.join(module_name.split('.')[:-1])
base_name = module_name.split('.')[-1]
parent = load_module_from_name(os.path.dirname(filename),
parent_name)
else:
base_name = module_name
fp = None
try:
fp, pathname, stuff = imp.find_module(
base_name, [os.path.dirname(filename)])
module = imp.load_module(module_name, fp, pathname, stuff)
finally:
if fp is not None:
fp.close()
return module
|