Converted all docstrings in the commands submodule (not the default commands themselves) to Google style as per #709.
This commit is contained in:
parent
ae88d67548
commit
e84db3df54
3 changed files with 402 additions and 184 deletions
|
|
@ -150,9 +150,12 @@ class Command(object):
|
|||
# sessid - which session-id (if any) is responsible for triggering this command
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""the lockhandler works the same as for objects.
|
||||
"""
|
||||
The lockhandler works the same as for objects.
|
||||
optional kwargs will be set as properties on the Command at runtime,
|
||||
overloading evential same-named class properties."""
|
||||
overloading evential same-named class properties.
|
||||
|
||||
"""
|
||||
if kwargs:
|
||||
_init_command(self, **kwargs)
|
||||
|
||||
|
|
@ -161,14 +164,23 @@ class Command(object):
|
|||
return LockHandler(self)
|
||||
|
||||
def __str__(self):
|
||||
"Print the command"
|
||||
"""
|
||||
Print the command key
|
||||
"""
|
||||
return self.key
|
||||
|
||||
def __eq__(self, cmd):
|
||||
"""
|
||||
Compare two command instances to each other by matching their
|
||||
key and aliases.
|
||||
input can be either a cmd object or the name of a command.
|
||||
|
||||
Args:
|
||||
cmd (Command or str): Allows for equating both Command
|
||||
objects and their keys.
|
||||
|
||||
Returns:
|
||||
equal (bool): If the commands are equal or not.
|
||||
|
||||
"""
|
||||
try:
|
||||
# first assume input is a command (the most common case)
|
||||
|
|
@ -179,9 +191,10 @@ class Command(object):
|
|||
|
||||
def __ne__(self, cmd):
|
||||
"""
|
||||
The logical negation of __eq__. Since this is one of the
|
||||
most called methods in Evennia (along with __eq__) we do some
|
||||
code-duplication here rather than issuing a method-lookup to __eq__.
|
||||
The logical negation of __eq__. Since this is one of the most
|
||||
called methods in Evennia (along with __eq__) we do some
|
||||
code-duplication here rather than issuing a method-lookup to
|
||||
__eq__.
|
||||
"""
|
||||
try:
|
||||
return not cmd.key in self._matcheset
|
||||
|
|
@ -190,11 +203,15 @@ class Command(object):
|
|||
|
||||
def __contains__(self, query):
|
||||
"""
|
||||
This implements searches like 'if query in cmd'. It's a fuzzy matching
|
||||
used by the help system, returning True if query can be found
|
||||
as a substring of the commands key or its aliases.
|
||||
This implements searches like 'if query in cmd'. It's a fuzzy
|
||||
matching used by the help system, returning True if query can
|
||||
be found as a substring of the commands key or its aliases.
|
||||
|
||||
query (str) - query to match against. Should be lower case.
|
||||
Args:
|
||||
query (str): query to match against. Should be lower case.
|
||||
|
||||
Returns:
|
||||
result (bool): Fuzzy matching result.
|
||||
|
||||
"""
|
||||
return any(query in keyalias for keyalias in self._keyaliases)
|
||||
|
|
@ -205,7 +222,11 @@ class Command(object):
|
|||
in order to determine if this is the one we wanted. cmdname was
|
||||
previously extracted from the raw string by the system.
|
||||
|
||||
cmdname (str) is always lowercase when reaching this point.
|
||||
Args:
|
||||
cmdname (str): Always lowercase when reaching this point.
|
||||
|
||||
Returns:
|
||||
result (bool): Match result.
|
||||
|
||||
"""
|
||||
return cmdname in self._matchset
|
||||
|
|
@ -216,25 +237,38 @@ class Command(object):
|
|||
is allowed to execute this command. It should return a boolean
|
||||
value and is not normally something that need to be changed since
|
||||
it's using the Evennia permission system directly.
|
||||
|
||||
Args:
|
||||
srcobj (Object): Object trying to gain permission
|
||||
access_type (str, optional): The lock type to check.
|
||||
default (bool, optional): The fallbacl result if no lock
|
||||
of matching `access_type` is found on this Command.
|
||||
|
||||
"""
|
||||
return self.lockhandler.check(srcobj, access_type, default=default)
|
||||
|
||||
def msg(self, msg="", to_obj=None, from_obj=None,
|
||||
sessid=None, all_sessions=False, **kwargs):
|
||||
"""
|
||||
This is a shortcut instad of calling msg() directly on an object - it
|
||||
will detect if caller is an Object or a Player and also appends
|
||||
self.sessid automatically.
|
||||
This is a shortcut instad of calling msg() directly on an
|
||||
object - it will detect if caller is an Object or a Player and
|
||||
also appends self.sessid automatically.
|
||||
|
||||
Args:
|
||||
msg (str, optional): Text string of message to send.
|
||||
to_obj (Object, optional): Target object of message. Defaults to self.caller.
|
||||
from_obj (Object, optional): Source of message. Defaults to to_obj.
|
||||
sessid (int, optional): Supply data only to a unique
|
||||
session id (normally not used - this is only potentially
|
||||
useful if to_obj is a Player object different from
|
||||
self.caller or self.caller.player).
|
||||
all_sessions (bool): Default is to send only to the session
|
||||
connected to the target object
|
||||
|
||||
Kwargs:
|
||||
kwargs (any): These are all passed on to the message mechanism. Common
|
||||
keywords are `oob` and `raw`.
|
||||
|
||||
msg - text string of message to send
|
||||
to_obj - target object of message. Defaults to self.caller
|
||||
from_obj - source of message. Defaults to to_obj
|
||||
data - optional dictionary of data
|
||||
sessid - supply data only to a unique sessid (normally not used -
|
||||
this is only potentially useful if to_obj is a Player object
|
||||
different from self.caller or self.caller.player)
|
||||
all_sessions (bool) - default is to send only to the session
|
||||
connected to the target object
|
||||
"""
|
||||
from_obj = from_obj or self.caller
|
||||
to_obj = to_obj or from_obj
|
||||
|
|
@ -263,9 +297,10 @@ class Command(object):
|
|||
|
||||
def at_pre_cmd(self):
|
||||
"""
|
||||
This hook is called before self.parse() on all commands.
|
||||
If this hook returns anything but False/None, the command
|
||||
This hook is called before self.parse() on all commands. If
|
||||
this hook returns anything but False/None, the command
|
||||
sequence is aborted.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
|
@ -273,27 +308,30 @@ class Command(object):
|
|||
"""
|
||||
This hook is called after the command has finished executing
|
||||
(after self.func()).
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
Once the cmdhandler has identified this as the command we
|
||||
want, this function is run. If many of your commands have
|
||||
a similar syntax (for example 'cmd arg1 = arg2') you should simply
|
||||
define this once and just let other commands of the same form
|
||||
inherit from this. See the docstring of this module for
|
||||
which object properties are available to use
|
||||
(notably self.args).
|
||||
want, this function is run. If many of your commands have a
|
||||
similar syntax (for example 'cmd arg1 = arg2') you should
|
||||
simply define this once and just let other commands of the
|
||||
same form inherit from this. See the docstring of this module
|
||||
for which object properties are available to use (notably
|
||||
self.args).
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
def func(self):
|
||||
"""
|
||||
This is the actual executing part of the command.
|
||||
It is called directly after self.parse(). See the docstring
|
||||
of this module for which object properties are available
|
||||
(beyond those set in self.parse())
|
||||
This is the actual executing part of the command. It is
|
||||
called directly after self.parse(). See the docstring of this
|
||||
module for which object properties are available (beyond those
|
||||
set in self.parse())
|
||||
|
||||
"""
|
||||
# a simple test command to show the available properties
|
||||
string = "-" * 50
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue