Rename state variable in get_menu_choices()
[mudpy.git] / mudpy / misc.py
index b83215c..62f531e 100644 (file)
@@ -406,7 +406,7 @@ class Universe:
         """Create a new, empty Universe (the Big Bang)."""
         new_universe = Universe()
         for attribute in vars(self).keys():
-            exec("new_universe." + attribute + " = self." + attribute)
+            setattr(new_universe, attribute, getattr(self, attribute))
         new_universe.reload_flag = False
         del self
         return new_universe
@@ -637,14 +637,13 @@ class User:
         """Flag the user as authenticated and disconnect duplicates."""
         if self.state != "authenticated":
             self.authenticated = True
+            log("User %s authenticated for account %s." % (
+                    self, self.account.subkey), 2)
             if ("mudpy.limit" in universe.contents and self.account.subkey in
                     universe.contents["mudpy.limit"].get("admins")):
                 self.account.set("administrator", True)
-                log("Administrator %s authenticated." %
-                    self.account.get("name"), 2)
-            else:
-                log("User %s authenticated for account %s." % (
-                        self, self.account.subkey), 2)
+                log("Account %s is an administrator." % (
+                        self.account.subkey), 2)
 
     def show_menu(self):
         """Send the user their current menu."""
@@ -1582,8 +1581,8 @@ def get_menu_prompt(state):
 
 def get_menu_choices(user):
     """Return a dict of choice:meaning."""
-    menu = universe.groups["menu"][user.state]
-    create_choices = menu.get("create")
+    state = universe.groups["menu"][user.state]
+    create_choices = state.get("create")
     if create_choices:
         choices = eval(create_choices)
     else:
@@ -1591,7 +1590,7 @@ def get_menu_choices(user):
     ignores = []
     options = {}
     creates = {}
-    for facet in menu.facets():
+    for facet in state.facets():
         if facet.startswith("demand_") and not eval(
            universe.groups["menu"][user.state].get(facet)
            ):
@@ -1602,10 +1601,10 @@ def get_menu_choices(user):
             options[facet] = facet.split("_", 2)[1]
     for facet in creates.keys():
         if not creates[facet] in ignores:
-            choices[creates[facet]] = eval(menu.get(facet))
+            choices[creates[facet]] = eval(state.get(facet))
     for facet in options.keys():
         if not options[facet] in ignores:
-            choices[options[facet]] = menu.get(facet)
+            choices[options[facet]] = state.get(facet)
     return choices
 
 
@@ -1686,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