Additional style cleanup
[mudpy.git] / lib / mudpy / misc.py
index 3c031a5..5ba81ea 100644 (file)
@@ -44,7 +44,7 @@ class Element:
             else:
                 self.category = u"other"
                 self.subkey = self.key
-            if not self.category in self.universe.categories:
+            if self.category not in self.universe.categories:
                 self.category = u"other"
                 self.subkey = self.key
 
@@ -55,7 +55,7 @@ class Element:
                 filename = os.path.abspath(filename)
 
             # add the file if it doesn't exist yet
-            if not filename in self.universe.files:
+            if filename not in self.universe.files:
                 data.DataFile(filename, self.universe)
 
         # record or reset a pointer to the origin file
@@ -731,7 +731,7 @@ class User:
 
     def authenticate(self):
         u"""Flag the user as authenticated and disconnect duplicates."""
-        if not self.state is u"authenticated":
+        if self.state is not u"authenticated":
             log(u"User " + self.account.get(u"name") + u" logged in.", 2)
             self.authenticated = True
             if self.account.subkey in universe.categories[
@@ -909,10 +909,8 @@ class User:
                     account = self.account.get(u"name")
                 else:
                     account = u"an unknown user"
-                log(
-                    u"Sending to %s raised an exception (broken pipe?)." % account,
-                    7
-                )
+                log(u"Sending to %s raised an exception (broken pipe?)."
+                    % account, 7)
                 pass
 
     def enqueue_input(self):
@@ -1110,9 +1108,9 @@ def log(message, level=0):
             # iterate over every line in the message
             full_message = u""
             for line in lines:
-                full_message += u"$(bld)$(red)" + timestamp + u" " + line.replace(
-                    u"$(", u"$_("
-                ) + u"$(nrm)$(eol)"
+                full_message += (
+                    u"$(bld)$(red)" + timestamp + u" "
+                    + line.replace(u"$(", u"$_(") + u"$(nrm)$(eol)")
             user.send(full_message, flush=True)
 
     # add to the recent log list
@@ -1188,11 +1186,11 @@ def wrap_ansi_text(text, width):
 
     # the current position in the entire text string, including all
     # characters, printable or otherwise
-    absolute_position = 0
+    abs_pos = 0
 
     # the current text position relative to the begining of the line,
     # ignoring color escape sequences
-    relative_position = 0
+    rel_pos = 0
 
     # the absolute position of the most recent whitespace character
     last_whitespace = 0
@@ -1221,16 +1219,16 @@ def wrap_ansi_text(text, width):
         # the current character is a newline, so reset the relative
         # position (start a new line)
         elif each_character == u"\n":
-            relative_position = 0
-            last_whitespace = absolute_position
+            rel_pos = 0
+            last_whitespace = abs_pos
 
         # the current character meets the requested maximum line width,
         # so we need to backtrack and find a space at which to wrap;
         # special care is taken to avoid an off-by-one in case the
         # current character is a double-width glyph
         elif each_character != u"\r" and (
-            relative_position >= width or (
-                relative_position >= width - 1 and glyph_columns(
+            rel_pos >= width or (
+                rel_pos >= width - 1 and glyph_columns(
                     each_character
                 ) == 2
             )
@@ -1238,7 +1236,7 @@ def wrap_ansi_text(text, width):
 
             # it's always possible we landed on whitespace
             if unicodedata.category(each_character) in (u"Cc", u"Zs"):
-                last_whitespace = absolute_position
+                last_whitespace = abs_pos
 
             # insert an eol in place of the space
             text = text[:last_whitespace] + \
@@ -1246,24 +1244,24 @@ def wrap_ansi_text(text, width):
 
             # increase the absolute position because an eol is two
             # characters but the space it replaced was only one
-            absolute_position += 1
+            abs_pos += 1
 
             # now we're at the begining of a new line, plus the
             # number of characters wrapped from the previous line
-            relative_position = 0
-            for remaining_characters in text[last_whitespace:absolute_position]:
-                relative_position += glyph_columns(remaining_characters)
+            rel_pos = 0
+            for remaining_characters in text[last_whitespace:abs_pos]:
+                rel_pos += glyph_columns(remaining_characters)
 
         # as long as the character is not a carriage return and the
         # other above conditions haven't been met, count it as a
         # printable character
         elif each_character != u"\r":
-            relative_position += glyph_columns(each_character)
+            rel_pos += glyph_columns(each_character)
             if unicodedata.category(each_character) in (u"Cc", u"Zs"):
-                last_whitespace = absolute_position
+                last_whitespace = abs_pos
 
         # increase the absolute position for every character
-        absolute_position += 1
+        abs_pos += 1
 
     # return the newly-wrapped text
     return text
@@ -1454,7 +1452,7 @@ def on_pulse():
         user.pulse()
 
     # add an element for counters if it doesn't exist
-    if not u"counters" in universe.categories[u"internal"]:
+    if u"counters" not in universe.categories[u"internal"]:
         universe.categories[u"internal"][u"counters"] = Element(
             u"internal:counters", universe
         )
@@ -2121,9 +2119,9 @@ def command_say(actor, parameters):
         actions = universe.categories[u"internal"][u"language"].getdict(
             u"actions"
         )
-        default_punctuation = universe.categories[u"internal"][u"language"].get(
-            u"default_punctuation"
-        )
+        default_punctuation = (
+            universe.categories[u"internal"][u"language"].get(
+                u"default_punctuation"))
         action = u""
         for mark in actions.keys():
             if not literal and message.endswith(mark):
@@ -2283,7 +2281,8 @@ def command_show(actor, parameters):
         else:
             start = 10
         if len(arguments) >= 2:
-            if re.match(u"^\d+$", arguments[1]) and 0 <= int(arguments[1]) <= 9:
+            if (re.match(u"^\d+$", arguments[1])
+                    and 0 <= int(arguments[1]) <= 9):
                 level = int(arguments[1])
             else:
                 level = -1
@@ -2635,7 +2634,8 @@ def setup():
 
 
 def finish():
-    """This contains functions to be performed when shutting down the engine."""
+    """This contains functions to be performed when shutting down the
+        engine."""
 
     # the loop has terminated, so save persistent data
     universe.save()