def test_python_script(self, with_proxy_roles=0): conn = self.db.open() try: app = conn.root()['Application'] script = PythonScript('script') script.write('##title=test script\nreturn "OK"') script._makeFunction() app._setObject(script.id, script, set_owner=0) if with_proxy_roles: # set a proxy role and verify nothing breaks script._proxy_roles = ('System Administrator', ) transaction.commit() conn2 = self.db.open() try: app = conn2.root()['Application'] script = app.script self.assertEqual(script.title, 'test script') res = script() self.assertEqual(res, 'OK') finally: conn2.close() finally: conn.close()
def _newPS(self, txt, bind=None): from Products.PythonScripts.PythonScript import PythonScript ps = PythonScript('ps') #ps.ZBindings_edit(bind or {}) ps.write(txt) ps._makeFunction() return ps
def test_python_script(self, with_proxy_roles=0): conn = self.db.open() try: app = conn.root()['Application'] script = PythonScript('script') script.write('##title=test script\nreturn "OK"') script._makeFunction() app._setObject(script.id, script, set_owner=0) if with_proxy_roles: # set a proxy role and verify nothing breaks script._proxy_roles = ('System Administrator',) transaction.commit() conn2 = self.db.open() try: app = conn2.root()['Application'] script = app.script self.assertEqual(script.title, 'test script') res = script() self.assertEqual(res, 'OK') finally: conn2.close() finally: conn.close()
def _write(self, text, compile): ''' Parses the source, storing the body, params, title, bindings, and source in self. If compile is set, compiles the function. ''' ps = PythonScript(self.id) ps.write(text) if compile: ps._makeFunction(1) self._v_f = f = ps._v_f if f is not None: self.func_code = f.func_code self.func_defaults = f.func_defaults else: # There were errors in the compile. # No signature. self.func_code = bad_func_code() self.func_defaults = None self._body = ps._body self._params = ps._params if not self.title: self.title = ps.title self._setupBindings(ps.getBindingAssignments().getAssignedNames()) self._source = ps.read() # Find out what the script sees.
def createPythonScript(self, id_, title, code): """Creare new Python Script object.""" ps = PythonScript(id_) if title: ps.ZPythonScript_setTitle(title) ps.write(code) ps._makeFunction() return ps
def _filePS(self, fname, bind=None): ps = PythonScript(fname) ps.ZBindings_edit(bind or {}) ps.write(readf(fname)) ps._makeFunction() if ps.errors: raise SyntaxError(ps.errors[0]) return ps
def _newPS(self, txt, bind=None): ps = PythonScript('ps') ps.ZBindings_edit(bind or {}) ps.write(txt) ps._makeFunction() if ps.errors: raise SyntaxError(ps.errors[0]) return ps
def _write(self, text): ps = PythonScript(self.id) ps.write(text) ps._makeFunction() ps._editedBindings() self._v_f = f = ps._v_f self._body = ps._body self._params = ps._params fc = f.func_code self._setFuncSignature(f.func_defaults, fc.co_varnames, fc.co_argcount)
def _write(self, text, compile): ''' Parses the source, storing the body, params, title, bindings, and source in self. If compile is set, compiles the function. ''' ps = PythonScript(self.id) ps.write(text) if compile: ps._makeFunction() self._v_ft = ps._v_ft self.func_code = ps.func_code self.func_defaults = ps.func_defaults self._body = ps._body self._params = ps._params self.title = ps.title self._setupBindings(ps.getBindingAssignments().getAssignedNames()) self._source = ps.read() # Find out what the script sees.
def _testScript(self,txt): theScript = PythonScript('test') theScript.ZBindings_edit({}) theScript.write(txt) theScript._makeFunction() return theScript()
def _newPS(self, txt, bind=None): ps = PythonScript('ps') ps.ZBindings_edit(bind or {}) ps.write(txt) ps._makeFunction() return ps