Hello, Jorge et al.
Jorge said:
> > Maybe because it's one of the basic things you first learn in Python? Try
> > this simple experiment if you don't believe me:
> >
> > Create a module which has the contents below:
> > """
> > class MockObject(object):
> > def __init__(self):
> > print "Initialized"
> >
> > class CoolController(object):
> > allow_only = MockObject()
> >
> > def my_action(self,):
> > pass
> > my_action.predicate = MockObject()
> > """
> >
> > Now try to import it from another module (just import it, don't do
> > anything else) and tell me what you got. Next, guess why you got that.
> > Hint: Anything that is outside a function/method is evaluated when the
> > module is loaded, even decorators and their arguments.
>
> did you missed the part where I said that syntax will need to change?
> we'll need something like
>
> allow_only = autorize(MockObject())
Neither that or something similar would work.
There's only one way to make it work that way: Putting that inside a function
(or a method); otherwise, it will always be evaluated when the module is
loaded. Something like this:
"""
class MyController():
def allow_only(self):
....
"""
You can't do that without it being wrapped by a function.
> > I repeat: They'd be evaluated when the module is loaded and thus
> > .allow_only and @require will just receive a True or a False, which is
> > obviously not going to change on a request-basis.
>
> I'm more than willing to complicate the allow_only and require
> interfaces in order to simplify the "query api" as you are going to
> use the "query" part many more times than then "require" api.
>
> As I said a couple of emails ago you keep trying to stick with the
> status quo. If that is your api AND you CALL the function on each
> request, just like __before__ is used in "roll your own" pylons auth
> systems.
I'm not trying to stick to anything. I'm absolutely open to review and comment
on alternatives, and even get them applied in any of the packages I maintain
if it's a good alternative.
But this is not even an alternative, because there's no way you could get that
thing working in Python. No matter what syntax you could use: If it's a
function that returns True or False, it won't ever work.
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
-~----------~----~----~----~------~----~------~--~---