Remove exec() from handle_user_input() function
authorJeremy Stanley <fungi@yuggoth.org>
Tue, 24 Dec 2019 22:37:18 +0000 (22:37 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Sat, 28 Dec 2019 20:40:11 +0000 (20:40 +0000)
Stop passing the constructed handler function name into an exec()
and instead reference it from the globals() dict.

mudpy/misc.py

index fca279a..24443dd 100644 (file)
@@ -1685,9 +1685,9 @@ def handle_user_input(user):
         user.send("", add_prompt=False, prepend_padding=False)
 
     # check to make sure the state is expected, then call that handler
-    if "handler_" + user.state in globals():
-        exec("handler_" + user.state + "(user)")
-    else:
+    try:
+        globals()["handler_" + user.state](user)
+    except KeyError:
         generic_menu_handler(user)
 
     # since we got input, flag that the menu/prompt needs to be redisplayed