From 1a95a9fc1738cc9bfda02e52c3a1e342a91e909b Mon Sep 17 00:00:00 2001 From: Vincent Duvert Date: Sat, 5 Jun 2021 10:16:03 +0200 Subject: [PATCH] Shell: do not access properties on startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the way the shell finds methods to add to the locals on startup: the methods are queried on the object’s class, rather than the object itself. This allows detecting if an object’s member is a property and ignore it, rather than accessing the property. Attributes whose name starts by ‘_’ are also now ignored, which avoids importing private methods or Python magic methods in the shell namespace. Fixes spurious accesses to ProxyUtils’s SIMD properties (b, h, etc) on shell startup, which caused a ProxyCommandError if m1n1 is not recent enough. Signed-off-by: Vincent Duvert --- proxyclient/shell.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/proxyclient/shell.py b/proxyclient/shell.py index bc8c4d1e..c9ff344b 100755 --- a/proxyclient/shell.py +++ b/proxyclient/shell.py @@ -65,13 +65,19 @@ def run_shell(locals, msg=None, exitmsg=None): if "utils" in locals and "u" not in locals: locals["u"] = locals["utils"] - for obj in ("iface", "p", "u"): - if obj in locals: - for attr in dir(locals[obj]): - if attr not in locals: - v = getattr(locals[obj], attr) - if callable(v): - locals[attr] = v + for obj_name in ("iface", "p", "u"): + obj = locals.get(obj_name) + obj_class = type(obj) + if obj is None: + continue + + for attr in dir(obj_class): + if attr in locals or attr.startswith('_'): + continue + + member = getattr(obj_class, attr) + if callable(member) and not isinstance(member, property): + locals[attr] = getattr(obj, attr) for attr in dir(sysreg): locals[attr] = getattr(sysreg, attr)