Make PEP8 cleanup of line spaces and character distances as well as indents
This commit is contained in:
parent
7ff783fea1
commit
b278337172
189 changed files with 2039 additions and 1583 deletions
|
|
@ -88,41 +88,41 @@ _SEARCH_AT_RESULT = utils.variable_from_module(*settings.SEARCH_AT_RESULT.rsplit
|
|||
# is the normal "production message to echo to the account.
|
||||
|
||||
_ERROR_UNTRAPPED = (
|
||||
"""
|
||||
"""
|
||||
An untrapped error occurred.
|
||||
""",
|
||||
"""
|
||||
"""
|
||||
An untrapped error occurred. Please file a bug report detailing the steps to reproduce.
|
||||
""")
|
||||
|
||||
_ERROR_CMDSETS = (
|
||||
"""
|
||||
"""
|
||||
A cmdset merger-error occurred. This is often due to a syntax
|
||||
error in one of the cmdsets to merge.
|
||||
""",
|
||||
"""
|
||||
"""
|
||||
A cmdset merger-error occurred. Please file a bug report detailing the
|
||||
steps to reproduce.
|
||||
""")
|
||||
|
||||
_ERROR_NOCMDSETS = (
|
||||
"""
|
||||
"""
|
||||
No command sets found! This is a critical bug that can have
|
||||
multiple causes.
|
||||
""",
|
||||
"""
|
||||
"""
|
||||
No command sets found! This is a sign of a critical bug. If
|
||||
disconnecting/reconnecting doesn't" solve the problem, try to contact
|
||||
the server admin through" some other means for assistance.
|
||||
""")
|
||||
|
||||
_ERROR_CMDHANDLER = (
|
||||
"""
|
||||
"""
|
||||
A command handler bug occurred. If this is not due to a local change,
|
||||
please file a bug report with the Evennia project, including the
|
||||
traceback and steps to reproduce.
|
||||
""",
|
||||
"""
|
||||
"""
|
||||
A command handler bug occurred. Please notify staff - they should
|
||||
likely file a bug report with the Evennia project.
|
||||
""")
|
||||
|
|
@ -234,19 +234,23 @@ class NoCmdSets(Exception):
|
|||
|
||||
class ExecSystemCommand(Exception):
|
||||
"Run a system command"
|
||||
|
||||
def __init__(self, syscmd, sysarg):
|
||||
self.args = (syscmd, sysarg) # needed by exception error handling
|
||||
self.syscmd = syscmd
|
||||
self.sysarg = sysarg
|
||||
|
||||
|
||||
class ErrorReported(Exception):
|
||||
"Re-raised when a subsructure already reported the error"
|
||||
|
||||
def __init__(self, raw_string):
|
||||
self.args = (raw_string,)
|
||||
self.raw_string = raw_string
|
||||
|
||||
# Helper function
|
||||
|
||||
|
||||
@inlineCallbacks
|
||||
def get_and_merge_cmdsets(caller, session, account, obj, callertype, raw_string):
|
||||
"""
|
||||
|
|
@ -318,11 +322,11 @@ def get_and_merge_cmdsets(caller, session, account, obj, callertype, raw_string)
|
|||
# the no_superuser_bypass must be True)
|
||||
local_obj_cmdsets = \
|
||||
yield list(chain.from_iterable(
|
||||
lobj.cmdset.cmdset_stack for lobj in local_objlist
|
||||
if (lobj.cmdset.current and
|
||||
lobj.cmdset.cmdset_stack for lobj in local_objlist
|
||||
if (lobj.cmdset.current and
|
||||
lobj.access(caller, access_type='call', no_superuser_bypass=True))))
|
||||
for cset in local_obj_cmdsets:
|
||||
#This is necessary for object sets, or we won't be able to
|
||||
# This is necessary for object sets, or we won't be able to
|
||||
# separate the command sets from each other in a busy room. We
|
||||
# only keep the setting if duplicates were set to False/True
|
||||
# explicitly.
|
||||
|
|
@ -333,7 +337,6 @@ def get_and_merge_cmdsets(caller, session, account, obj, callertype, raw_string)
|
|||
_msg_err(caller, _ERROR_CMDSETS)
|
||||
raise ErrorReported(raw_string)
|
||||
|
||||
|
||||
@inlineCallbacks
|
||||
def _get_cmdsets(obj):
|
||||
"""
|
||||
|
|
@ -346,7 +349,7 @@ def get_and_merge_cmdsets(caller, session, account, obj, callertype, raw_string)
|
|||
_msg_err(caller, _ERROR_CMDSETS)
|
||||
raise ErrorReported(raw_string)
|
||||
try:
|
||||
returnValue((obj.cmdset.current, list(obj.cmdset.cmdset_stack)))
|
||||
returnValue((obj.cmdset.current, list(obj.cmdset.cmdset_stack)))
|
||||
except AttributeError:
|
||||
returnValue(((None, None, None), []))
|
||||
|
||||
|
|
@ -550,9 +553,9 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
|||
cmd.session = session
|
||||
cmd.account = account
|
||||
cmd.raw_string = unformatted_raw_string
|
||||
#cmd.obj # set via on-object cmdset handler for each command,
|
||||
# since this may be different for every command when
|
||||
# merging multuple cmdsets
|
||||
# cmd.obj # set via on-object cmdset handler for each command,
|
||||
# since this may be different for every command when
|
||||
# merging multuple cmdsets
|
||||
|
||||
if hasattr(cmd, 'obj') and hasattr(cmd.obj, 'scripts'):
|
||||
# cmd.obj is automatically made available by the cmdhandler.
|
||||
|
|
@ -615,7 +618,6 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
|||
finally:
|
||||
_COMMAND_NESTING[called_by] -= 1
|
||||
|
||||
|
||||
raw_string = to_unicode(raw_string, force_string=True)
|
||||
|
||||
session, account, obj = session, None, None
|
||||
|
|
@ -653,7 +655,7 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
|||
else:
|
||||
# no explicit cmdobject given, figure it out
|
||||
cmdset = yield get_and_merge_cmdsets(caller, session, account, obj,
|
||||
callertype, raw_string)
|
||||
callertype, raw_string)
|
||||
if not cmdset:
|
||||
# this is bad and shouldn't happen.
|
||||
raise NoCmdSets
|
||||
|
|
@ -701,8 +703,8 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
|||
# fallback to default error text
|
||||
sysarg = _("Command '%s' is not available.") % raw_string
|
||||
suggestions = string_suggestions(raw_string,
|
||||
cmdset.get_all_cmd_keys_and_aliases(caller),
|
||||
cutoff=0.7, maxnum=3)
|
||||
cmdset.get_all_cmd_keys_and_aliases(caller),
|
||||
cutoff=0.7, maxnum=3)
|
||||
if suggestions:
|
||||
sysarg += _(" Maybe you meant %s?") % utils.list_to_string(suggestions, _('or'), addquote=True)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from evennia.utils.logger import log_trace
|
|||
_MULTIMATCH_REGEX = re.compile(settings.SEARCH_MULTIMATCH_REGEX, re.I + re.U)
|
||||
_CMD_IGNORE_PREFIXES = settings.CMD_IGNORE_PREFIXES
|
||||
|
||||
|
||||
def cmdparser(raw_string, cmdset, caller, match_index=None):
|
||||
"""
|
||||
This function is called by the cmdhandler once it has
|
||||
|
|
@ -82,10 +83,10 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
|
|||
# use the cmdname as-is
|
||||
for cmd in cmdset:
|
||||
matches.extend([create_match(cmdname, raw_string, cmd, cmdname)
|
||||
for cmdname in [cmd.key] + cmd.aliases
|
||||
if cmdname and l_raw_string.startswith(cmdname.lower())
|
||||
and (not cmd.arg_regex or
|
||||
cmd.arg_regex.match(l_raw_string[len(cmdname):]))])
|
||||
for cmdname in [cmd.key] + cmd.aliases
|
||||
if cmdname and l_raw_string.startswith(cmdname.lower()) and
|
||||
(not cmd.arg_regex or
|
||||
cmd.arg_regex.match(l_raw_string[len(cmdname):]))])
|
||||
else:
|
||||
# strip prefixes set in settings
|
||||
for cmd in cmdset:
|
||||
|
|
@ -133,7 +134,7 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
|
|||
# See if it helps to analyze the match with preserved case but only if
|
||||
# it leaves at least one match.
|
||||
trimmed = [match for match in matches
|
||||
if raw_string.startswith(match[0])]
|
||||
if raw_string.startswith(match[0])]
|
||||
if trimmed:
|
||||
matches = trimmed
|
||||
|
||||
|
|
@ -151,10 +152,10 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
|
|||
quality = [mat[4] for mat in matches]
|
||||
matches = matches[-quality.count(quality[-1]):]
|
||||
|
||||
if len(matches) > 1 and match_index != None and 0 < match_index <= len(matches):
|
||||
if len(matches) > 1 and match_index is not None and 0 < match_index <= len(matches):
|
||||
# We couldn't separate match by quality, but we have an
|
||||
# index argument to tell us which match to use.
|
||||
matches = [matches[match_index-1]]
|
||||
matches = [matches[match_index - 1]]
|
||||
|
||||
# no matter what we have at this point, we have to return it.
|
||||
return matches
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class _CmdSetMeta(type):
|
|||
cls.key = cls.__name__
|
||||
cls.path = "%s.%s" % (cls.__module__, cls.__name__)
|
||||
|
||||
if not type(cls.key_mergetypes) == dict:
|
||||
if not isinstance(cls.key_mergetypes, dict):
|
||||
cls.key_mergetypes = {}
|
||||
|
||||
super(_CmdSetMeta, cls).__init__(*args, **kwargs)
|
||||
|
|
@ -188,7 +188,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
|
|||
|
||||
# initialize system
|
||||
self.at_cmdset_creation()
|
||||
self._contains_cache = WeakKeyDictionary()#{}
|
||||
self._contains_cache = WeakKeyDictionary() # {}
|
||||
|
||||
# Priority-sensitive merge operations for cmdsets
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
|
|||
cmdset_c.commands.extend(cmdset_b.commands)
|
||||
else:
|
||||
cmdset_c.commands.extend([cmd for cmd in cmdset_b
|
||||
if not cmd in cmdset_a])
|
||||
if cmd not in cmdset_a])
|
||||
return cmdset_c
|
||||
|
||||
def _intersect(self, cmdset_a, cmdset_b):
|
||||
|
|
@ -280,7 +280,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
|
|||
"""
|
||||
|
||||
cmdset_c = cmdset_a._duplicate()
|
||||
cmdset_c.commands = [cmd for cmd in cmdset_b if not cmd in cmdset_a]
|
||||
cmdset_c.commands = [cmd for cmd in cmdset_b if cmd not in cmdset_a]
|
||||
return cmdset_c
|
||||
|
||||
def _instantiate(self, cmd):
|
||||
|
|
@ -411,7 +411,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
|
|||
cmdset_c = self._replace(self, cmdset_a)
|
||||
elif mergetype == "Remove":
|
||||
cmdset_c = self._remove(self, cmdset_a)
|
||||
else: # Union
|
||||
else: # Union
|
||||
cmdset_c = self._union(self, cmdset_a)
|
||||
|
||||
# pass through options whenever they are set, unless the higher-prio
|
||||
|
|
@ -426,7 +426,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
|
|||
# This is used for diagnosis.
|
||||
cmdset_c.actual_mergetype = mergetype
|
||||
|
||||
#print "__add__ for %s (prio %i) called with %s (prio %i)." % (self.key, self.priority, cmdset_a.key, cmdset_a.priority)
|
||||
# print "__add__ for %s (prio %i) called with %s (prio %i)." % (self.key, self.priority, cmdset_a.key, cmdset_a.priority)
|
||||
|
||||
# return the system commands to the cmdset
|
||||
cmdset_c.add(sys_commands)
|
||||
|
|
@ -604,7 +604,7 @@ class CmdSet(with_metaclass(_CmdSetMeta, object)):
|
|||
names = []
|
||||
if caller:
|
||||
[names.extend(cmd._keyaliases) for cmd in self.commands
|
||||
if cmd.access(caller)]
|
||||
if cmd.access(caller)]
|
||||
else:
|
||||
[names.extend(cmd._keyaliases) for cmd in self.commands]
|
||||
return names
|
||||
|
|
|
|||
|
|
@ -86,32 +86,32 @@ _CMDSET_FALLBACKS = settings.CMDSET_FALLBACKS
|
|||
# Output strings
|
||||
|
||||
_ERROR_CMDSET_IMPORT = _(
|
||||
"""{traceback}
|
||||
"""{traceback}
|
||||
Error loading cmdset '{path}'
|
||||
(Traceback was logged {timestamp})""")
|
||||
|
||||
_ERROR_CMDSET_KEYERROR = _(
|
||||
"""Error loading cmdset: No cmdset class '{classname}' in '{path}'.
|
||||
"""Error loading cmdset: No cmdset class '{classname}' in '{path}'.
|
||||
(Traceback was logged {timestamp})""")
|
||||
|
||||
_ERROR_CMDSET_SYNTAXERROR = _(
|
||||
"""{traceback}
|
||||
"""{traceback}
|
||||
SyntaxError encountered when loading cmdset '{path}'.
|
||||
(Traceback was logged {timestamp})""")
|
||||
|
||||
_ERROR_CMDSET_EXCEPTION = _(
|
||||
"""{traceback}
|
||||
"""{traceback}
|
||||
Compile/Run error when loading cmdset '{path}'.",
|
||||
(Traceback was logged {timestamp})""")
|
||||
|
||||
_ERROR_CMDSET_FALLBACK = _(
|
||||
"""
|
||||
"""
|
||||
Error encountered for cmdset at path '{path}'.
|
||||
Replacing with fallback '{fallback_path}'.
|
||||
""")
|
||||
|
||||
_ERROR_CMDSET_NO_FALLBACK = _(
|
||||
"""Fallback path '{fallback_path}' failed to generate a cmdset."""
|
||||
"""Fallback path '{fallback_path}' failed to generate a cmdset."""
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -122,6 +122,7 @@ class _ErrorCmdSet(CmdSet):
|
|||
key = "_CMDSET_ERROR"
|
||||
errmessage = "Error when loading cmdset."
|
||||
|
||||
|
||||
class _EmptyCmdSet(CmdSet):
|
||||
"""
|
||||
This cmdset represents an empty cmdset
|
||||
|
|
@ -130,6 +131,7 @@ class _EmptyCmdSet(CmdSet):
|
|||
priority = -101
|
||||
mergetype = "Union"
|
||||
|
||||
|
||||
def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||
"""
|
||||
This helper function is used by the cmdsethandler to load a cmdset
|
||||
|
|
@ -154,11 +156,11 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
|
||||
"""
|
||||
python_paths = [path] + ["%s.%s" % (prefix, path)
|
||||
for prefix in _CMDSET_PATHS if not path.startswith(prefix)]
|
||||
for prefix in _CMDSET_PATHS if not path.startswith(prefix)]
|
||||
errstring = ""
|
||||
for python_path in python_paths:
|
||||
|
||||
if "." in path:
|
||||
if "." in path:
|
||||
modpath, classname = python_path.rsplit(".", 1)
|
||||
else:
|
||||
raise ImportError("The path '%s' is not on the form modulepath.ClassName" % path)
|
||||
|
|
@ -191,7 +193,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
continue
|
||||
_CACHED_CMDSETS[python_path] = cmdsetclass
|
||||
|
||||
#instantiate the cmdset (and catch its errors)
|
||||
# instantiate the cmdset (and catch its errors)
|
||||
if callable(cmdsetclass):
|
||||
cmdsetclass = cmdsetclass(cmdsetobj)
|
||||
return cmdsetclass
|
||||
|
|
@ -235,7 +237,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
err_cmdset = _ErrorCmdSet()
|
||||
err_cmdset.errmessage = errstring
|
||||
return err_cmdset
|
||||
return None # undefined error
|
||||
return None # undefined error
|
||||
|
||||
# classes
|
||||
|
||||
|
|
@ -278,7 +280,7 @@ class CmdSetHandler(object):
|
|||
self.permanent_paths = [""]
|
||||
|
||||
if init_true:
|
||||
self.update(init_mode=True) #is then called from the object __init__.
|
||||
self.update(init_mode=True) # is then called from the object __init__.
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
|
|
@ -311,8 +313,8 @@ class CmdSetHandler(object):
|
|||
if mergelist:
|
||||
tmpstring = _(" <Merged {mergelist} {mergetype}, prio {prio}>: {current}")
|
||||
string += tmpstring.format(mergelist="+".join(mergelist),
|
||||
mergetype=mergetype, prio=self.current.priority,
|
||||
current=self.current)
|
||||
mergetype=mergetype, prio=self.current.priority,
|
||||
current=self.current)
|
||||
else:
|
||||
permstring = "non-perm"
|
||||
if self.current.permanent:
|
||||
|
|
@ -322,7 +324,7 @@ class CmdSetHandler(object):
|
|||
prio=self.current.priority,
|
||||
permstring=permstring,
|
||||
keylist=", ".join(cmd.key for
|
||||
cmd in sorted(self.current, key=lambda o: o.key)))
|
||||
cmd in sorted(self.current, key=lambda o: o.key)))
|
||||
return string.strip()
|
||||
|
||||
def _import_cmdset(self, cmdset_path, emit_to_obj=None):
|
||||
|
|
@ -542,7 +544,6 @@ class CmdSetHandler(object):
|
|||
# legacy alias
|
||||
delete_default = remove_default
|
||||
|
||||
|
||||
def all(self):
|
||||
"""
|
||||
Show all cmdsets.
|
||||
|
|
@ -588,16 +589,16 @@ class CmdSetHandler(object):
|
|||
else:
|
||||
print [cset.path for cset in self.cmdset_stack], cmdset.path
|
||||
return any([cset for cset in self.cmdset_stack
|
||||
if cset.path == cmdset.path])
|
||||
if cset.path == cmdset.path])
|
||||
else:
|
||||
# try it as a path or key
|
||||
if must_be_default:
|
||||
return self.cmdset_stack and (
|
||||
self.cmdset_stack[0].key == cmdset or
|
||||
self.cmdset_stack[0].path == cmdset)
|
||||
self.cmdset_stack[0].key == cmdset or
|
||||
self.cmdset_stack[0].path == cmdset)
|
||||
else:
|
||||
return any([cset for cset in self.cmdset_stack
|
||||
if cset.path == cmdset or cset.key == cmdset])
|
||||
if cset.path == cmdset or cset.key == cmdset])
|
||||
|
||||
# backwards-compatability alias
|
||||
has_cmdset = has
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ def _init_command(cls, **kwargs):
|
|||
if "cmd:" not in cls.locks:
|
||||
cls.locks = "cmd:all();" + cls.locks
|
||||
for lockstring in cls.locks.split(';'):
|
||||
if lockstring and not ':' in lockstring:
|
||||
if lockstring and ':' not in lockstring:
|
||||
lockstring = "cmd:%s" % lockstring
|
||||
temp.append(lockstring)
|
||||
cls.lock_storage = ";".join(temp)
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ class CmdSessions(COMMAND_DEFAULT_CLASS):
|
|||
for sess in sorted(sessions, key=lambda x: x.sessid):
|
||||
char = account.get_puppet(sess)
|
||||
table.add_row(str(sess.sessid), str(sess.protocol_key),
|
||||
type(sess.address) == tuple and sess.address[0] or sess.address,
|
||||
isinstance(sess.address, tuple) and sess.address[0] or sess.address,
|
||||
char and str(char) or "None",
|
||||
char and str(char.location) or "N/A")
|
||||
self.msg("|wYour current session(s):|n\n%s" % table)
|
||||
|
|
@ -508,7 +508,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
|
|||
options["SCREENHEIGHT"] = options["SCREENHEIGHT"][0]
|
||||
else:
|
||||
options["SCREENHEIGHT"] = " \n".join("%s : %s" % (screenid, size)
|
||||
for screenid, size in options["SCREENHEIGHT"].iteritems())
|
||||
for screenid, size in options["SCREENHEIGHT"].iteritems())
|
||||
options.pop("TTYPE", None)
|
||||
|
||||
header = ("Name", "Value", "Saved") if saved_options else ("Name", "Value")
|
||||
|
|
@ -552,7 +552,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
|
|||
flags[new_name] = new_val
|
||||
self.msg("Option |w%s|n was changed from '|w%s|n' to '|w%s|n'." % (new_name, old_val, new_val))
|
||||
return {new_name: new_val}
|
||||
except Exception, err:
|
||||
except Exception as err:
|
||||
self.msg("|rCould not set option |w%s|r:|n %s" % (new_name, err))
|
||||
return False
|
||||
|
||||
|
|
@ -578,7 +578,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
|
|||
val = self.rhs.strip()
|
||||
optiondict = False
|
||||
if val and name in validators:
|
||||
optiondict = update(name, val, validators[name])
|
||||
optiondict = update(name, val, validators[name])
|
||||
else:
|
||||
self.msg("|rNo option named '|w%s|r'." % name)
|
||||
if optiondict:
|
||||
|
|
@ -664,7 +664,7 @@ class CmdQuit(COMMAND_DEFAULT_CLASS):
|
|||
if nsess == 2:
|
||||
account.msg("|RQuitting|n. One session is still connected.", session=self.session)
|
||||
elif nsess > 2:
|
||||
account.msg("|RQuitting|n. %i sessions are still connected." % (nsess-1), session=self.session)
|
||||
account.msg("|RQuitting|n. %i sessions are still connected." % (nsess - 1), session=self.session)
|
||||
else:
|
||||
# we are quitting the last available session
|
||||
account.msg("|RQuitting|n. Hope to see you again, soon.", session=self.session)
|
||||
|
|
@ -732,7 +732,7 @@ class CmdColorTest(COMMAND_DEFAULT_CLASS):
|
|||
for code, _ in ap.ansi_map[self.slice_dark_bg]]
|
||||
bright_bg = ["%s%s|n" % (code.replace("\\", ""), code.replace("|", "||").replace("\\", ""))
|
||||
for code, _ in ap.ansi_xterm256_bright_bg_map[self.slice_bright_bg]]
|
||||
dark_fg.extend(["" for _ in range(len(bright_fg)-len(dark_fg))])
|
||||
dark_fg.extend(["" for _ in range(len(bright_fg) - len(dark_fg))])
|
||||
table = utils.format_table([bright_fg, dark_fg, bright_bg, dark_bg])
|
||||
string = "ANSI colors:"
|
||||
for row in table:
|
||||
|
|
@ -751,16 +751,16 @@ class CmdColorTest(COMMAND_DEFAULT_CLASS):
|
|||
# foreground table
|
||||
table[ir].append("|%i%i%i%s|n" % (ir, ig, ib, "||%i%i%i" % (ir, ig, ib)))
|
||||
# background table
|
||||
table[6+ir].append("|%i%i%i|[%i%i%i%s|n"
|
||||
% (5 - ir, 5 - ig, 5 - ib, ir, ig, ib, "||[%i%i%i" % (ir, ig, ib)))
|
||||
table[6 + ir].append("|%i%i%i|[%i%i%i%s|n"
|
||||
% (5 - ir, 5 - ig, 5 - ib, ir, ig, ib, "||[%i%i%i" % (ir, ig, ib)))
|
||||
table = self.table_format(table)
|
||||
string = "Xterm256 colors (if not all hues show, your client might not report that it can handle xterm256):"
|
||||
string += "\n" + "\n".join("".join(row) for row in table)
|
||||
table = [[], [], [], [], [], [], [], [], [], [], [], []]
|
||||
for ibatch in range(4):
|
||||
for igray in range(6):
|
||||
letter = chr(97 + (ibatch*6 + igray))
|
||||
inverse = chr(122 - (ibatch*6 + igray))
|
||||
letter = chr(97 + (ibatch * 6 + igray))
|
||||
inverse = chr(122 - (ibatch * 6 + igray))
|
||||
table[0 + igray].append("|=%s%s |n" % (letter, "||=%s" % letter))
|
||||
table[6 + igray].append("|=%s|[=%s%s |n" % (inverse, letter, "||[=%s" % letter))
|
||||
for igray in range(6):
|
||||
|
|
|
|||
|
|
@ -171,9 +171,9 @@ class CmdBan(COMMAND_DEFAULT_CLASS):
|
|||
if not banlist:
|
||||
banlist = []
|
||||
|
||||
if not self.args or (self.switches
|
||||
and not any(switch in ('ip', 'name')
|
||||
for switch in self.switches)):
|
||||
if not self.args or (self.switches and
|
||||
not any(switch in ('ip', 'name')
|
||||
for switch in self.switches)):
|
||||
self.caller.msg(list_bans(banlist))
|
||||
return
|
||||
|
||||
|
|
@ -430,7 +430,7 @@ class CmdNewPassword(COMMAND_DEFAULT_CLASS):
|
|||
self.msg("%s - new password set to '%s'." % (account.name, self.rhs))
|
||||
if account.character != caller:
|
||||
account.msg("%s has changed your password to '%s'." % (caller.name,
|
||||
self.rhs))
|
||||
self.rhs))
|
||||
|
||||
|
||||
class CmdPerm(COMMAND_DEFAULT_CLASS):
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ _DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
|
|||
|
||||
_PROTOTYPE_PARENTS = None
|
||||
|
||||
|
||||
class ObjManipCommand(COMMAND_DEFAULT_CLASS):
|
||||
"""
|
||||
This is a parent class for some of the defining objmanip commands
|
||||
|
|
@ -73,7 +74,7 @@ class ObjManipCommand(COMMAND_DEFAULT_CLASS):
|
|||
super(ObjManipCommand, self).parse()
|
||||
|
||||
obj_defs = ([], []) # stores left- and right-hand side of '='
|
||||
obj_attrs = ([], []) # "
|
||||
obj_attrs = ([], []) # "
|
||||
|
||||
for iside, arglist in enumerate((self.lhslist, self.rhslist)):
|
||||
# lhslist/rhslist is already split by ',' at this point
|
||||
|
|
@ -88,8 +89,8 @@ class ObjManipCommand(COMMAND_DEFAULT_CLASS):
|
|||
objdef, attrs = [part.strip() for part in objdef.split('/', 1)]
|
||||
attrs = [part.strip().lower() for part in attrs.split('/') if part.strip()]
|
||||
# store data
|
||||
obj_defs[iside].append({"name":objdef, 'option':option, 'aliases':aliases})
|
||||
obj_attrs[iside].append({"name":objdef, 'attrs':attrs})
|
||||
obj_defs[iside].append({"name": objdef, 'option': option, 'aliases': aliases})
|
||||
obj_attrs[iside].append({"name": objdef, 'attrs': attrs})
|
||||
|
||||
# store for future access
|
||||
self.lhs_objs = obj_defs[0]
|
||||
|
|
@ -242,9 +243,9 @@ class CmdCopy(ObjManipCommand):
|
|||
return
|
||||
|
||||
copiedobj = ObjectDB.objects.copy_object(from_obj,
|
||||
new_key=to_obj_name,
|
||||
new_location=to_obj_location,
|
||||
new_aliases=to_obj_aliases)
|
||||
new_key=to_obj_name,
|
||||
new_location=to_obj_location,
|
||||
new_aliases=to_obj_aliases)
|
||||
if copiedobj:
|
||||
string = "Copied %s to '%s' (aliases: %s)." % (from_obj_name, to_obj_name,
|
||||
to_obj_aliases)
|
||||
|
|
@ -350,7 +351,7 @@ class CmdCpAttr(ObjManipCommand):
|
|||
if not from_obj or not to_objs:
|
||||
caller.msg("You have to supply both source object and target(s).")
|
||||
return
|
||||
#copy to all to_obj:ects
|
||||
# copy to all to_obj:ects
|
||||
if "move" in self.switches:
|
||||
clear = True
|
||||
else:
|
||||
|
|
@ -387,7 +388,7 @@ class CmdCpAttr(ObjManipCommand):
|
|||
value = self.get_attr(from_obj, from_attr)
|
||||
to_obj.attributes.add(to_attr, value)
|
||||
if (clear and not (from_obj == to_obj and
|
||||
from_attr == to_attr)):
|
||||
from_attr == to_attr)):
|
||||
from_obj.attributes.remove(from_attr)
|
||||
result.append("\nMoved %s.%s -> %s.%s. (value: %s)" % (from_obj.name,
|
||||
from_attr,
|
||||
|
|
@ -522,6 +523,7 @@ class CmdCreate(ObjManipCommand):
|
|||
def _desc_load(caller):
|
||||
return caller.db.evmenu_target.db.desc or ""
|
||||
|
||||
|
||||
def _desc_save(caller, buf):
|
||||
"""
|
||||
Save line buffer to the desc prop. This should
|
||||
|
|
@ -531,10 +533,12 @@ def _desc_save(caller, buf):
|
|||
caller.msg("Saved.")
|
||||
return True
|
||||
|
||||
|
||||
def _desc_quit(caller):
|
||||
caller.attributes.remove("evmenu_target")
|
||||
caller.msg("Exited editor.")
|
||||
|
||||
|
||||
class CmdDesc(COMMAND_DEFAULT_CLASS):
|
||||
"""
|
||||
describe an object or the current room.
|
||||
|
|
@ -642,12 +646,12 @@ class CmdDestroy(COMMAND_DEFAULT_CLASS):
|
|||
objname = obj.name
|
||||
if not (obj.access(caller, "control") or obj.access(caller, 'delete')):
|
||||
return "\nYou don't have permission to delete %s." % objname
|
||||
if obj.account and not 'override' in self.switches:
|
||||
if obj.account and 'override' not in self.switches:
|
||||
return "\nObject %s is controlled by an active account. Use /override to delete anyway." % objname
|
||||
if obj.dbid == int(settings.DEFAULT_HOME.lstrip("#")):
|
||||
return "\nYou are trying to delete |c%s|n, which is set as DEFAULT_HOME. " \
|
||||
"Re-point settings.DEFAULT_HOME to another " \
|
||||
"object before continuing." % objname
|
||||
"Re-point settings.DEFAULT_HOME to another " \
|
||||
"object before continuing." % objname
|
||||
|
||||
had_exits = hasattr(obj, "exits") and obj.exits
|
||||
had_objs = hasattr(obj, "contents") and any(obj for obj in obj.contents
|
||||
|
|
@ -749,7 +753,7 @@ class CmdDig(ObjManipCommand):
|
|||
if new_room.aliases.all():
|
||||
alias_string = " (%s)" % ", ".join(new_room.aliases.all())
|
||||
room_string = "Created room %s(%s)%s of type %s." % (new_room,
|
||||
new_room.dbref, alias_string, typeclass)
|
||||
new_room.dbref, alias_string, typeclass)
|
||||
|
||||
# create exit to room
|
||||
|
||||
|
|
@ -763,7 +767,7 @@ class CmdDig(ObjManipCommand):
|
|||
"\nNo exit created to new room."
|
||||
elif not location:
|
||||
exit_to_string = \
|
||||
"\nYou cannot create an exit from a None-location."
|
||||
"\nYou cannot create an exit from a None-location."
|
||||
else:
|
||||
# Build the exit to the new room from the current one
|
||||
typeclass = to_exit["option"]
|
||||
|
|
@ -796,18 +800,18 @@ class CmdDig(ObjManipCommand):
|
|||
"\nNo back exit created."
|
||||
elif not location:
|
||||
exit_back_string = \
|
||||
"\nYou cannot create an exit back to a None-location."
|
||||
"\nYou cannot create an exit back to a None-location."
|
||||
else:
|
||||
typeclass = back_exit["option"]
|
||||
if not typeclass:
|
||||
typeclass = settings.BASE_EXIT_TYPECLASS
|
||||
new_back_exit = create.create_object(typeclass,
|
||||
back_exit["name"],
|
||||
new_room,
|
||||
aliases=back_exit["aliases"],
|
||||
locks=lockstring,
|
||||
destination=location,
|
||||
report_to=caller)
|
||||
back_exit["name"],
|
||||
new_room,
|
||||
aliases=back_exit["aliases"],
|
||||
locks=lockstring,
|
||||
destination=location,
|
||||
report_to=caller)
|
||||
alias_string = ""
|
||||
if new_back_exit.aliases.all():
|
||||
alias_string = " (%s)" % ", ".join(new_back_exit.aliases.all())
|
||||
|
|
@ -821,6 +825,7 @@ class CmdDig(ObjManipCommand):
|
|||
if new_room and ('teleport' in self.switches or "tel" in self.switches):
|
||||
caller.move_to(new_room)
|
||||
|
||||
|
||||
class CmdTunnel(COMMAND_DEFAULT_CLASS):
|
||||
"""
|
||||
create new rooms in cardinal directions only
|
||||
|
|
@ -893,7 +898,7 @@ class CmdTunnel(COMMAND_DEFAULT_CLASS):
|
|||
if "tel" in self.switches:
|
||||
telswitch = "/teleport"
|
||||
backstring = ""
|
||||
if not "oneway" in self.switches:
|
||||
if "oneway" not in self.switches:
|
||||
backstring = ", %s;%s" % (backname, backshort)
|
||||
|
||||
# build the string we will use to call @dig
|
||||
|
|
@ -951,7 +956,7 @@ class CmdLink(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
string = ""
|
||||
if not obj.destination:
|
||||
string += "Note: %s(%s) did not have a destination set before. Make sure you linked the right thing." % (obj.name,obj.dbref)
|
||||
string += "Note: %s(%s) did not have a destination set before. Make sure you linked the right thing." % (obj.name, obj.dbref)
|
||||
if "twoway" in self.switches:
|
||||
if not (target.location and obj.location):
|
||||
string = "To create a two-way link, %s and %s must both have a location" % (obj, target)
|
||||
|
|
@ -1199,7 +1204,7 @@ class CmdOpen(ObjManipCommand):
|
|||
|
||||
# a custom member method to chug out exits and do checks
|
||||
def create_exit(self, exit_name, location, destination,
|
||||
exit_aliases=None, typeclass=None):
|
||||
exit_aliases=None, typeclass=None):
|
||||
"""
|
||||
Helper function to avoid code duplication.
|
||||
At this point we know destination is a valid location
|
||||
|
|
@ -1484,10 +1489,11 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
old_value = obj.attributes.get(attr)
|
||||
if old_value is not None and not isinstance(old_value, basestring):
|
||||
typ = type(old_value).__name__
|
||||
self.caller.msg("|RWARNING! Saving this buffer will overwrite the "\
|
||||
self.caller.msg("|RWARNING! Saving this buffer will overwrite the "
|
||||
"current attribute (of type %s) with a string!|n" % typ)
|
||||
return str(old_value)
|
||||
return old_value
|
||||
|
||||
def save(caller, buf):
|
||||
"Called when editor saves its buffer."
|
||||
obj.attributes.add(attr, buf)
|
||||
|
|
@ -1495,7 +1501,6 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
# start the editor
|
||||
EvEditor(self.caller, load, save, key="%s/%s" % (obj, attr))
|
||||
|
||||
|
||||
def func(self):
|
||||
"Implement the set attribute - a limited form of @py."
|
||||
|
||||
|
|
@ -1523,7 +1528,7 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
if "edit" in self.switches:
|
||||
# edit in the line editor
|
||||
if len(attrs) > 1:
|
||||
caller.msg("The Line editor can only be applied " \
|
||||
caller.msg("The Line editor can only be applied "
|
||||
"to one attribute at a time.")
|
||||
return
|
||||
self.edit_handler(obj, attrs[0])
|
||||
|
|
@ -1538,7 +1543,7 @@ class CmdSetAttribute(ObjManipCommand):
|
|||
continue
|
||||
result.append(self.view_attr(obj, attr))
|
||||
# we view it without parsing markup.
|
||||
self.caller.msg("".join(result).strip(), options={"raw":True})
|
||||
self.caller.msg("".join(result).strip(), options={"raw": True})
|
||||
return
|
||||
else:
|
||||
# deleting the attribute(s)
|
||||
|
|
@ -1644,7 +1649,7 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
|
|||
return
|
||||
|
||||
is_same = obj.is_typeclass(new_typeclass, exact=True)
|
||||
if is_same and not 'force' in self.switches:
|
||||
if is_same and 'force' not in self.switches:
|
||||
string = "%s already has the typeclass '%s'. Use /force to override." % (obj.name, new_typeclass)
|
||||
else:
|
||||
update = "update" in self.switches
|
||||
|
|
@ -1654,14 +1659,14 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
# we let this raise exception if needed
|
||||
obj.swap_typeclass(new_typeclass, clean_attributes=reset,
|
||||
clean_cmdsets=reset, run_start_hooks=hooks)
|
||||
clean_cmdsets=reset, run_start_hooks=hooks)
|
||||
|
||||
if is_same:
|
||||
string = "%s updated its existing typeclass (%s).\n" % (obj.name, obj.path)
|
||||
else:
|
||||
string = "%s changed typeclass from %s to %s.\n" % (obj.name,
|
||||
old_typeclass_path,
|
||||
obj.typeclass_path)
|
||||
old_typeclass_path,
|
||||
obj.typeclass_path)
|
||||
if update:
|
||||
string += "Only the at_object_creation hook was run (update mode)."
|
||||
else:
|
||||
|
|
@ -1797,8 +1802,8 @@ class CmdLock(ObjManipCommand):
|
|||
# we have a = separator, so we are assigning a new lock
|
||||
if self.switches:
|
||||
swi = ", ".join(self.switches)
|
||||
caller.msg("Switch(es) |w%s|n can not be used with a "\
|
||||
"lock assignment. Use e.g. " \
|
||||
caller.msg("Switch(es) |w%s|n can not be used with a "
|
||||
"lock assignment. Use e.g. "
|
||||
"|w@lock/del objname/locktype|n instead." % swi)
|
||||
return
|
||||
|
||||
|
|
@ -1851,7 +1856,7 @@ class CmdExamine(ObjManipCommand):
|
|||
|
||||
"""
|
||||
key = "@examine"
|
||||
aliases = ["@ex","exam"]
|
||||
aliases = ["@ex", "exam"]
|
||||
locks = "cmd:perm(examine) or perm(Builder)"
|
||||
help_category = "Building"
|
||||
arg_regex = r"(/\w+?(\s|$))|\s|$"
|
||||
|
|
@ -1913,7 +1918,7 @@ class CmdExamine(ObjManipCommand):
|
|||
string += "\n|wAliases|n: %s" % (", ".join(utils.make_iter(str(obj.aliases))))
|
||||
if hasattr(obj, "sessions") and obj.sessions.all():
|
||||
string += "\n|wSession id(s)|n: %s" % (", ".join("#%i" % sess.sessid
|
||||
for sess in obj.sessions.all()))
|
||||
for sess in obj.sessions.all()))
|
||||
if hasattr(obj, "email") and obj.email:
|
||||
string += "\n|wEmail|n: |c%s|n" % obj.email
|
||||
if hasattr(obj, "has_account") and obj.has_account:
|
||||
|
|
@ -1957,20 +1962,19 @@ class CmdExamine(ObjManipCommand):
|
|||
locks_string = " Default"
|
||||
string += "\n|wLocks|n:%s" % locks_string
|
||||
|
||||
|
||||
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"):
|
||||
# all() returns a 'stack', so make a copy to sort.
|
||||
stored_cmdsets = sorted(obj.cmdset.all(), key=lambda x: x.priority, reverse=True)
|
||||
string += "\n|wStored Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \
|
||||
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
|
||||
for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET"))
|
||||
string += "\n|wStored Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" %
|
||||
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
|
||||
for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET"))
|
||||
|
||||
# this gets all components of the currently merged set
|
||||
all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from]
|
||||
# we always at least try to add account- and session sets since these are ignored
|
||||
# if we merge on the object level.
|
||||
if hasattr(obj, "account") and obj.account:
|
||||
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.account.cmdset.all()])
|
||||
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.account.cmdset.all()])
|
||||
if obj.sessions.count():
|
||||
# if there are more sessions than one on objects it's because of multisession mode 3.
|
||||
# we only show the first session's cmdset here (it is -in principle- possible that
|
||||
|
|
@ -1986,14 +1990,13 @@ class CmdExamine(ObjManipCommand):
|
|||
pass
|
||||
all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()]
|
||||
all_cmdsets.sort(key=lambda x: x.priority, reverse=True)
|
||||
string += "\n|wMerged Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \
|
||||
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
|
||||
for cmdset in all_cmdsets))
|
||||
|
||||
string += "\n|wMerged Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" %
|
||||
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
|
||||
for cmdset in all_cmdsets))
|
||||
|
||||
# list the commands available to this object
|
||||
avail_cmdset = sorted([cmd.key for cmd in avail_cmdset
|
||||
if cmd.access(obj, "cmd")])
|
||||
if cmd.access(obj, "cmd")])
|
||||
|
||||
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
|
||||
string += "\n|wCommands available to %s (result of Merged CmdSets)|n:\n %s" % (obj.key, cmdsetstr)
|
||||
|
|
@ -2005,7 +2008,7 @@ class CmdExamine(ObjManipCommand):
|
|||
|
||||
# display Tags
|
||||
tags_string = utils.fill(", ".join("%s[%s]" % (tag, category)
|
||||
for tag, category in obj.tags.all(return_key_and_category=True)), indent=5)
|
||||
for tag, category in obj.tags.all(return_key_and_category=True)), indent=5)
|
||||
if tags_string:
|
||||
string += "\n|wTags[category]|n: %s" % tags_string.strip()
|
||||
|
||||
|
|
@ -2029,7 +2032,7 @@ class CmdExamine(ObjManipCommand):
|
|||
string += "\n|wContents|n: %s" % ", ".join(["%s(%s)" % (cont.name, cont.dbref) for cont in obj.contents
|
||||
if cont not in exits and cont not in pobjs])
|
||||
separator = "-" * _DEFAULT_WIDTH
|
||||
#output info
|
||||
# output info
|
||||
return '%s\n%s\n%s' % (separator, string.strip(), separator)
|
||||
|
||||
def func(self):
|
||||
|
|
@ -2053,7 +2056,7 @@ class CmdExamine(ObjManipCommand):
|
|||
if hasattr(caller, "location"):
|
||||
obj = caller.location
|
||||
if not obj.access(caller, 'examine'):
|
||||
#If we don't have special info access, just look at the object instead.
|
||||
# If we don't have special info access, just look at the object instead.
|
||||
self.msg(caller.at_look(obj))
|
||||
return
|
||||
# using callback for printing result whenever function returns.
|
||||
|
|
@ -2070,20 +2073,20 @@ class CmdExamine(ObjManipCommand):
|
|||
obj_attrs = objdef['attrs']
|
||||
|
||||
self.account_mode = utils.inherits_from(caller, "evennia.accounts.accounts.DefaultAccount") or \
|
||||
"account" in self.switches or obj_name.startswith('*')
|
||||
"account" in self.switches or obj_name.startswith('*')
|
||||
if self.account_mode:
|
||||
try:
|
||||
obj = caller.search_account(obj_name.lstrip('*'))
|
||||
except AttributeError:
|
||||
# this means we are calling examine from an account object
|
||||
obj = caller.search(obj_name.lstrip('*'), search_object = 'object' in self.switches)
|
||||
obj = caller.search(obj_name.lstrip('*'), search_object='object' in self.switches)
|
||||
else:
|
||||
obj = caller.search(obj_name)
|
||||
if not obj:
|
||||
continue
|
||||
|
||||
if not obj.access(caller, 'examine'):
|
||||
#If we don't have special info access, just look
|
||||
# If we don't have special info access, just look
|
||||
# at the object instead.
|
||||
self.msg(caller.at_look(obj))
|
||||
continue
|
||||
|
|
@ -2184,7 +2187,7 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
elif not low <= int(result[0].id) <= high:
|
||||
string += "\n |RNo match found for '%s' in #dbref interval.|n" % (searchstring)
|
||||
else:
|
||||
result=result[0]
|
||||
result = result[0]
|
||||
string += "\n|g %s - %s|n" % (result.get_display_name(caller), result.path)
|
||||
else:
|
||||
# Not an account/dbref search but a wider search; build a queryset.
|
||||
|
|
@ -2192,7 +2195,7 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
if "exact" in switches:
|
||||
keyquery = Q(db_key__iexact=searchstring, id__gte=low, id__lte=high)
|
||||
aliasquery = Q(db_tags__db_key__iexact=searchstring,
|
||||
db_tags__db_tagtype__iexact="alias",id__gte=low, id__lte=high)
|
||||
db_tags__db_tagtype__iexact="alias", id__gte=low, id__lte=high)
|
||||
else:
|
||||
keyquery = Q(db_key__istartswith=searchstring, id__gte=low, id__lte=high)
|
||||
aliasquery = Q(db_tags__db_key__istartswith=searchstring,
|
||||
|
|
@ -2283,14 +2286,14 @@ class CmdTeleport(COMMAND_DEFAULT_CLASS):
|
|||
if obj_to_teleport.has_account:
|
||||
caller.msg("Cannot teleport a puppeted object "
|
||||
"(%s, puppeted by %s) to a None-location." % (
|
||||
obj_to_teleport.key, obj_to_teleport.account))
|
||||
obj_to_teleport.key, obj_to_teleport.account))
|
||||
return
|
||||
caller.msg("Teleported %s -> None-location." % obj_to_teleport)
|
||||
if obj_to_teleport.location and not tel_quietly:
|
||||
obj_to_teleport.location.msg_contents("%s teleported %s into nothingness."
|
||||
% (caller, obj_to_teleport),
|
||||
exclude=caller)
|
||||
obj_to_teleport.location=None
|
||||
obj_to_teleport.location = None
|
||||
return
|
||||
|
||||
# not teleporting to None location
|
||||
|
|
@ -2397,7 +2400,7 @@ class CmdScript(COMMAND_DEFAULT_CLASS):
|
|||
obj.get_display_name(caller)))
|
||||
script.stop()
|
||||
obj.scripts.validate()
|
||||
else: # rhs exists
|
||||
else: # rhs exists
|
||||
if not self.switches:
|
||||
# adding a new script, and starting it
|
||||
ok = obj.scripts.add(self.rhs, autostart=True)
|
||||
|
|
@ -2478,16 +2481,16 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
|
|||
nobjs = len(objs)
|
||||
if nobjs > 0:
|
||||
catstr = " (category: '|w%s|n')" % category if category else \
|
||||
("" if nobjs == 1 else " (may have different tag categories)")
|
||||
("" if nobjs == 1 else " (may have different tag categories)")
|
||||
matchstr = ", ".join(o.get_display_name(self.caller) for o in objs)
|
||||
|
||||
string = "Found |w%i|n object%s with tag '|w%s|n'%s:\n %s" % (nobjs,
|
||||
"s" if nobjs > 1 else "",
|
||||
tag,
|
||||
catstr, matchstr)
|
||||
"s" if nobjs > 1 else "",
|
||||
tag,
|
||||
catstr, matchstr)
|
||||
else:
|
||||
string = "No objects found with tag '%s%s'." % (tag,
|
||||
" (category: %s)" % category if category else "")
|
||||
" (category: %s)" % category if category else "")
|
||||
self.caller.msg(string)
|
||||
return
|
||||
if "del" in self.switches:
|
||||
|
|
@ -2504,14 +2507,14 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
|
|||
if obj.tags.get(tag, category=category):
|
||||
obj.tags.remove(tag, category=category)
|
||||
string = "Removed tag '%s'%s from %s." % (
|
||||
tag,
|
||||
" (category: %s)" % category if category else "",
|
||||
obj)
|
||||
tag,
|
||||
" (category: %s)" % category if category else "",
|
||||
obj)
|
||||
else:
|
||||
string = "No tag '%s'%s to delete on %s." % (
|
||||
tag,
|
||||
" (category: %s)" % category if category else "",
|
||||
obj)
|
||||
tag,
|
||||
" (category: %s)" % category if category else "",
|
||||
obj)
|
||||
else:
|
||||
# no tag specified, clear all tags
|
||||
old_tags = ["%s%s" % (tag, " (category: %s" % category if category else "")
|
||||
|
|
@ -2550,7 +2553,7 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
|
|||
categories = [" (category: %s)" % tup[1] if tup[1] else "" for tup in tagtuples]
|
||||
if ntags:
|
||||
string = "Tag%s on %s: %s" % ("s" if ntags > 1 else "", obj,
|
||||
", ".join("'%s'%s" % (tags[i], categories[i]) for i in range(ntags)))
|
||||
", ".join("'%s'%s" % (tags[i], categories[i]) for i in range(ntags)))
|
||||
else:
|
||||
string = "No tags attached to %s." % obj
|
||||
self.caller.msg(string)
|
||||
|
|
@ -2561,6 +2564,7 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
|
|||
# Reload the server and the prototypes should be available.
|
||||
#
|
||||
|
||||
|
||||
class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
||||
"""
|
||||
spawn objects from prototype
|
||||
|
|
@ -2608,7 +2612,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||
"Helper to show a list of available prototypes"
|
||||
prots = ", ".join(sorted(prototypes.keys()))
|
||||
return "\nAvailable prototypes (case sensistive): %s" % \
|
||||
("\n" + utils.fill(prots) if prots else "None")
|
||||
("\n" + utils.fill(prots) if prots else "None")
|
||||
|
||||
prototypes = spawn(return_prototypes=True)
|
||||
if not self.args:
|
||||
|
|
@ -2628,7 +2632,6 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||
self.caller.msg(string)
|
||||
return
|
||||
|
||||
|
||||
if isinstance(prototype, basestring):
|
||||
# A prototype key
|
||||
keystr = prototype
|
||||
|
|
@ -2647,9 +2650,8 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||
self.caller.msg("The prototype must be a prototype key or a Python dictionary.")
|
||||
return
|
||||
|
||||
if not "noloc" in self.switches and not "location" in prototype:
|
||||
if "noloc" in self.switches and not "location" not in prototype:
|
||||
prototype["location"] = self.caller.location
|
||||
|
||||
for obj in spawn(prototype):
|
||||
self.caller.msg("Spawned %s." % obj.get_display_name(self.caller))
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class AccountCmdSet(CmdSet):
|
|||
self.add(account.CmdOOC())
|
||||
self.add(account.CmdCharCreate())
|
||||
self.add(account.CmdCharDelete())
|
||||
#self.add(account.CmdSessions())
|
||||
# self.add(account.CmdSessions())
|
||||
self.add(account.CmdWho())
|
||||
self.add(account.CmdOption())
|
||||
self.add(account.CmdQuit())
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from evennia.commands.default import general, help, admin, system
|
|||
from evennia.commands.default import building
|
||||
from evennia.commands.default import batchprocess
|
||||
|
||||
|
||||
class CharacterCmdSet(CmdSet):
|
||||
"""
|
||||
Implements the default command set.
|
||||
|
|
@ -46,7 +47,7 @@ class CharacterCmdSet(CmdSet):
|
|||
self.add(system.CmdAbout())
|
||||
self.add(system.CmdTime())
|
||||
self.add(system.CmdServerLoad())
|
||||
#self.add(system.CmdPs())
|
||||
# self.add(system.CmdPs())
|
||||
self.add(system.CmdTickers())
|
||||
|
||||
# Admin commands
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ This module stores session-level commands.
|
|||
from evennia.commands.cmdset import CmdSet
|
||||
from evennia.commands.default import account
|
||||
|
||||
|
||||
class SessionCmdSet(CmdSet):
|
||||
"""
|
||||
Sets up the unlogged cmdset.
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ class CmdChannels(COMMAND_DEFAULT_CLASS):
|
|||
clower = chan.key.lower()
|
||||
nicks = caller.nicks.get(category="channel", return_obj=True)
|
||||
comtable.add_row(*["%s%s" % (chan.key, chan.aliases.all() and
|
||||
"(%s)" % ",".join(chan.aliases.all()) or ""),
|
||||
"(%s)" % ",".join(chan.aliases.all()) or ""),
|
||||
"%s" % ",".join(nick.db_key for nick in make_iter(nicks)
|
||||
if nick and nick.value[3].lower() == clower),
|
||||
chan.db.desc])
|
||||
|
|
@ -614,7 +614,7 @@ class CmdClock(COMMAND_DEFAULT_CLASS):
|
|||
# Try to add the lock
|
||||
try:
|
||||
channel.locks.add(self.rhs)
|
||||
except LockException, err:
|
||||
except LockException as err:
|
||||
self.msg(err)
|
||||
return
|
||||
string = "Lock(s) applied. "
|
||||
|
|
@ -890,7 +890,7 @@ class CmdIRC2Chan(COMMAND_DEFAULT_CLASS):
|
|||
self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues
|
||||
try:
|
||||
irc_network, irc_port, irc_channel, irc_botname = \
|
||||
[part.strip() for part in self.rhs.split(None, 4)]
|
||||
[part.strip() for part in self.rhs.split(None, 4)]
|
||||
irc_channel = "#%s" % irc_channel
|
||||
except Exception:
|
||||
string = "IRC bot definition '%s' is not valid." % self.rhs
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
|||
# we are given a index in nicklist
|
||||
delindex = int(arg)
|
||||
if 0 < delindex <= len(nicklist):
|
||||
oldnick = nicklist[delindex-1]
|
||||
oldnick = nicklist[delindex - 1]
|
||||
_, _, old_nickstring, old_replstring = oldnick.value
|
||||
else:
|
||||
errstring += "Not a valid nick index."
|
||||
|
|
@ -419,6 +419,7 @@ class CmdSay(COMMAND_DEFAULT_CLASS):
|
|||
# Call the at_after_say hook on the character
|
||||
caller.at_say(speech)
|
||||
|
||||
|
||||
class CmdWhisper(COMMAND_DEFAULT_CLASS):
|
||||
"""
|
||||
Speak privately as your character to another
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class MuxCommand(Command):
|
|||
used by Evennia to create the automatic help entry for
|
||||
the command, so make sure to document consistently here.
|
||||
"""
|
||||
|
||||
def has_perm(self, srcobj):
|
||||
"""
|
||||
This is called by the cmdhandler to determine
|
||||
|
|
@ -191,6 +192,7 @@ class MuxAccountCommand(MuxCommand):
|
|||
creating a new property "character" that is set only if a
|
||||
character is actually attached to this Account and Session.
|
||||
"""
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
We run the parent parser as usual, then fix the result
|
||||
|
|
|
|||
|
|
@ -133,11 +133,11 @@ def _py_code(caller, buf):
|
|||
"""
|
||||
measure_time = caller.db._py_measure_time
|
||||
string = "Executing code%s ..." % (
|
||||
" (measure timing)" if measure_time else "")
|
||||
" (measure timing)" if measure_time else "")
|
||||
caller.msg(string)
|
||||
_run_code_snippet(caller, buf, mode="exec",
|
||||
measure_time=measure_time,
|
||||
show_input=False)
|
||||
measure_time=measure_time,
|
||||
show_input=False)
|
||||
return True
|
||||
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ def _py_quit(caller):
|
|||
|
||||
|
||||
def _run_code_snippet(caller, pycode, mode="eval", measure_time=False,
|
||||
show_input=True):
|
||||
show_input=True):
|
||||
"""
|
||||
Run code and try to display information to the caller.
|
||||
|
||||
|
|
@ -166,18 +166,18 @@ def _run_code_snippet(caller, pycode, mode="eval", measure_time=False,
|
|||
# import useful variables
|
||||
import evennia
|
||||
available_vars = {
|
||||
'self': caller,
|
||||
'me': caller,
|
||||
'here': getattr(caller, "location", None),
|
||||
'evennia': evennia,
|
||||
'ev': evennia,
|
||||
'inherits_from': utils.inherits_from,
|
||||
'self': caller,
|
||||
'me': caller,
|
||||
'here': getattr(caller, "location", None),
|
||||
'evennia': evennia,
|
||||
'ev': evennia,
|
||||
'inherits_from': utils.inherits_from,
|
||||
}
|
||||
|
||||
if show_input:
|
||||
try:
|
||||
caller.msg(">>> %s" % pycode, session=session,
|
||||
options={"raw": True})
|
||||
options={"raw": True})
|
||||
except TypeError:
|
||||
caller.msg(">>> %s" % pycode, options={"raw": True})
|
||||
|
||||
|
|
@ -256,8 +256,8 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
|
|||
if "edit" in self.switches:
|
||||
caller.db._py_measure_time = "time" in self.switches
|
||||
EvEditor(self.caller, loadfunc=_py_load, savefunc=_py_code,
|
||||
quitfunc=_py_quit, key="Python exec: :w or :!", persistent=True,
|
||||
codefunc=_py_code)
|
||||
quitfunc=_py_quit, key="Python exec: :w or :!", persistent=True,
|
||||
codefunc=_py_code)
|
||||
return
|
||||
|
||||
if not pycode:
|
||||
|
|
@ -719,7 +719,7 @@ class CmdServerLoad(COMMAND_DEFAULT_CLASS):
|
|||
now, _ = _IDMAPPER.cache_size()
|
||||
string = "The Idmapper cache freed |w{idmapper}|n database objects.\n" \
|
||||
"The Python garbage collector freed |w{gc}|n Python instances total."
|
||||
self.caller.msg(string.format(idmapper=(prev-now), gc=nflushed))
|
||||
self.caller.msg(string.format(idmapper=(prev - now), gc=nflushed))
|
||||
return
|
||||
|
||||
# display active processes
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class CommandTest(EvenniaTest):
|
|||
cmdobj.caller = caller
|
||||
cmdobj.cmdname = cmdstring if cmdstring else cmdobj.key
|
||||
cmdobj.raw_cmdname = cmdobj.cmdname
|
||||
cmdobj.cmdstring = cmdobj.cmdname # deprecated
|
||||
cmdobj.cmdstring = cmdobj.cmdname # deprecated
|
||||
cmdobj.args = args
|
||||
cmdobj.cmdset = cmdset
|
||||
cmdobj.session = SESSIONS.session_from_sessid(1)
|
||||
|
|
@ -79,17 +79,17 @@ class CommandTest(EvenniaTest):
|
|||
pass
|
||||
finally:
|
||||
# clean out evtable sugar. We only operate on text-type
|
||||
stored_msg = [args[0] if args and args[0] else kwargs.get("text",utils.to_str(kwargs, force_string=True))
|
||||
for name, args, kwargs in receiver.msg.mock_calls]
|
||||
stored_msg = [args[0] if args and args[0] else kwargs.get("text", utils.to_str(kwargs, force_string=True))
|
||||
for name, args, kwargs in receiver.msg.mock_calls]
|
||||
# Get the first element of a tuple if msg received a tuple instead of a string
|
||||
stored_msg = [smsg[0] if isinstance(smsg, tuple) else smsg for smsg in stored_msg]
|
||||
if msg is not None:
|
||||
returned_msg = "||".join(_RE.sub("", mess) for mess in stored_msg)
|
||||
returned_msg = ansi.parse_ansi(returned_msg, strip_ansi=noansi).strip()
|
||||
if msg == "" and returned_msg or not returned_msg.startswith(msg.strip()):
|
||||
sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n"
|
||||
sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n"
|
||||
sep3 = "\n" + "="*78
|
||||
sep1 = "\n" + "=" * 30 + "Wanted message" + "=" * 34 + "\n"
|
||||
sep2 = "\n" + "=" * 30 + "Returned message" + "=" * 32 + "\n"
|
||||
sep3 = "\n" + "=" * 78
|
||||
retval = sep1 + msg.strip() + sep2 + returned_msg + sep3
|
||||
raise AssertionError(retval)
|
||||
else:
|
||||
|
|
@ -271,7 +271,7 @@ class TestBuilding(CommandTest):
|
|||
|
||||
def test_typeclass(self):
|
||||
self.call(building.CmdTypeclass(), "Obj = evennia.objects.objects.DefaultExit",
|
||||
"Obj changed typeclass from evennia.objects.objects.DefaultObject to evennia.objects.objects.DefaultExit.")
|
||||
"Obj changed typeclass from evennia.objects.objects.DefaultObject to evennia.objects.objects.DefaultExit.")
|
||||
|
||||
def test_lock(self):
|
||||
self.call(building.CmdLock(), "Obj = test:perm(Developer)", "Added lock 'test:perm(Developer)' to Obj.")
|
||||
|
|
@ -294,10 +294,10 @@ class TestComms(CommandTest):
|
|||
|
||||
def test_toggle_com(self):
|
||||
self.call(comms.CmdAddCom(), "tc = testchan", "You are already connected to channel testchan. You can now", receiver=self.account)
|
||||
self.call(comms.CmdDelCom(), "tc", "Your alias 'tc' for channel testchan was cleared.", receiver=self.account)
|
||||
self.call(comms.CmdDelCom(), "tc", "Your alias 'tc' for channel testchan was cleared.", receiver=self.account)
|
||||
|
||||
def test_channels(self):
|
||||
self.call(comms.CmdChannels(), "" ,"Available channels (use comlist,addcom and delcom to manage", receiver=self.account)
|
||||
self.call(comms.CmdChannels(), "", "Available channels (use comlist,addcom and delcom to manage", receiver=self.account)
|
||||
|
||||
def test_all_com(self):
|
||||
self.call(comms.CmdAllCom(), "", "Available channels (use comlist,addcom and delcom to manage", receiver=self.account)
|
||||
|
|
@ -322,7 +322,7 @@ class TestComms(CommandTest):
|
|||
self.call(comms.CmdCBoot(), "", "Usage: @cboot[/quiet] <channel> = <account> [:reason]", receiver=self.account)
|
||||
|
||||
def test_cdestroy(self):
|
||||
self.call(comms.CmdCdestroy(), "testchan" ,"[testchan] TestAccount: testchan is being destroyed. Make sure to change your aliases.|Channel 'testchan' was destroyed.", receiver=self.account)
|
||||
self.call(comms.CmdCdestroy(), "testchan", "[testchan] TestAccount: testchan is being destroyed. Make sure to change your aliases.|Channel 'testchan' was destroyed.", receiver=self.account)
|
||||
|
||||
|
||||
class TestBatchProcess(CommandTest):
|
||||
|
|
@ -332,6 +332,7 @@ class TestBatchProcess(CommandTest):
|
|||
# we make sure to delete the button again here to stop the running reactor
|
||||
self.call(building.CmdDestroy(), "button", "button was destroyed.")
|
||||
|
||||
|
||||
class CmdInterrupt(Command):
|
||||
|
||||
key = "interrupt"
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ def create_normal_account(session, name, password):
|
|||
account (Account): the account which was created from the name and password.
|
||||
"""
|
||||
# check for too many login errors too quick.
|
||||
if _throttle(session, maxlim=5, timeout=5*60):
|
||||
if _throttle(session, maxlim=5, timeout=5 * 60):
|
||||
# timeout is 5 minutes.
|
||||
session.msg("|RYou made too many connection attempts. Try again in a few minutes.|n")
|
||||
return None
|
||||
|
|
@ -168,8 +168,8 @@ def create_normal_account(session, name, password):
|
|||
|
||||
# Check IP and/or name bans
|
||||
bans = ServerConfig.objects.conf("server_bans")
|
||||
if bans and (any(tup[0] == account.name.lower() for tup in bans)
|
||||
or
|
||||
if bans and (any(tup[0] == account.name.lower() for tup in bans) or
|
||||
|
||||
any(tup[2].match(session.address) for tup in bans if tup[2])):
|
||||
# this is a banned IP or name!
|
||||
string = "|rYou have been banned and cannot continue from here." \
|
||||
|
|
@ -209,7 +209,7 @@ class CmdUnconnectedConnect(COMMAND_DEFAULT_CLASS):
|
|||
session = self.caller
|
||||
|
||||
# check for too many login errors too quick.
|
||||
if _throttle(session, maxlim=5, timeout=5*60, storage=_LATEST_FAILED_LOGINS):
|
||||
if _throttle(session, maxlim=5, timeout=5 * 60, storage=_LATEST_FAILED_LOGINS):
|
||||
# timeout is 5 minutes.
|
||||
session.msg("|RYou made too many connection attempts. Try again in a few minutes.|n")
|
||||
return
|
||||
|
|
@ -301,8 +301,8 @@ class CmdUnconnectedCreate(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
# Check IP and/or name bans
|
||||
bans = ServerConfig.objects.conf("server_bans")
|
||||
if bans and (any(tup[0] == accountname.lower() for tup in bans)
|
||||
or
|
||||
if bans and (any(tup[0] == accountname.lower() for tup in bans) or
|
||||
|
||||
any(tup[2].match(session.address) for tup in bans if tup[2])):
|
||||
# this is a banned IP or name!
|
||||
string = "|rYou have been banned and cannot continue from here." \
|
||||
|
|
|
|||
|
|
@ -12,46 +12,67 @@ from evennia.commands.command import Command
|
|||
|
||||
class _CmdA(Command):
|
||||
key = "A"
|
||||
|
||||
def __init__(self, cmdset, *args, **kwargs):
|
||||
super(_CmdA, self).__init__(*args, **kwargs)
|
||||
self.from_cmdset = cmdset
|
||||
|
||||
|
||||
class _CmdB(Command):
|
||||
key = "B"
|
||||
|
||||
def __init__(self, cmdset, *args, **kwargs):
|
||||
super(_CmdB, self).__init__(*args, **kwargs)
|
||||
self.from_cmdset = cmdset
|
||||
|
||||
|
||||
class _CmdC(Command):
|
||||
key = "C"
|
||||
|
||||
def __init__(self, cmdset, *args, **kwargs):
|
||||
super(_CmdC, self).__init__(*args, **kwargs)
|
||||
self.from_cmdset = cmdset
|
||||
|
||||
|
||||
class _CmdD(Command):
|
||||
key = "D"
|
||||
|
||||
def __init__(self, cmdset, *args, **kwargs):
|
||||
super(_CmdD, self).__init__(*args, **kwargs)
|
||||
self.from_cmdset = cmdset
|
||||
|
||||
|
||||
class _CmdSetA(CmdSet):
|
||||
key = "A"
|
||||
def at_cmdset_creation(self):
|
||||
|
||||
def at_cmdset_creation(self):
|
||||
self.add(_CmdA("A"))
|
||||
self.add(_CmdB("A"))
|
||||
self.add(_CmdC("A"))
|
||||
self.add(_CmdD("A"))
|
||||
|
||||
|
||||
class _CmdSetB(CmdSet):
|
||||
key = "B"
|
||||
def at_cmdset_creation(self):
|
||||
|
||||
def at_cmdset_creation(self):
|
||||
self.add(_CmdA("B"))
|
||||
self.add(_CmdB("B"))
|
||||
self.add(_CmdC("B"))
|
||||
|
||||
|
||||
class _CmdSetC(CmdSet):
|
||||
key = "C"
|
||||
def at_cmdset_creation(self):
|
||||
|
||||
def at_cmdset_creation(self):
|
||||
self.add(_CmdA("C"))
|
||||
self.add(_CmdB("C"))
|
||||
|
||||
|
||||
class _CmdSetD(CmdSet):
|
||||
key = "D"
|
||||
def at_cmdset_creation(self):
|
||||
|
||||
def at_cmdset_creation(self):
|
||||
self.add(_CmdA("D"))
|
||||
self.add(_CmdB("D"))
|
||||
self.add(_CmdC("D"))
|
||||
|
|
@ -59,8 +80,10 @@ class _CmdSetD(CmdSet):
|
|||
|
||||
# testing Command Sets
|
||||
|
||||
|
||||
class TestCmdSetMergers(TestCase):
|
||||
"Test merging of cmdsets"
|
||||
|
||||
def setUp(self):
|
||||
super(TestCmdSetMergers, self).setUp()
|
||||
self.cmdset_a = _CmdSetA()
|
||||
|
|
@ -70,16 +93,16 @@ class TestCmdSetMergers(TestCase):
|
|||
|
||||
def test_union(self):
|
||||
a, c = self.cmdset_a, self.cmdset_c
|
||||
cmdset_f = a + c # same-prio
|
||||
cmdset_f = a + c # same-prio
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 2)
|
||||
cmdset_f = c + a # same-prio, inverse order
|
||||
cmdset_f = c + a # same-prio, inverse order
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
a.priority = 1
|
||||
cmdset_f = a + c # high prio A
|
||||
cmdset_f = a + c # high prio A
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
|
|
@ -87,16 +110,16 @@ class TestCmdSetMergers(TestCase):
|
|||
def test_intersect(self):
|
||||
a, c = self.cmdset_a, self.cmdset_c
|
||||
a.mergetype = "Intersect"
|
||||
cmdset_f = a + c # same-prio - c's Union kicks in
|
||||
cmdset_f = a + c # same-prio - c's Union kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 2)
|
||||
cmdset_f = c + a # same-prio - a's Intersect kicks in
|
||||
cmdset_f = c + a # same-prio - a's Intersect kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
a.priority = 1
|
||||
cmdset_f = a + c # high prio A, intersect kicks in
|
||||
cmdset_f = a + c # high prio A, intersect kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
|
|
@ -104,16 +127,16 @@ class TestCmdSetMergers(TestCase):
|
|||
def test_replace(self):
|
||||
a, c = self.cmdset_a, self.cmdset_c
|
||||
c.mergetype = "Replace"
|
||||
cmdset_f = a + c # same-prio. C's Replace kicks in
|
||||
cmdset_f = a + c # same-prio. C's Replace kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 0)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 2)
|
||||
cmdset_f = c + a # same-prio. A's Union kicks in
|
||||
cmdset_f = c + a # same-prio. A's Union kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
c.priority = 1
|
||||
cmdset_f = c + a # c higher prio. C's Replace kicks in
|
||||
cmdset_f = c + a # c higher prio. C's Replace kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 0)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 2)
|
||||
|
|
@ -121,16 +144,16 @@ class TestCmdSetMergers(TestCase):
|
|||
def test_remove(self):
|
||||
a, c = self.cmdset_a, self.cmdset_c
|
||||
c.mergetype = "Remove"
|
||||
cmdset_f = a + c # same-prio. C's Remove kicks in
|
||||
cmdset_f = a + c # same-prio. C's Remove kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
cmdset_f = c + a # same-prio. A's Union kicks in
|
||||
cmdset_f = c + a # same-prio. A's Union kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 4)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
c.priority = 1
|
||||
cmdset_f = c + a # c higher prio. C's Remove kicks in
|
||||
cmdset_f = c + a # c higher prio. C's Remove kicks in
|
||||
self.assertEqual(len(cmdset_f.commands), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "A"), 2)
|
||||
self.assertEqual(sum(1 for cmd in cmdset_f.commands if cmd.from_cmdset == "C"), 0)
|
||||
|
|
@ -138,15 +161,15 @@ class TestCmdSetMergers(TestCase):
|
|||
def test_order(self):
|
||||
"Merge in reverse- and forward orders, same priorities"
|
||||
a, b, c, d = self.cmdset_a, self.cmdset_b, self.cmdset_c, self.cmdset_d
|
||||
cmdset_f = d + c + b + a # merge in reverse order of priority
|
||||
cmdset_f = d + c + b + a # merge in reverse order of priority
|
||||
self.assertEqual(cmdset_f.priority, 0)
|
||||
self.assertEqual(cmdset_f.mergetype, "Union")
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertTrue(all(True for cmd in cmdset_f.commands if cmd.from_cmdset == "A"))
|
||||
cmdset_f = a + b + c + d # merge in order of priority
|
||||
cmdset_f = a + b + c + d # merge in order of priority
|
||||
self.assertEqual(cmdset_f.priority, 0)
|
||||
self.assertEqual(cmdset_f.mergetype, "Union")
|
||||
self.assertEqual(len(cmdset_f.commands), 4) # duplicates setting from A transfers
|
||||
self.assertEqual(len(cmdset_f.commands), 4) # duplicates setting from A transfers
|
||||
self.assertTrue(all(True for cmd in cmdset_f.commands if cmd.from_cmdset == "D"))
|
||||
|
||||
def test_priority_order(self):
|
||||
|
|
@ -156,12 +179,12 @@ class TestCmdSetMergers(TestCase):
|
|||
b.priority = 1
|
||||
c.priority = 0
|
||||
d.priority = -1
|
||||
cmdset_f = d + c + b + a # merge in reverse order of priority
|
||||
cmdset_f = d + c + b + a # merge in reverse order of priority
|
||||
self.assertEqual(cmdset_f.priority, 2)
|
||||
self.assertEqual(cmdset_f.mergetype, "Union")
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
self.assertTrue(all(True for cmd in cmdset_f.commands if cmd.from_cmdset == "A"))
|
||||
cmdset_f = a + b + c + d # merge in order of priority
|
||||
cmdset_f = a + b + c + d # merge in order of priority
|
||||
self.assertEqual(cmdset_f.priority, 2)
|
||||
self.assertEqual(cmdset_f.mergetype, "Union")
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
|
|
@ -176,13 +199,13 @@ class TestCmdSetMergers(TestCase):
|
|||
a.no_objs = True
|
||||
a.no_channels = True
|
||||
a.duplicates = True
|
||||
cmdset_f = d + c + b + a # reverse, same-prio
|
||||
cmdset_f = d + c + b + a # reverse, same-prio
|
||||
self.assertTrue(cmdset_f.no_exits)
|
||||
self.assertTrue(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
self.assertTrue(cmdset_f.duplicates)
|
||||
self.assertEqual(len(cmdset_f.commands), 8)
|
||||
cmdset_f = a + b + c + d # forward, same-prio
|
||||
cmdset_f = a + b + c + d # forward, same-prio
|
||||
self.assertTrue(cmdset_f.no_exits)
|
||||
self.assertTrue(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
|
|
@ -192,13 +215,13 @@ class TestCmdSetMergers(TestCase):
|
|||
b.priority = 1
|
||||
c.priority = 0
|
||||
d.priority = -1
|
||||
cmdset_f = d + c + b + a # reverse, A top priority
|
||||
cmdset_f = d + c + b + a # reverse, A top priority
|
||||
self.assertTrue(cmdset_f.no_exits)
|
||||
self.assertTrue(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
self.assertTrue(cmdset_f.duplicates)
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
cmdset_f = a + b + c + d # forward, A top priority. This never happens in practice.
|
||||
cmdset_f = a + b + c + d # forward, A top priority. This never happens in practice.
|
||||
self.assertTrue(cmdset_f.no_exits)
|
||||
self.assertTrue(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
|
|
@ -208,13 +231,13 @@ class TestCmdSetMergers(TestCase):
|
|||
b.priority = 0
|
||||
c.priority = 1
|
||||
d.priority = 2
|
||||
cmdset_f = d + c + b + a # reverse, A low prio. This never happens in practice.
|
||||
cmdset_f = d + c + b + a # reverse, A low prio. This never happens in practice.
|
||||
self.assertTrue(cmdset_f.no_exits)
|
||||
self.assertTrue(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
self.assertFalse(cmdset_f.duplicates)
|
||||
self.assertEqual(len(cmdset_f.commands), 4)
|
||||
cmdset_f = a + b + c + d # forward, A low prio
|
||||
cmdset_f = a + b + c + d # forward, A low prio
|
||||
self.assertTrue(cmdset_f.no_exits)
|
||||
self.assertTrue(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
|
|
@ -224,7 +247,7 @@ class TestCmdSetMergers(TestCase):
|
|||
b.no_objs = False
|
||||
d.duplicates = False
|
||||
# higher-prio sets will change the option up the chain
|
||||
cmdset_f = a + b + c + d # forward, A low prio
|
||||
cmdset_f = a + b + c + d # forward, A low prio
|
||||
self.assertFalse(cmdset_f.no_exits)
|
||||
self.assertFalse(cmdset_f.no_objs)
|
||||
self.assertTrue(cmdset_f.no_channels)
|
||||
|
|
@ -235,15 +258,19 @@ class TestCmdSetMergers(TestCase):
|
|||
c.priority = 0
|
||||
d.priority = 0
|
||||
c.duplicates = True
|
||||
cmdset_f = d + b + c + a # two last mergers duplicates=True
|
||||
cmdset_f = d + b + c + a # two last mergers duplicates=True
|
||||
self.assertEqual(len(cmdset_f.commands), 10)
|
||||
|
||||
# test cmdhandler functions
|
||||
|
||||
|
||||
from evennia.commands import cmdhandler
|
||||
from twisted.trial.unittest import TestCase as TwistedTestCase
|
||||
|
||||
|
||||
class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
||||
"Test the cmdhandler.get_and_merge_cmdsets function."
|
||||
|
||||
def setUp(self):
|
||||
super(TestGetAndMergeCmdSets, self).setUp()
|
||||
self.cmdset_a = _CmdSetA()
|
||||
|
|
@ -261,6 +288,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
|||
a.no_channels = True
|
||||
self.set_cmdsets(self.session, a)
|
||||
deferred = cmdhandler.get_and_merge_cmdsets(self.session, self.session, None, None, "session", "")
|
||||
|
||||
def _callback(cmdset):
|
||||
self.assertEqual(cmdset.key, "A")
|
||||
deferred.addCallback(_callback)
|
||||
|
|
@ -273,6 +301,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
|||
self.set_cmdsets(self.account, a)
|
||||
deferred = cmdhandler.get_and_merge_cmdsets(self.account, None, self.account, None, "account", "")
|
||||
# get_and_merge_cmdsets converts to lower-case internally.
|
||||
|
||||
def _callback(cmdset):
|
||||
pcmdset = AccountCmdSet()
|
||||
pcmdset.at_cmdset_creation()
|
||||
|
|
@ -286,7 +315,8 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
|||
self.set_cmdsets(self.obj1, self.cmdset_a)
|
||||
deferred = cmdhandler.get_and_merge_cmdsets(self.obj1, None, None, self.obj1, "object", "")
|
||||
# get_and_merge_cmdsets converts to lower-case internally.
|
||||
_callback = lambda cmdset: self.assertEqual(sum(1 for cmd in cmdset.commands if cmd.key in ("a", "b", "c", "d")), 4)
|
||||
|
||||
def _callback(cmdset): return self.assertEqual(sum(1 for cmd in cmdset.commands if cmd.key in ("a", "b", "c", "d")), 4)
|
||||
deferred.addCallback(_callback)
|
||||
return deferred
|
||||
|
||||
|
|
@ -296,6 +326,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
|||
a.no_channels = True
|
||||
self.set_cmdsets(self.obj1, a, b, c, d)
|
||||
deferred = cmdhandler.get_and_merge_cmdsets(self.obj1, None, None, self.obj1, "object", "")
|
||||
|
||||
def _callback(cmdset):
|
||||
self.assertTrue(cmdset.no_exits)
|
||||
self.assertTrue(cmdset.no_channels)
|
||||
|
|
@ -315,6 +346,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
|||
a, b, c, d = self.cmdset_a, self.cmdset_b, self.cmdset_c, self.cmdset_d
|
||||
self.set_cmdsets(self.account, a, b, c, d)
|
||||
deferred = cmdhandler.get_and_merge_cmdsets(self.session, self.session, self.account, self.char1, "session", "")
|
||||
|
||||
def _callback(cmdset):
|
||||
pcmdset = AccountCmdSet()
|
||||
pcmdset.at_cmdset_creation()
|
||||
|
|
@ -332,6 +364,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, EvenniaTest):
|
|||
d.duplicates = True
|
||||
self.set_cmdsets(self.obj1, a, b, c, d)
|
||||
deferred = cmdhandler.get_and_merge_cmdsets(self.obj1, None, None, self.obj1, "object", "")
|
||||
|
||||
def _callback(cmdset):
|
||||
self.assertEqual(len(cmdset.commands), 9)
|
||||
deferred.addCallback(_callback)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue