SupyML: Add warnings managment

master
Valentin Lorentz 2010-11-14 16:41:33 +01:00
parent 078bc676ae
commit 6528a9b483
2 changed files with 22 additions and 5 deletions

View File

@ -165,6 +165,7 @@ class SupyMLParser:
def _processVar(self, node, variables):
"""Handles the <var /> tag"""
variableName = node.attributes['name'].value
self._checkVariableName(variableName)
try:
return variables[variableName]
except KeyError:
@ -212,20 +213,22 @@ class SupyML(callbacks.Plugin):
This scripts (Supybot Markup Language) are script written in a XML-based
language."""
#threaded = True
def eval(self, irc, msg, args, code):
"""<SupyML script>
def eval(self, irc, msg, args, optlist, code):
"""[--warnings] <SupyML script>
Executes the <SupyML script>"""
parser = SupyMLParser(self, irc, msg, code,
self.registryValue('maxnodes')+2)
if world.testing and len(parser.warnings) != 0:
print parser.warnings
for item in optlist:
if ('warnings', True) == item and len(parser.warnings) != 0:
irc.error(' & '.join(parser.warnings))
if parser.rawData is not None:
irc.queueMsg(parser.rawData)
else:
irc.reply(parser.data)
eval=wrap(eval, ['text'])
eval=wrap(eval, [getopts({'warnings':''}), 'text'])
SupyML = internationalizeDocstring(SupyML)
Class = SupyML

View File

@ -149,4 +149,18 @@ class SupyMLTestCase(ChannelPluginTestCase):
'</echo>'*31
)
def testWarnings(self):
self.assertResponse('SupyML eval <echo>'
'<set name="">'
'bar'
'</set>'
'<var name="" />'
'</echo>', 'bar')
self.assertResponse('SupyML eval --warnings <echo>'
'<set name="">'
'bar'
'</set>'
'<var name="" />'
'</echo>', 'Error: Empty variable name')
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: