launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #06693
@ProxyFactory functions in lieu of methods
Here's an idea that's in line with my mini-lightning talk in which I encouraged the use of functions when appropriate.
If you have a function that should always be importable/usable by any user, but that should hand out proxied objects, you can use zope.security.proxy.ProxyFactory as a function decorator. This will Just Work without further configuration.
This is much lighter-weight than adding it to a proxied utility or a model object. If you have some code that you don't feel ought to muddy up the model with Yet Another Method that maybe serves a single client call, and that fits the description I gave above, give it a try!
It's also somewhat lighter-weight than proxying an entire module, which zope.security also supports but we don't use.
For instance:
@ProxyFactory
def get_some_people(...):
return IStore(Person).find(Person, conditions...)
Now the result set will be proxied, so the Person objects will be proxied, and their attributes, and so on.
Virally yrs,
Gary