I'm working on a module that reports which methods can be invoked by a given overlord (minion-to-minion) in the presence of acls. To do this, I've been recreating a bit of what the system list_methods() module does. I've found that I can get into an infinite recursion because of how the handlers are discovered. I'm attaching a patch that allows me to break this recursive loop by placing the problematic code into a private method. Note that it's just a reordering of the checks that tell if a given method is a valid public handler. -Toshio
From 5b70b579ec294cf2d37775bf71a58a4b7dcd1670 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi <toshio@xxxxxxxxxxxxxxxxx> Date: Tue, 27 Apr 2010 17:15:45 -0400 Subject: [PATCH 2/2] Fix for potential infinite recursion --- func/utils.py | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/func/utils.py b/func/utils.py index f184013..1c4d94c 100644 --- a/func/utils.py +++ b/func/utils.py @@ -57,10 +57,14 @@ def get_formated_jobid(**id_pack): return job_id def is_public_valid_method(obj, attr, blacklist=[]): - if inspect.ismethod(getattr(obj, attr)) and attr[0] != '_': - for b in blacklist: - if attr==b: - return False + # Note: the order can be important here. func modules that try to inspect + # the list of available methods may run into inifinite recursion issues if + # getattr() is called on them. They can work around this by placing the + # problematic code in a private method that's called from their public + # method if we perform the check for a leading underscore before the check + # that calls getattr() + if attr[0] != '_' and attr not in blacklist and \ + inspect.ismethod(getattr(obj, attr)): return True return False -- 1.6.6.1
Attachment:
pgpwA2QiwLIqU.pgp
Description: PGP signature
_______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list