Hi everyone.

I've always agreed that it's absolutely handy to have predicate checkers act 
as booleans, but at the same time, I've been opposed to all the alternatives 
proposed to work around this because I consider them to have serious side-
effects, even the one I implemented by popular demand (the so-called 
"predicate booleanizers").

However, a new potential solution has popped into my head and I'd be happy 
with it, so let me propose it to see if it'd make you happy too.

We can use Python's overloading functionality like this:
"""
<p py_if='overloader.in_group("foo")'>This is a sensitive message!</p>
"""

Where "overloader" is a class instance with the __getattr__ method defined, so 
we can return the class "in_group" (the class itself, not an instance). This 
method will be implemented like this:
"""
def __getattr__(self, name):
    original_class = self.get_predicate_checker(name)
    class BooleanPredicate(original_class):
        def __nonzero__(self,):
            return self.is_met()
    return BooleanPredicate
"""

I'd be happy with this because it wouldn't affect repoze.what globally, and 
thus it wouldn't affect other software powered by repoze.what in the same 
environment.

And another great thing would be that we could replace tg.predicates in the 
template with this object and everything will be backwards compatible.

What do you think?

Cheers.
-- 
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to