"""Miscellaneous functions for the mudpy engine."""
-# Copyright (c) 2004-2015 Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-2016 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.
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:
"""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))
return text
-def escape_macros(text):
+def escape_macros(value):
"""Escapes replacement macros in text."""
- return text.replace("$(", "$_(")
+ if type(value) is str:
+ return value.replace("$(", "$_(")
+ else:
+ return value
def first_word(text, separator=" "):
+ "\" 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":
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: