Commit d702bf05 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Use slice notation to remove prefixes/suffixes properly rather than replace().

parent 4a1dbd67
...@@ -3829,7 +3829,7 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem): ...@@ -3829,7 +3829,7 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem):
# does not set _archive with portal_components/ like # does not set _archive with portal_components/ like
# ObjectTemplateItem.__init__() # ObjectTemplateItem.__init__()
self._archive[name] = None self._archive[name] = None
del self._archive[name.replace('portal_components/', '')] del self._archive[name[len('portal_components/'):]]
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
path = self.__class__.__name__ + '/' path = self.__class__.__name__ + '/'
......
...@@ -72,7 +72,7 @@ class ComponentDynamicPackage(ModuleType): ...@@ -72,7 +72,7 @@ class ComponentDynamicPackage(ModuleType):
self._namespace = namespace self._namespace = namespace
self._namespace_prefix = namespace + '.' self._namespace_prefix = namespace + '.'
self._portal_type = portal_type self._portal_type = portal_type
self.__version_suffix_len = len('_version')
self._lock = threading.RLock() self._lock = threading.RLock()
# Add this module to sys.path for future imports # Add this module to sys.path for future imports
...@@ -135,11 +135,11 @@ class ComponentDynamicPackage(ModuleType): ...@@ -135,11 +135,11 @@ class ComponentDynamicPackage(ModuleType):
# __import__ will first try a relative import, for example # __import__ will first try a relative import, for example
# erp5.component.XXX.YYY.ZZZ where erp5.component.XXX.YYY is the current # erp5.component.XXX.YYY.ZZZ where erp5.component.XXX.YYY is the current
# Component where an import is done # Component where an import is done
name = fullname.replace(self._namespace_prefix, '') name = fullname[len(self._namespace_prefix):]
if '.' in name: if '.' in name:
try: try:
version, name = name.split('.') version, name = name.split('.')
version = version.replace('_version', '') version = version[:-self.__version_suffix_len]
except ValueError: except ValueError:
return None return None
...@@ -152,7 +152,7 @@ class ComponentDynamicPackage(ModuleType): ...@@ -152,7 +152,7 @@ class ComponentDynamicPackage(ModuleType):
# wrongly considered as importable and thus the actual filesystem class # wrongly considered as importable and thus the actual filesystem class
# ignored # ignored
elif (name not in self._registry_dict and elif (name not in self._registry_dict and
name.replace('_version', '') not in site.getVersionPriorityList()): name[:-self.__version_suffix_len] not in site.getVersionPriorityList()):
return None return None
return self return self
...@@ -176,18 +176,18 @@ class ComponentDynamicPackage(ModuleType): ...@@ -176,18 +176,18 @@ class ComponentDynamicPackage(ModuleType):
properly in find_module(). properly in find_module().
""" """
site = getSite() site = getSite()
component_name = fullname.replace(self._namespace_prefix, '') component_name = fullname[len(self._namespace_prefix):]
if component_name.endswith('_version'): if component_name.endswith('_version'):
version = component_name.replace('_version', '') version = component_name[:-self.__version_suffix_len]
return (version in site.getVersionPriorityList() and return (version in site.getVersionPriorityList() and
self._getVersionPackage(version) or None) self._getVersionPackage(version) or None)
component_id_alias = None component_id_alias = None
version_package_name = component_name.replace('_version', '') version_package_name = component_name[:-self.__version_suffix_len]
if '.' in component_name: if '.' in component_name:
try: try:
version, component_name = component_name.split('.') version, component_name = component_name.split('.')
version = version.replace('_version', '') version = version[:-self.__version_suffix_len]
except ValueError: except ValueError:
return None return 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