Commit 2fb1b3f1 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Cosmetic: rename variables to more meaningful names in Component dynamic package.

parent 2a7ab878
...@@ -191,34 +191,34 @@ class ComponentDynamicPackage(ModuleType): ...@@ -191,34 +191,34 @@ class ComponentDynamicPackage(ModuleType):
properly in find_module(). properly in find_module().
""" """
site = getSite() site = getSite()
component_name = fullname[len(self._namespace_prefix):] name = fullname[len(self._namespace_prefix):]
if component_name.endswith('_version'): if name.endswith('_version'):
version = component_name[:-self.__version_suffix_len] version = name[:-self.__version_suffix_len]
return (version in site.getVersionPriorityNameList() and return (version in site.getVersionPriorityNameList() and
self._getVersionPackage(version) or None) self._getVersionPackage(version) or None)
component_id_alias = None module_fullname_alias = None
version_package_name = component_name[:-self.__version_suffix_len] version_package_name = name[:-self.__version_suffix_len]
if '.' in component_name: if '.' in name:
try: try:
version, component_name = component_name.split('.') version, name = name.split('.')
version = version[:-self.__version_suffix_len] version = version[:-self.__version_suffix_len]
except ValueError, error: except ValueError, error:
raise ImportError("%s: should be %s.VERSION.COMPONENT_REFERENCE (%s)" % \ raise ImportError("%s: should be %s.VERSION.COMPONENT_REFERENCE (%s)" % \
(fullname, self._namespace, error)) (fullname, self._namespace, error))
try: try:
component = self._registry_dict[component_name][version] component = self._registry_dict[name][version]
except KeyError: except KeyError:
raise ImportError("%s: version %s of Component %s could not be found" % \ raise ImportError("%s: version %s of Component %s could not be found" % \
(fullname, version, component_name)) (fullname, version, name))
else: else:
try: try:
component_version_dict = self._registry_dict[component_name] component_version_dict = self._registry_dict[name]
except KeyError: except KeyError:
raise ImportError("%s: Component %s could not be found" % (fullname, raise ImportError("%s: Component %s could not be found" % (fullname,
component_name)) name))
for version in site.getVersionPriorityNameList(): for version in site.getVersionPriorityNameList():
component = component_version_dict.get(version) component = component_version_dict.get(version)
...@@ -226,55 +226,54 @@ class ComponentDynamicPackage(ModuleType): ...@@ -226,55 +226,54 @@ class ComponentDynamicPackage(ModuleType):
break break
else: else:
raise ImportError("%s: no version of Component %s in Site priority" % \ raise ImportError("%s: no version of Component %s in Site priority" % \
(fullname, component_name)) (fullname, name))
try: try:
module = getattr(getattr(self, version + '_version'), component_name) module = getattr(getattr(self, version + '_version'), name)
except AttributeError: except AttributeError:
pass pass
else: else:
with self._load_module_lock: with self._load_module_lock:
setattr(self._getVersionPackage(version), component_name, module) setattr(self._getVersionPackage(version), name, module)
return module return module
component_id_alias = self._namespace + '.' + component_name module_fullname_alias = self._namespace + '.' + name
component_id = '%s.%s_version.%s' % (self._namespace, version, module_fullname = '%s.%s_version.%s' % (self._namespace, version, name)
component_name)
with self._load_module_lock: with self._load_module_lock:
new_module = ModuleType(component_id, component.getDescription()) module = ModuleType(module_fullname, component.getDescription())
# The module *must* be in sys.modules before executing the code in case # The module *must* be in sys.modules before executing the code in case
# the module code imports (directly or indirectly) itself (see PEP 302) # the module code imports (directly or indirectly) itself (see PEP 302)
sys.modules[component_id] = new_module sys.modules[module_fullname] = module
if component_id_alias: if module_fullname_alias:
sys.modules[component_id_alias] = new_module sys.modules[module_fullname_alias] = module
# This must be set for imports at least (see PEP 302) # This must be set for imports at least (see PEP 302)
new_module.__file__ = '<' + component.getId() + '>' module.__file__ = '<' + component.getId() + '>'
try: try:
component.load(new_module.__dict__, validated_only=True) component.load(module.__dict__, validated_only=True)
except Exception, error: except Exception, error:
del sys.modules[component_id] del sys.modules[module_fullname]
if component_id_alias: if module_fullname_alias:
del sys.modules[component_id_alias] del sys.modules[module_fullname_alias]
raise ImportError("%s: cannot load Component %s (%s)" % (fullname, raise ImportError("%s: cannot load Component %s (%s)" % (fullname,
component_name, name,
error)) error))
new_module.__path__ = [] module.__path__ = []
new_module.__loader__ = self module.__loader__ = self
new_module.__name__ = component_id module.__name__ = module_fullname
setattr(self._getVersionPackage(version), component_name, new_module) setattr(self._getVersionPackage(version), name, module)
if component_id_alias: if module_fullname_alias:
setattr(self, component_name, new_module) setattr(self, name, module)
return new_module return module
def reset(self, sub_package=None): def reset(self, sub_package=None):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment