Add a demo walk-through to the coder guide
[mudpy.git] / mudpy / telnet.py
index 0cc29b8..e483c13 100644 (file)
@@ -1,8 +1,8 @@
 """Telnet functions and constants for the mudpy engine."""
 
-# Copyright (c) 2004-2018 Jeremy Stanley <fungi@yuggoth.org>. Permission
-# to use, copy, modify, and distribute this software is granted under
-# terms provided in the LICENSE file distributed with this software.
+# Copyright (c) 2004-2019 mudpy authors. Permission to use, copy,
+# modify, and distribute this software is granted under terms
+# provided in the LICENSE file distributed with this software.
 
 import mudpy
 
@@ -97,7 +97,20 @@ def telnet_proto(*arguments):
 
 def translate_action(*command):
     """Convert a Telnet command sequence into text suitable for logging."""
-    return "%s %s" % (command_names[command[0]], option_names[command[1]])
+    try:
+        command_name = command_names[command[0]]
+    except KeyError:
+        # This should never happen since we filter unknown commands from
+        # the input queue, but added here for completeness since logging
+        # should never crash the process
+        command_name = str(command[0])
+    try:
+        option_name = option_names[command[1]]
+    except KeyError:
+        # This can happen for any of the myriad of Telnet options missing
+        # from the option_names dict
+        option_name = str(command[1])
+    return "%s %s" % (command_name, option_name)
 
 
 def send_command(user, *command):