Use raw strings when escape sequences are needed
[mudpy.git] / mudpy / misc.py
index 6cb7804..822beeb 100644 (file)
@@ -299,7 +299,7 @@ class Element:
     def portals(self):
         """Map the portal directions for an area to neighbors."""
         portals = {}
-        if re.match("""^area:-?\d+,-?\d+,-?\d+$""", self.key):
+        if re.match(r"""^area:-?\d+,-?\d+,-?\d+$""", self.key):
             coordinates = [(int(x))
                            for x in self.key.split(":")[1].split(",")]
             offsets = dict(
@@ -2178,21 +2178,21 @@ def command_show(actor, parameters):
                            "$(eol)$(bld)%s$(nrm)" % e)
     elif arguments[0] == "log":
         if len(arguments) == 4:
-            if re.match("^\d+$", arguments[3]) and int(arguments[3]) >= 0:
+            if re.match(r"^\d+$", arguments[3]) and int(arguments[3]) >= 0:
                 stop = int(arguments[3])
             else:
                 stop = -1
         else:
             stop = 0
         if len(arguments) >= 3:
-            if re.match("^\d+$", arguments[2]) and int(arguments[2]) > 0:
+            if re.match(r"^\d+$", arguments[2]) and int(arguments[2]) > 0:
                 start = int(arguments[2])
             else:
                 start = -1
         else:
             start = 10
         if len(arguments) >= 2:
-            if (re.match("^\d+$", arguments[1])
+            if (re.match(r"^\d+$", arguments[1])
                     and 0 <= int(arguments[1]) <= 9):
                 level = int(arguments[1])
             else:
@@ -2284,11 +2284,17 @@ def command_set(actor, parameters):
             if element not in universe.contents:
                 message = "The \"" + element + "\" element does not exist."
             else:
-                universe.contents[element].set(facet, value)
-                message = ("You have successfully (re)set the \"" + facet
-                           + "\" facet of element \"" + element
-                           + "\". Try \"show element " +
-                           element + "\" for verification.")
+                try:
+                    universe.contents[element].set(facet, value)
+                except ValueError:
+                    message = ("Value \"%s\" of type \"%s\" cannot be coerced "
+                               "to the correct datatype for facet \"%s\"." %
+                               (value, type(value), facet))
+                else:
+                    message = ("You have successfully (re)set the \"" + facet
+                               + "\" facet of element \"" + element
+                               + "\". Try \"show element " +
+                               element + "\" for verification.")
     actor.send(message)