added IScriptContainer providing additional global variables
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1871 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
01935abab7
commit
2206d795a1
2 changed files with 19 additions and 2 deletions
|
@ -24,6 +24,8 @@ $Id$
|
|||
|
||||
from zope.interface import Interface
|
||||
from zope import schema
|
||||
from zope.app.container.constraints import contains
|
||||
from zope.app.container.interfaces import IContainer
|
||||
from zope.app.i18n import ZopeMessageFactory as _
|
||||
|
||||
|
||||
|
@ -56,3 +58,15 @@ class IPythonScript(Interface):
|
|||
variables. Furthermore, the variables `script` and `context` (which is
|
||||
the container of the script) will be added.
|
||||
"""
|
||||
|
||||
|
||||
class IScriptContainer(IContainer):
|
||||
""" A container for Python scripts.
|
||||
"""
|
||||
|
||||
contains(IPythonScript)
|
||||
|
||||
def updateGlobals(globs):
|
||||
""" Put additional variable bindings into the globals dictionary.
|
||||
"""
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ from zope.app.container.contained import Contained
|
|||
from zope.interface import implements
|
||||
from zope.app.i18n import ZopeMessageFactory as _
|
||||
|
||||
from cybertools.pyscript.interfaces import IPythonScript
|
||||
from cybertools.pyscript.interfaces import IPythonScript, IScriptContainer
|
||||
|
||||
|
||||
class PythonScript(Contained, Persistent):
|
||||
|
@ -94,11 +94,14 @@ class PythonScript(Contained, Persistent):
|
|||
if self._v_compiled is None:
|
||||
self._v_compiled = Function(self.__prepared_source,
|
||||
self.__filename())
|
||||
parent = getParent(self)
|
||||
kw['request'] = request
|
||||
kw['script'] = self
|
||||
kw['untrusted_output'] = kw['printed'] = output
|
||||
kw['context'] = getParent(self)
|
||||
kw['context'] = parent
|
||||
kw['script_result'] = None
|
||||
if IScriptContainer.providedBy(parent):
|
||||
parent.updateGlobals(kw)
|
||||
self._v_compiled(kw)
|
||||
result = kw['script_result']
|
||||
if result == output:
|
||||
|
|
Loading…
Add table
Reference in a new issue