Commit ac4580f7 authored by Evan Simpson's avatar Evan Simpson

Made all methods that edit the body go through write(), so that

##metdata= lines can be used.  Collected cache invalidations into _makeFunction.
parent 5d3f14c3
...@@ -89,7 +89,7 @@ This product provides support for Script objects containing restricted ...@@ -89,7 +89,7 @@ This product provides support for Script objects containing restricted
Python code. Python code.
""" """
__version__='$Revision: 1.6 $'[11:-2] __version__='$Revision: 1.7 $'[11:-2]
import sys, os, traceback, re import sys, os, traceback, re
from Globals import MessageDialog, HTMLFile, package_home from Globals import MessageDialog, HTMLFile, package_home
...@@ -187,18 +187,18 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -187,18 +187,18 @@ class PythonScript(Script, Historical, Cacheable):
manage_tabs_message=message) manage_tabs_message=message)
def ZPythonScript_setTitle(self, title): def ZPythonScript_setTitle(self, title):
self.title = str(title) title = str(title)
self.ZCacheable_invalidate() if self.title != title:
self.title = title
self.ZCacheable_invalidate()
def ZPythonScript_edit(self, params, body): def ZPythonScript_edit(self, params, body):
self._validateProxy() self._validateProxy()
self.ZCacheable_invalidate()
if type(body) is not type(''): if type(body) is not type(''):
body = body.read() body = body.read()
if self._params <> params or self._body <> body: if self._params <> params or self._body <> body:
self._params = str(params) self._params = str(params)
self._body = rstrip(body) self.write(body)
self._makeFunction(1)
def ZPythonScriptHTML_upload(self, REQUEST, file=''): def ZPythonScriptHTML_upload(self, REQUEST, file=''):
"""Replace the body of the script with the text in file.""" """Replace the body of the script with the text in file."""
...@@ -275,6 +275,7 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -275,6 +275,7 @@ class PythonScript(Script, Historical, Cacheable):
from Guarded import WriteGuard, ReadGuard from Guarded import WriteGuard, ReadGuard
if allowSideEffect: if allowSideEffect:
self._checkCBlock(GuardedBlock) self._checkCBlock(GuardedBlock)
self.ZCacheable_invalidate()
if getattr(self, '_v_errors', None): if getattr(self, '_v_errors', None):
raise "Python Script Error", ('<pre>%s</pre>' % raise "Python Script Error", ('<pre>%s</pre>' %
join(self._v_errors, '\n') ) join(self._v_errors, '\n') )
...@@ -284,7 +285,6 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -284,7 +285,6 @@ class PythonScript(Script, Historical, Cacheable):
__builtins__=safebin) __builtins__=safebin)
def _editedBindings(self): def _editedBindings(self):
self.ZCacheable_invalidate()
f = getattr(self, '_v_f', None) f = getattr(self, '_v_f', None)
if f is None: if f is None:
return return
...@@ -377,10 +377,10 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -377,10 +377,10 @@ class PythonScript(Script, Historical, Cacheable):
def write(self, text): def write(self, text):
self._validateProxy() self._validateProxy()
self.ZCacheable_invalidate()
mdata = self._metadata_map() mdata = self._metadata_map()
bindmap = self.getBindingAssignments().getAssignedNames() bindmap = self.getBindingAssignments().getAssignedNames()
bup = 0 bup = 0
st = 0 st = 0
try: try:
while 1: while 1:
...@@ -419,10 +419,14 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -419,10 +419,14 @@ class PythonScript(Script, Historical, Cacheable):
bindmap[_nice_bind_names[k[5:]]] = v bindmap[_nice_bind_names[k[5:]]] = v
bup = 1 bup = 1
self._body = rstrip(body) body = rstrip(body)
if body != self._body:
self._body = body
if bup: if bup:
self._setupBindings(bindmap) self._setupBindings(bindmap)
self._makeFunction(1)
if self._p_changed:
self._makeFunction(1)
except: except:
LOG(self.meta_type, ERROR, 'write failed', error=sys.exc_info()) LOG(self.meta_type, ERROR, 'write failed', error=sys.exc_info())
raise raise
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment