Re: Python scripts
Laurence Rowe <[email protected]>
| Newsgroups | gmane.comp.web.zope.general |
|---|---|
| Message-ID | <CAOycyLRo=H3=BXKCfUomKG6z5+49ziE80TCDzU1n=JW_XQO+=Q@mail.gmail.com> |
On 6 July 2012 16:36, Richard Harley <[email protected]> wrote: > That works great, thanks. So there is no way to do this across, say, a > folder with hundreds of scripts in without duplicating the code in each > individually? For one Plone hotfix we took the approach of blacklisting certain scripts by monkey-patching Bindings._bindAndExec (Bindings is a superclass of PythonScript): from Shared.DC.Scripts.Bindings import Bindings from zExceptions import Forbidden DO_NOT_PUBLISH = [ 'script_id', ... ] def _patched_bindAndExec(self, args, kw, caller_namespace): '''Prepares the bound information and calls _exec(), possibly with a namespace. ''' template_id = hasattr(self, 'getId') and self.getId() or '' request = getattr(self, 'REQUEST', None) if (template_id and request and template_id in DO_NOT_PUBLISH and request.get('PUBLISHED') is self): raise Forbidden('Script may not be published.') return self._original_bindAndExec(args, kw, caller_namespace) Bindings._original_bindAndExec = Bindings._bindAndExec Bindings._bindAndExec = _patched_bindAndExec You could create an unpublishable subclass of PythonScript using a similar technique. Ideally PythonScripts would opt in to being publishable based on some metadata option. Laurence _______________________________________________ Zope maillist - [email protected] https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )