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
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
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[
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):
# 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
# 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
# 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
)
# 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] + \
# 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
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
)
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):
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
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()