X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=154b555db14f6bc9ea4e90959d09426fa31e814c;hp=2da1b409bad9659f60ccbfca799d22743d848877;hb=0c50d321bc2ecb103c9e80896f6d79e77f1a72b2;hpb=46a46f095b503ba27f07521e9fef62a97ff1b078 diff --git a/mudpy/misc.py b/mudpy/misc.py index 2da1b40..154b555 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -1,6 +1,6 @@ """Miscellaneous functions for the mudpy engine.""" -# Copyright (c) 2004-2017 Jeremy Stanley . Permission +# Copyright (c) 2004-2018 Jeremy Stanley . Permission # to use, copy, modify, and distribute this software is granted under # terms provided in the LICENSE file distributed with this software. @@ -129,16 +129,25 @@ class Element: # updated data from files raise PermissionError("Altering elements in read-only files is " "disallowed") + # Coerce some values to appropriate data types + # TODO(fungi) Move these to a separate validation mechanism if facet in ["loglevel"]: value = int(value) elif facet in ["administrator"]: value = bool(value) - if not self.has_facet(facet) or not self.get(facet) == value: - node = ".".join((self.key, facet)) + + # The canonical node for this facet within its origin + node = ".".join((self.key, facet)) + + if node not in self.origin.data or self.origin.data[node] != value: + # Be careful to only update the origin's contents when required, + # since that affects whether the backing file gets written self.origin.data[node] = value - self.facethash[facet] = self.origin.data[node] self.origin.modified = True + # Make sure this facet is included in the element's facets + self.facethash[facet] = self.origin.data[node] + def append(self, facet, value): """Append value to a list.""" newlist = self.get(facet) @@ -825,13 +834,13 @@ class User: if self.output_queue: try: self.connection.send(self.output_queue[0]) - except BrokenPipeError: + except (BrokenPipeError, ConnectionResetError): if self.account and self.account.get("name"): account = self.account.get("name") else: account = "an unknown user" self.state = "disconnecting" - log("Broken pipe sending to %s." % account, 7) + log("Disconnected while sending to %s." % account, 7) del self.output_queue[0] def enqueue_input(self): @@ -889,7 +898,7 @@ class User: try: line = line.decode("utf-8") except UnicodeDecodeError: - logline = "Non-UTF-8 characters from " + logline = "Non-UTF-8 sequence from " if self.account and self.account.get("name"): logline += self.account.get("name") + ": " else: