From de9abf7f706d994d8adba5b364dc154450c09160 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Mon, 6 Jun 2011 04:26:17 +0000 Subject: [PATCH] Additional style cleanup * lib/mudpy/__init__.py * lib/mudpy/data.py * lib/mudpy/misc.py * lib/mudpy/telnet.py: Limit lines to <80 characters and adjust hanging/visual indents for clarity and consistency. --- lib/mudpy/__init__.py | 3 ++- lib/mudpy/data.py | 5 ++--- lib/mudpy/misc.py | 60 +++++++++++++++++++++++++-------------------------- lib/mudpy/telnet.py | 6 ++++-- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/lib/mudpy/__init__.py b/lib/mudpy/__init__.py index ab2f0b6..91a9baf 100644 --- a/lib/mudpy/__init__.py +++ b/lib/mudpy/__init__.py @@ -7,7 +7,8 @@ u"""Core modules package for the mudpy engine.""" def load(): - u"""Import/reload some modules (be careful, as this can result in loops).""" + u"""Import/reload some modules (be careful, as this can result in + loops).""" # pick up the modules list from this package global modules diff --git a/lib/mudpy/data.py b/lib/mudpy/data.py index f94b02b..3ed5e0f 100644 --- a/lib/mudpy/data.py +++ b/lib/mudpy/data.py @@ -91,9 +91,8 @@ class DataFile: relative=self.filename, universe=self.universe ) - if include_file not in self.universe.files or not self.universe.files[ - include_file - ].is_writeable(): + if (include_file not in self.universe.files or not + self.universe.files[include_file].is_writeable()): DataFile(include_file, self.universe) def save(self): diff --git a/lib/mudpy/misc.py b/lib/mudpy/misc.py index 3c031a5..5ba81ea 100644 --- a/lib/mudpy/misc.py +++ b/lib/mudpy/misc.py @@ -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() diff --git a/lib/mudpy/telnet.py b/lib/mudpy/telnet.py index 043c86b..e7a0c86 100644 --- a/lib/mudpy/telnet.py +++ b/lib/mudpy/telnet.py @@ -59,7 +59,8 @@ def send_command(user, *command): def is_enabled(user, telopt, party, state=YES): - u"""Returns True if the indicated Telnet option is enabled, False if not.""" + u"""Returns True if the indicated Telnet option is enabled, False if + not.""" if (telopt, party) in user.telopts and user.telopts[ (telopt, party) ] is state: @@ -86,7 +87,8 @@ def enable(user, telopt, party): def disable(user, telopt, party): - u"""Negotiates disabling a Telnet option for the indicated user's socket.""" + u"""Negotiates disabling a Telnet option for the indicated user's + socket.""" if party is HIM: txneg = DONT else: -- 2.11.0