diff --git a/product/ERP5Type/dynamic/component_package.py b/product/ERP5Type/dynamic/component_package.py index 12bed78e01725e85f6a6aba165f317856ad7a59f..d904bf2b86bef65d1d9981632db2f50e61a86323 100644 --- a/product/ERP5Type/dynamic/component_package.py +++ b/product/ERP5Type/dynamic/component_package.py @@ -339,13 +339,4 @@ class ComponentDynamicPackage(ModuleType): # the meantime del sys.modules[module_name] - # Delete linecache data to get updated source code (__file__ attribute - # (<ComponentID>) is used as linecache key) - import linecache - try: - del linecache.cache[getattr(package, name).__file__] - # __file__ may not be defined - except (AttributeError, KeyError): - pass - delattr(package, name) diff --git a/product/ERP5Type/patches/PythonScript.py b/product/ERP5Type/patches/PythonScript.py index d84a904b249642af366d6eb94c8e6d60698ae92d..326ea2fa75c6b57365584babdba24f8fae2c8579 100644 --- a/product/ERP5Type/patches/PythonScript.py +++ b/product/ERP5Type/patches/PythonScript.py @@ -14,22 +14,6 @@ from Products.PythonScripts.PythonScript import PythonScript from OFS.misc_ import p_ from App.ImageFile import ImageFile -PythonScript_write = PythonScript.write -def write(self, text): - """ - Change the Python Script and purge linecache cache entry (meaningful for any - module relying on linecache, such as traceback and pdb) - """ - PythonScript_write(self, text) - - import linecache - try: - del linecache.cache[self.get_filepath()] - except KeyError: - pass - -PythonScript.write = write - def haveProxyRole(self): """if a script has proxy role, return True""" return bool(self._proxy_roles) diff --git a/product/ERP5Type/patches/python.py b/product/ERP5Type/patches/python.py index b9746d7cfd9ffd075ff2065aeabe7dd9360992ad..f1e155f56b17b33b232e0b9825d4512f20e7490d 100644 --- a/product/ERP5Type/patches/python.py +++ b/product/ERP5Type/patches/python.py @@ -100,48 +100,29 @@ if 1: from docutils import utils utils.relative_path = lambda source, target: os.path.abspath(target) -# Patch of linecache module (used in traceback and pdb module) to display ZODB -# Components source code properly without requiring to create a temporary file -# on the filesystem import linecache linecache_getlines = linecache.getlines def getlines(filename, module_globals=None): """ - The filename is always '<string>' for any code executed by exec(). ZODB - Component modules always set __file__ attribute to <erp5.component...> and - 'Script (Python)' for Zope Python Scripts. - - The original getlines() will be called which look into the cache and if not - available, call updatecache. - """ - if ((filename == '<string>' or filename == 'Script (Python)') - and module_globals and '__file__' in module_globals): - filename = module_globals['__file__'] - - return linecache_getlines(filename, module_globals) - -linecache.getlines = getlines - -linecache_updatecache = linecache.updatecache -def updatecache(filename, module_globals=None): - """ - Original updatecache requires a filename which doesn't match <.*>, which is - strange considering that it then looks whether the module has been loaded - through PEP 302 Loader, but it is perhaps to be more generic. Anyhow, <> is - really needed to differenciate files on the filesystem to the ones only in - memory... - - Also, get source code of Zope Python Script and store it in the linecache - cache as well (using __file__ module attribute equals to: 'Script - (Python):ABSOLUTE_URL'). See PythonScript.py patch as well to remove cache - entry when a PythonScript is modified. + Patch of linecache module (used in traceback and pdb module) to display ZODB + Components and Python Script source code properly without requiring to + create a temporary file on the filesystem + + The filename is always '<string>' for any code executed by exec() (ZODB + Components) and '(FILENAME)?Script \(Python\)' for Zope Python Scripts. + + linecache.cache filled by linecache.updatecache() called by the original + linecache.getlines() is bypassed for ZODB Components and Python Script to + avoid getting inconsistent source code. Having no cache could be an issue if + performances would be required here but as linecache module is only called + by traceback and pdb modules not used often, this should not be an issue. """ if filename and module_globals: data = None # Get source code of ZODB Components (following PEP 302) - if filename[0] == '<' and filename[-1] == '>' and '__loader__' in module_globals: + if filename == '<string>' and '__loader__' in module_globals: name = module_globals.get('__name__') loader = module_globals['__loader__'] get_source = getattr(loader, 'get_source', None) @@ -150,20 +131,15 @@ def updatecache(filename, module_globals=None): data = get_source(name) except (ImportError, AttributeError): pass - else: - if data is None: - return [] # Get source code of Zope Python Script - elif filename.startswith('Script (Python)') and 'script' in module_globals: + elif 'Script (Python)' in filename and 'script' in module_globals: data = module_globals['script'].body() if data is not None: - data_len = len(data) data = [line + '\n' for line in data.splitlines()] - linecache.cache[filename] = (data_len, None, data, filename) return data - return linecache_updatecache(filename, module_globals) + return linecache_getlines(filename, module_globals) -linecache.updatecache = updatecache +linecache.getlines = getlines