SupyML: use irc.error() for sandbox errors, and add MemoryError test

master
Valentin Lorentz 2010-12-23 17:03:23 +01:00
parent 525097416b
commit f3c5b40b7e
2 changed files with 10 additions and 4 deletions

View File

@ -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())

View File

@ -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: