Hi, Christoph.

Christoph said:
> Gustavo Narea schrieb:
> > 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 thught the problem was that is_met() needs the environment? So I guess
> you wanted to say that "overloader" stores the environment in an
> attribute when instantiated and then calls self.is_met(self._environ).

Oh, yes, I'm sorry. I meant to write:
"""
def __getattr__(self, name):
    original_class = self.get_predicate_checker(name)
    class BooleanPredicate(original_class):
        def __nonzero__(self,):
            return self.is_met(request.environ)  # <--- HERE
    return BooleanPredicate
"""


> By the way, isn't this pretty much the same idea as option 4) that had
> been proposed already here? http://trac.turbogears.org/ticket/2205

They're similar because both use __getattr__, but this will return a valid 
predicate, not a callable (which in turn returns True/False). So you'd be able 
to use the result like a normal predicate (i.e., as explained in the main 
docs, not in a way too specific to TG).


> One thing I don't like in this solution is all the overhead that makes
> things hard to understand and is bad for performance (your proposed
> get_predicate_checker even has a for loop in it).

I fully agree, but I believe it's the best compromise among the solutions 
proposed.

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