X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=b0b729089a00b7896a738217860c05a9ad6b8ac5;hp=4e32cccd5e99073b7f718bb3a7bbfc7eedb3086d;hb=06d1068372f462904a718ffbbe38d9603e71873a;hpb=31bd5bdf5962b81cd22df5173775d7886405be80 diff --git a/mudpy/misc.py b/mudpy/misc.py index 4e32ccc..b0b7290 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -154,6 +154,12 @@ class Element: def set(self, facet, value): """Set values.""" + if not self.origin.is_writeable() and not self.universe.loading: + # break if there is an attempt to update an element from a + # read-only file, unless the universe is in the midst of loading + # updated data from files + raise PermissionError("Altering elements in read-only files is " + "disallowed") if facet in ["loglevel"]: value = int(value) if not self.has_facet(facet) or not self.get(facet) == value: @@ -2288,6 +2294,11 @@ def command_set(actor, parameters): else: try: universe.contents[element].set(facet, value) + except PermissionError: + message = ('The "%s" element is kept in read-only file ' + '"%s" and cannot be altered.' % + (element, universe.contents[ + element].origin.filename)) except ValueError: message = ('Value "%s" of type "%s" cannot be coerced ' 'to the correct datatype for facet "%s".' %