def recompileScript(self, baseName): "recompile python script" scriptName = '%sScript' % baseName pyscript = getattr(self, scriptName, None) if pyscript is None: pyscript = PythonScript(scriptName) self.setObject(scriptName, pyscript) pyscript.ZPythonScript_edit('', getattr(self, baseName))
def updateScript(self, body): # Regenerate Python script object # Sync set of script source code and # creation of Python Script object. bodyField = self.schema["mipago_payment_amountOverride"] script = PythonScript(self.title_or_id()) script = script.__of__(self) script.ZPythonScript_edit("fields, ploneformgen, request", body) PythonField.set(bodyField, self, script)
def getScript(self, context): # Generate Python script object body = self.ScriptBody role = self.ProxyRole script = PythonScript(self.__name__) script = script.__of__(context) # Skip check roles script._validateProxy = lambda i=None: None # Force proxy role if role != u'none': script.manage_proxy((role, )) body = body.encode('utf-8') params = 'fields, easyform, request' script.ZPythonScript_edit(params, body) return script
def updateScript(self, body, role): # Regenerate Python script object # Sync set of script source code, proxy role and # creation of Python Script object. bodyField = self.schema["ScriptBody"] proxyField = self.schema["ProxyRole"] script = PythonScript(self.title_or_id()) script = script.__of__(self) # Force proxy role if role != "none": script.manage_proxy((role, )) script.ZPythonScript_edit("fields, ploneformgen, request", body) PythonField.set(bodyField, self, script) StringField.set(proxyField, self, role)
def getScript(self, context): # Generate Python script object body = self.ScriptBody role = self.ProxyRole script = PythonScript(self.__name__) script = script.__of__(context) # Skip check roles script._validateProxy = lambda i=None: None # Force proxy role if role != u"none": script.manage_proxy((role, )) if six.PY2 and isinstance(body, six.text_type): body = body.encode("utf-8") params = "fields, easyform, request" script.ZPythonScript_edit(params, body) return script
def testRestrictedIteration(self): """ Check content iterators can be used by restricted python code. """ # To let restricted python access methods on folder marker = object() saved_class_attributes = {} for method_id in ('objectIds', 'objectValues', 'objectItems'): roles_id = method_id + '__roles__' saved_class_attributes[roles_id] = getattr(HBTreeFolder2, roles_id, marker) setattr(HBTreeFolder2, roles_id, None) try: h = HBTreeFolder2() # whatever value, as long as it has an __of__ h._setOb('foo', HBTreeFolder2()) script = PythonScript('script') script.ZPythonScript_edit( 'h', dedent(""" for dummy in h.objectIds(): pass for dummy in h.objectValues(): pass for dummy in h.objectItems(): pass """)) class DummyRequest(object): # To make Shared.DC.Scripts.Bindings.Bindings._getTraverseSubpath # happy other = {} script.REQUEST = DummyRequest script(h) finally: for roles_id, orig in six.iteritems(saved_class_attributes): if orig is marker: delattr(HBTreeFolder2, roles_id) else: setattr(HBTreeFolder2, roles_id, orig)
def restricted_exec(self, body, varmap=None): ps = PythonScript('temp') if varmap is None: varmap = {} ps.ZPythonScript_edit(join(varmap.keys(), ','), body) return ps.__of__(self)(varmap.values())