Stop unnecessarily stripping quote marks
[mudpy.git] / mudpy / data.py
index 00ab923..0483cd7 100644 (file)
@@ -97,7 +97,7 @@ class DataFile:
                     element = self.universe.contents[prefix]
                 except KeyError:
                     element = mudpy.misc.Element(prefix, self.universe,
-                        self.filename)
+                                                 self.filename)
                 element.set(node[facet_pos:], self.data[node])
                 if prefix.startswith("mudpy.movement."):
                     self.universe.directions.add(
@@ -134,15 +134,17 @@ class DataFile:
             if "__control__" in self.data and "backup_count" in self.data[
                     "__control__"]:
                 max_count = self.data["__control__"]["backup_count"]
-            else:
+            elif "mudpy.limit" in self.universe.contents:
                 max_count = self.universe.contents["mudpy.limit"].get(
-                    "backups")
+                    "backups", 0)
+            else:
+                max_count = 0
             if os.path.exists(self.filename) and max_count:
                 backups = []
                 for candidate in os.listdir(os.path.dirname(self.filename)):
                     if re.match(
                        os.path.basename(self.filename) +
-                       """\.\d+$""", candidate
+                       r"""\.\d+$""", candidate
                        ):
                         backups.append(int(candidate.split(".")[-1]))
                 backups.sort()
@@ -199,10 +201,6 @@ def find_file(
 ):
     """Return an absolute file path based on configuration."""
 
-    # make sure to get rid of any surrounding quotes first thing
-    if file_name:
-        file_name = file_name.strip("\"'")
-
     # this is all unnecessary if it's already absolute
     if file_name and os.path.isabs(file_name):
         return os.path.realpath(file_name)
@@ -216,11 +214,11 @@ def find_file(
            ) and "internal:storage" in universe.contents:
             storage = universe.categories["internal"]["storage"]
             if not root_path:
-                root_path = storage.get("root_path").strip("\"'")
+                root_path = storage.get("root_path")
             if not search_path:
                 search_path = storage.get("search_path")
             if not default_dir:
-                default_dir = storage.get("default_dir").strip("\"'")
+                default_dir = storage.get("default_dir")
 
         # if there's only one file loaded, try to work around a chicken<egg
         elif hasattr(universe, "files") and len(
@@ -245,16 +243,18 @@ def find_file(
                     "internal:storage", "").get("search_path", "")
 
         # another fallback root path, this time from the universe startdir
-        if not root_path and hasattr(universe, "startdir"):
-            root_path = universe.startdir
+        if hasattr(universe, "startdir"):
+            if not root_path:
+                root_path = universe.startdir
+            elif not os.path.isabs(root_path):
+                root_path = os.path.join(universe.startdir, root_path)
 
     # when no root path is specified, assume the current working directory
     if not root_path:
         root_path = os.getcwd()
 
-    # otherwise, make sure it's absolute
-    elif not os.path.isabs(root_path):
-        root_path = os.path.realpath(root_path)
+    # make sure it's absolute
+    root_path = os.path.realpath(root_path)
 
     # if there's no search path, just use the root path and etc
     if not search_path:
@@ -270,7 +270,6 @@ def find_file(
 
     # if an existing file or directory reference was supplied, prepend it
     if relative:
-        relative = relative.strip("\"'")
         if os.path.isdir(relative):
             search_path = [relative] + search_path
         else:
@@ -279,7 +278,6 @@ def find_file(
     # make the search path entries absolute and throw away any dupes
     clean_search_path = []
     for each_path in search_path:
-        each_path = each_path.strip("\"'")
         if not os.path.isabs(each_path):
             each_path = os.path.realpath(os.path.join(root_path, each_path))
         if each_path not in clean_search_path: