[libpeas] Do not reveal Python loader internals in tracebacks
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Do not reveal Python loader internals in tracebacks
- Date: Tue, 20 Jan 2015 09:24:57 +0000 (UTC)
commit fc3d26ff0f12c16941e5ff0501b01316d8df8deb
Author: Garrett Regier <garrettregier gmail com>
Date: Tue Jan 20 01:13:45 2015 -0800
Do not reveal Python loader internals in tracebacks
This adds format_plugin_exception() which
removes all internal Python frames from the traceback.
https://bugzilla.gnome.org/show_bug.cgi?id=742349
loaders/python/peas-python-internal.c | 2 ++
loaders/python/peas-python-internal.py | 15 ++++++++++++++-
2 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/loaders/python/peas-python-internal.c b/loaders/python/peas-python-internal.c
index 227c1b5..dca8e61 100644
--- a/loaders/python/peas-python-internal.c
+++ b/loaders/python/peas-python-internal.c
@@ -116,6 +116,8 @@ peas_python_internal_new (gboolean already_initialized)
module = PyModule_New ("libpeas-internal");
goto_error_if_failed (module != NULL);
+ goto_error_if_failed (PyModule_AddStringConstant (module, "__file__",
+ "peas-python-internal.py") == 0);
goto_error_if_failed (PyModule_AddObject (module, "__builtins__",
builtins_module) == 0);
goto_error_if_failed (PyModule_AddObject (module, "ALREADY_INITIALIZED",
diff --git a/loaders/python/peas-python-internal.py b/loaders/python/peas-python-internal.py
index dcffaeb..d14b4d8 100644
--- a/loaders/python/peas-python-internal.py
+++ b/loaders/python/peas-python-internal.py
@@ -58,6 +58,19 @@ class Hooks(object):
# This is implemented by the plugin loader
raise NotImplementedError('Hooks.failed()')
+ @staticmethod
+ def format_plugin_exception():
+ formatted = traceback.format_exception(*sys.exc_info())
+
+ # Remove all mentions of this file
+ for i in range(len(formatted)):
+ if __file__ in formatted[i]:
+ while not formatted[i].startswith('Traceback'):
+ formatted[i] = ''
+ i -= 1
+
+ return ''.join(formatted)
+
def call(self, name, args, return_type):
try:
result = getattr(self, name)(*args)
@@ -99,7 +112,7 @@ class Hooks(object):
except:
module = None
self.failed("Error importing plugin '%s':\n%s" %
- (module_name, traceback.format_exc()))
+ (module_name, self.format_plugin_exception()))
else:
self.__extension_cache[module] = {}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]