X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=plomrogue%2Fparser.py;h=05c830ff8552c216b81924c46244067717e478a4;hb=ea5ddf2c37571f3fb0ed486cd4a4294b82c54b54;hp=d1307a97701d3ef5c5eee6ecc2c16cfcb8d94282;hpb=d9c9b5b7d5cac2469ac075010c4d729e1adf0cc4;p=plomrogue2
diff --git a/plomrogue/parser.py b/plomrogue/parser.py
index d1307a9..05c830f 100644
--- a/plomrogue/parser.py
+++ b/plomrogue/parser.py
@@ -1,4 +1,3 @@
-import unittest
from plomrogue.errors import ArgError
from plomrogue.mapping import YX
@@ -78,7 +77,18 @@ class Parser:
"""Parse msg as call to function, return function with args tuple.
Respects function signature defined in function's .argtypes attribute.
+
+ Throws out messages with any but a small list of acceptable characters.
+
"""
+ import string
+ msg = msg.replace('\n', ' ') # Inserted by some tablet keyboards.
+ legal_chars = string.digits + string.ascii_letters +\
+ string.punctuation + ' ' + 'ÃäÃöÃüç' + 'éèáà ô' + 'â'
+ for c in msg:
+ if not c in legal_chars:
+ raise ArgError('Command/message contains illegal character(s), '
+ 'may only contain ones of: %s' % legal_chars)
tokens = self.tokenize(msg)
if len(tokens) == 0:
return None, ()
@@ -102,8 +112,8 @@ class Parser:
tmpl_tokens = signature.split()
if len(tmpl_tokens) != len(args_tokens):
raise ArgError('Number of arguments (' + str(len(args_tokens)) +
- ') not expected number (' + str(len(tmpl_tokens))
- + ').')
+ ') not expected number (' + str(len(tmpl_tokens)) +
+ ').')
args = []
string_string = 'string'
for i in range(len(tmpl_tokens)):
@@ -117,6 +127,10 @@ class Parser:
if not arg.isdigit() or int(arg) < 1:
raise ArgError('Argument must be positive integer.')
args += [int(arg)]
+ elif tmpl == 'bool':
+ if not arg.isdigit() or int(arg) not in (0, 1):
+ raise ArgError('Argument must be 0 or 1.')
+ args += [bool(int(arg))]
elif tmpl == 'char':
try:
ord(arg)