From c529beb903ae13dfbe682bbc93f22e897c91b183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 20 Nov 2024 14:36:44 +0100 Subject: [PATCH] Merge the filters --- c2cwsgiutils/debug/_views.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/c2cwsgiutils/debug/_views.py b/c2cwsgiutils/debug/_views.py index d30a0e56b..1696412e8 100644 --- a/c2cwsgiutils/debug/_views.py +++ b/c2cwsgiutils/debug/_views.py @@ -189,10 +189,17 @@ def _show_refs(request: pyramid.request.Request) -> pyramid.response.Response: args["extra_info"] = lambda obj: f"{get_size(obj) / 1024:.3f} kb\n{id(obj)}" result = StringIO() - if request.params.get("backrefs", "") != "": - objgraph.show_backrefs(objs, output=result, **args) - else: - objgraph.show_refs(objs, output=result, filter=lambda x: not objgraph.inspect.isclass(x), **args) + if request.params.get("backrefs", "") == "": + + def new_filter(x): + return not objgraph.inspect.isclass(x) + + if "filter" in args: + old_filter = args["filter"] + args["filter"] = lambda x: old_filter(x) and new_filter(x) + else: + args["filter"] = new_filter + objgraph.show_backrefs(objs, output=result, **args) request.response.content_type = "text/vnd.graphviz" request.response.text = result.getvalue()