diff --git a/SupySandbox/plugin.py b/SupySandbox/plugin.py index b45bba3..dbe1680 100644 --- a/SupySandbox/plugin.py +++ b/SupySandbox/plugin.py @@ -59,6 +59,8 @@ import supybot.ircutils as ircutils import supybot.callbacks as callbacks from cStringIO import StringIO +class SandboxError(Exception): + pass def createSandboxConfig(): cfg = S.SandboxConfig( @@ -160,11 +162,11 @@ def handleChild(childpid, r): n += 1 if not pid: os.kill(childpid, signal.SIGKILL) - return 'Timeout' + raise SandboxError('Timeout') elif os.WIFEXITED(status): return txt.rstrip() elif os.WIFSIGNALED(status): - return 'Killed' + raise SandboxError('Killed') def handle_line(line): r, w = os.pipe() @@ -188,7 +190,10 @@ class SupySandbox(callbacks.Plugin): Runs Python code safely thanks to pysandbox""" code = self._parser.match(msg.args[1]).group('code') - irc.reply(handle_line(code.replace(' $$ ', '\n'))) + try: + irc.reply(handle_line(code.replace(' $$ ', '\n'))) + except SandboxError, e: + irc.error('; '.join(e.args)) def runtests(self, irc, msg, args): irc.reply(runTests()) diff --git a/SupySandbox/test.py b/SupySandbox/test.py index cf29611..1598f60 100644 --- a/SupySandbox/test.py +++ b/SupySandbox/test.py @@ -49,7 +49,8 @@ class SupySandboxTestCase(PluginTestCase): ' $$ toto=False', "foo") def testProtections(self): - self.assertResponse('sandbox while True: pass', "Killed") + self.assertError('sandbox while True: pass') + self.assertError('sandbox foo="bar"; $$ while True:foo=foo*10') # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: