X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=plomrogue%2Fparser.py;h=22e90594be8313ab514d6d346ce1b87fa498188b;hb=920a6e5b6e7d355aaaf0ae79ed194eab6e00b999;hp=2a87e7d10ea221336cde9dae391b14d5b774b024;hpb=3efcac66212325fecbbf28e3c19762821fb65d76;p=plomrogue2
diff --git a/plomrogue/parser.py b/plomrogue/parser.py
index 2a87e7d..22e9059 100644
--- a/plomrogue/parser.py
+++ b/plomrogue/parser.py
@@ -77,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, ()
@@ -101,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)):
@@ -116,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)