home · contact · privacy
Only allow opening/closing doors that are installed.
[plomrogue2] / plomrogue / parser.py
index 2820c186778365384be548929c2a1128f587d490..302733d0322a69c9592276b94239b626debcb4c3 100644 (file)
@@ -77,11 +77,14 @@ class Parser:
         """Parse msg as call to function, return function with args tuple.
 
         Respects function signature defined in function's .argtypes attribute.
         """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
         """
         import string
-        msg = msg.rstrip()
+        msg = msg.replace('\n', ' ')  # Inserted by some tablet keyboards.
         legal_chars = string.digits + string.ascii_letters +\
         legal_chars = string.digits + string.ascii_letters +\
-            string.punctuation + ' ' + 'ÄäÖöÜüߧ' + 'éèáàô'
+            string.punctuation + ' ' + 'ÄäÖöÜüߧ' + 'éèáàô' + '–…'
         for c in msg:
             if not c in legal_chars:
                 raise ArgError('Command/message contains illegal character(s), '
         for c in msg:
             if not c in legal_chars:
                 raise ArgError('Command/message contains illegal character(s), '
@@ -124,6 +127,11 @@ class Parser:
                 if not arg.isdigit() or int(arg) < 1:
                     raise ArgError('Argument must be positive integer.')
                 args += [int(arg)]
                 if not arg.isdigit() or int(arg) < 1:
                     raise ArgError('Argument must be positive integer.')
                 args += [int(arg)]
+            elif tmpl == 'int':
+                try:
+                    args += [int(arg)]
+                except ValueError:
+                    raise ArgError('Argument must be integer.')
             elif tmpl == 'bool':
                 if not arg.isdigit() or int(arg) not in (0, 1):
                     raise ArgError('Argument must be 0 or 1.')
             elif tmpl == 'bool':
                 if not arg.isdigit() or int(arg) not in (0, 1):
                     raise ArgError('Argument must be 0 or 1.')