projects
/
mudpy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix show element command for Py3K
[mudpy.git]
/
lib
/
mudpy
/
misc.py
diff --git
a/lib/mudpy/misc.py
b/lib/mudpy/misc.py
index
8e747dd
..
f4c8779
100644
(file)
--- a/
lib/mudpy/misc.py
+++ b/
lib/mudpy/misc.py
@@
-1,7
+1,6
@@
-# -*- coding: utf-8 -*-
"""Miscellaneous functions for the mudpy engine."""
"""Miscellaneous functions for the mudpy engine."""
-# Copyright (c) 2004-201
4
Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-201
6
Jeremy Stanley <fungi@yuggoth.org>. Permission
# to use, copy, modify, and distribute this software is granted under
# terms provided in the LICENSE file distributed with this software.
# to use, copy, modify, and distribute this software is granted under
# terms provided in the LICENSE file distributed with this software.
@@
-414,9
+413,13
@@
class Universe:
# make a list of inactive avatars
inactive_avatars = []
for account in self.categories["account"].values():
# make a list of inactive avatars
inactive_avatars = []
for account in self.categories["account"].values():
- inactive_avatars += [
- (self.contents[x]) for x in account.getlist("avatars")
- ]
+ for avatar in account.get("avatars"):
+ try:
+ inactive_avatars.append(self.contents[avatar])
+ except KeyError:
+ pending_loglines.append((
+ "Missing avatar \"%s\", possible data corruption" %
+ avatar, 6))
for user in self.userlist:
if user.avatar in inactive_avatars:
inactive_avatars.remove(user.avatar)
for user in self.userlist:
if user.avatar in inactive_avatars:
inactive_avatars.remove(user.avatar)
@@
-837,14
+840,14
@@
class User:
if self.output_queue:
try:
self.connection.send(self.output_queue[0])
if self.output_queue:
try:
self.connection.send(self.output_queue[0])
- del self.output_queue[0]
except BrokenPipeError:
if self.account and self.account.get("name"):
account = self.account.get("name")
else:
account = "an unknown user"
except BrokenPipeError:
if self.account and self.account.get("name"):
account = self.account.get("name")
else:
account = "an unknown user"
- log("Broken pipe sending to %s." % account, 7)
self.state = "disconnecting"
self.state = "disconnecting"
+ log("Broken pipe sending to %s." % account, 7)
+ del self.output_queue[0]
def enqueue_input(self):
"""Process and enqueue any new input."""
def enqueue_input(self):
"""Process and enqueue any new input."""
@@
-973,11
+976,14
@@
class User:
def list_avatar_names(self):
"""List names of assigned avatars."""
def list_avatar_names(self):
"""List names of assigned avatars."""
- return [
- universe.contents[avatar].get(
- "name"
- ) for avatar in self.account.getlist("avatars")
- ]
+ avatars = []
+ for avatar in self.account.get("avatars"):
+ try:
+ avatars.append(universe.contents[avatar].get("name"))
+ except KeyError:
+ log("Missing avatar \"%s\", possible data corruption." %
+ avatar, 6)
+ return avatars
def broadcast(message, add_prompt=True):
def broadcast(message, add_prompt=True):
@@
-997,10
+1003,8
@@
def log(message, level=0):
syslog_name = universe.categories["internal"]["logging"].get("syslog")
timestamp = time.asctime()[4:19]
syslog_name = universe.categories["internal"]["logging"].get("syslog")
timestamp = time.asctime()[4:19]
- # turn the message into a list of lines
- lines = filter(
- lambda x: x != "", [(x.rstrip()) for x in message.split("\n")]
- )
+ # turn the message into a list of nonempty lines
+ lines = [x for x in [(x.rstrip()) for x in message.split("\n")] if x != ""]
# send the timestamp and line to a file
if file_name:
# send the timestamp and line to a file
if file_name:
@@
-1052,7
+1056,7
@@
def get_loglines(level, start, stop):
"""Return a specific range of loglines filtered by level."""
# filter the log lines
"""Return a specific range of loglines filtered by level."""
# filter the log lines
- loglines =
filter(lambda x: x[0] >= level, universe.loglines)
+ loglines =
[x for x in universe.loglines if x[0] >= level]
# we need these in several places
total_count = str(len(universe.loglines))
# we need these in several places
total_count = str(len(universe.loglines))
@@
-1338,9
+1342,12
@@
def replace_macros(user, text, is_input=False):
return text
return text
-def escape_macros(
text
):
+def escape_macros(
value
):
"""Escapes replacement macros in text."""
"""Escapes replacement macros in text."""
- return text.replace("$(", "$_(")
+ if type(value) is str:
+ return value.replace("$(", "$_(")
+ else:
+ return value
def first_word(text, separator=" "):
def first_word(text, separator=" "):
@@
-2037,7
+2044,9
@@
def command_say(actor, parameters):
universe.categories["internal"]["language"].get(
"default_punctuation"))
action = ""
universe.categories["internal"]["language"].get(
"default_punctuation"))
action = ""
- for mark in actions.keys():
+
+ # reverse sort punctuation options so the longest match wins
+ for mark in sorted(actions.keys(), reverse=True):
if not literal and message.endswith(mark):
action = actions[mark]
break
if not literal and message.endswith(mark):
action = actions[mark]
break
@@
-2163,10
+2172,9
@@
def command_show(actor, parameters):
+ "\" element (in \"" + element.origin.filename
+ "\"):$(eol)")
facets = element.facets()
+ "\" element (in \"" + element.origin.filename
+ "\"):$(eol)")
facets = element.facets()
- facets.sort()
- for facet in facets:
- message += ("$(eol) $(grn)" + facet + ": $(red)"
- + escape_macros(element.get(facet)) + "$(nrm)")
+ for facet in sorted(facets):
+ message += ("$(eol) $(grn)%s: $(red)%s$(nrm)" %
+ (facet, escape_macros(element.get(facet))))
else:
message = "Element \"" + arguments[1] + "\" does not exist."
elif arguments[0] == "result":
else:
message = "Element \"" + arguments[1] + "\" does not exist."
elif arguments[0] == "result":
@@
-2199,8
+2207,8
@@
def command_show(actor, parameters):
level = int(arguments[1])
else:
level = -1
level = int(arguments[1])
else:
level = -1
- elif 0 <= actor.owner.account.get("loglevel") <= 9:
- level = actor.owner.account.get("loglevel")
+ elif 0 <= actor.owner.account.get("loglevel"
, 0
) <= 9:
+ level = actor.owner.account.get("loglevel"
, 0
)
else:
level = 1
if level > -1 and start > -1 and stop > -1:
else:
level = 1
if level > -1 and start > -1 and stop > -1: