Ran black on sources

This commit is contained in:
Griatch 2020-10-21 21:11:04 +02:00
parent 7939e3cde3
commit 8b28900600
16 changed files with 115 additions and 77 deletions

View file

@ -358,14 +358,18 @@ class CmdSet(object, metaclass=_CmdSetMeta):
""" """
perm = "perm" if self.permanent else "non-perm" perm = "perm" if self.permanent else "non-perm"
options = ", ".join([ options = ", ".join(
"{}:{}".format(opt, "T" if getattr(self, opt) else "F") [
for opt in ("no_exits", "no_objs", "no_channels", "duplicates") "{}:{}".format(opt, "T" if getattr(self, opt) else "F")
if getattr(self, opt) is not None for opt in ("no_exits", "no_objs", "no_channels", "duplicates")
]) if getattr(self, opt) is not None
]
)
options = (", " + options) if options else "" options = (", " + options) if options else ""
return f"<CmdSet {self.key}, {self.mergetype}, {perm}, prio {self.priority}{options}>: " + ", ".join( return (
[str(cmd) for cmd in sorted(self.commands, key=lambda o: o.key)]) f"<CmdSet {self.key}, {self.mergetype}, {perm}, prio {self.priority}{options}>: "
+ ", ".join([str(cmd) for cmd in sorted(self.commands, key=lambda o: o.key)])
)
def __iter__(self): def __iter__(self):
""" """

View file

@ -331,7 +331,7 @@ class CmdSetHandler(object):
if mergelist: if mergelist:
# current is a result of mergers # current is a result of mergers
mergelist="+".join(mergelist) mergelist = "+".join(mergelist)
strings.append(f" <Merged {mergelist}>: {self.current}") strings.append(f" <Merged {mergelist}>: {self.current}")
else: else:
# current is a single cmdset # current is a single cmdset

View file

@ -2516,12 +2516,14 @@ class CmdExamine(ObjManipCommand):
def _format_options(cmdset): def _format_options(cmdset):
"""helper for cmdset-option display""" """helper for cmdset-option display"""
def _truefalse(string, value): def _truefalse(string, value):
if value is None: if value is None:
return "" return ""
if value: if value:
return f"{string}: T" return f"{string}: T"
return f"{string}: F" return f"{string}: F"
options = ", ".join( options = ", ".join(
_truefalse(opt, getattr(cmdset, opt)) _truefalse(opt, getattr(cmdset, opt))
for opt in ("no_exits", "no_objs", "no_channels", "duplicates") for opt in ("no_exits", "no_objs", "no_channels", "duplicates")
@ -2538,7 +2540,8 @@ class CmdExamine(ObjManipCommand):
continue continue
options = _format_options(cmdset) options = _format_options(cmdset)
stored.append( stored.append(
f"{cmdset.path} [{cmdset.key}] ({cmdset.mergetype}, prio {cmdset.priority}{options})") f"{cmdset.path} [{cmdset.key}] ({cmdset.mergetype}, prio {cmdset.priority}{options})"
)
output["Stored Cmdset(s)"] = "\n " + "\n ".join(stored) output["Stored Cmdset(s)"] = "\n " + "\n ".join(stored)
# this gets all components of the currently merged set # this gets all components of the currently merged set
@ -2576,13 +2579,15 @@ class CmdExamine(ObjManipCommand):
# the resulting merged cmdset # the resulting merged cmdset
options = _format_options(current_cmdset) options = _format_options(current_cmdset)
merged = [ merged = [
f"<Current merged cmdset> ({current_cmdset.mergetype} prio {current_cmdset.priority}{options})"] f"<Current merged cmdset> ({current_cmdset.mergetype} prio {current_cmdset.priority}{options})"
]
# the merge stack # the merge stack
for cmdset in all_cmdsets: for cmdset in all_cmdsets:
options = _format_options(cmdset) options = _format_options(cmdset)
merged.append( merged.append(
f"{cmdset.path} [{cmdset.key}] ({cmdset.mergetype} prio {cmdset.priority}{options})") f"{cmdset.path} [{cmdset.key}] ({cmdset.mergetype} prio {cmdset.priority}{options})"
)
output["Merged Cmdset(s)"] = "\n " + "\n ".join(merged) output["Merged Cmdset(s)"] = "\n " + "\n ".join(merged)
# list the commands available to this object # list the commands available to this object

View file

@ -833,7 +833,7 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
receiver = f"|n,{clr}".join([obj.name for obj in page.receivers]) receiver = f"|n,{clr}".join([obj.name for obj in page.receivers])
if sending: if sending:
template = to_template template = to_template
sender = f"{sender} " if multi_send else "" sender = f"{sender} " if multi_send else ""
receiver = f" {receiver}" if multi_recv else f" {receiver}" receiver = f" {receiver}" if multi_recv else f" {receiver}"
else: else:
template = from_template template = from_template
@ -848,7 +848,6 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
receiver=receiver, receiver=receiver,
message=page.message, message=page.message,
) )
) )
lastpages = "\n ".join(listing) lastpages = "\n ".join(listing)

View file

@ -379,10 +379,13 @@ class CmdInventory(COMMAND_DEFAULT_CLASS):
string = "You are not carrying anything." string = "You are not carrying anything."
else: else:
from evennia.utils.ansi import raw as raw_ansi from evennia.utils.ansi import raw as raw_ansi
table = self.styled_table(border="header") table = self.styled_table(border="header")
for item in items: for item in items:
table.add_row(f"|C{item.name}|n", table.add_row(
"{}|n".format(utils.crop(raw_ansi(item.db.desc), width=50) or "")) f"|C{item.name}|n",
"{}|n".format(utils.crop(raw_ansi(item.db.desc), width=50) or ""),
)
string = f"|wYou are carrying:\n{table}" string = f"|wYou are carrying:\n{table}"
self.caller.msg(string) self.caller.msg(string)

View file

@ -222,8 +222,11 @@ class CmdHelp(Command):
# system, but not be displayed in the table, or be displayed differently. # system, but not be displayed in the table, or be displayed differently.
for cmd in all_cmds: for cmd in all_cmds:
if self.should_list_cmd(cmd, caller): if self.should_list_cmd(cmd, caller):
key = (cmd.auto_help_display_key key = (
if hasattr(cmd, "auto_help_display_key") else cmd.key) cmd.auto_help_display_key
if hasattr(cmd, "auto_help_display_key")
else cmd.key
)
hdict_cmd[cmd.help_category].append(key) hdict_cmd[cmd.help_category].append(key)
[hdict_topic[topic.help_category].append(topic.key) for topic in all_topics] [hdict_topic[topic.help_category].append(topic.key) for topic in all_topics]
# report back # report back
@ -271,10 +274,7 @@ class CmdHelp(Command):
cmd = match[0] cmd = match[0]
key = cmd.auto_help_display_key if hasattr(cmd, "auto_help_display_key") else cmd.key key = cmd.auto_help_display_key if hasattr(cmd, "auto_help_display_key") else cmd.key
formatted = self.format_help_entry( formatted = self.format_help_entry(
key, key, cmd.get_help(caller, cmdset), aliases=cmd.aliases, suggested=suggestions,
cmd.get_help(caller, cmdset),
aliases=cmd.aliases,
suggested=suggestions,
) )
self.msg_help(formatted) self.msg_help(formatted)
return return
@ -294,10 +294,16 @@ class CmdHelp(Command):
# try to see if a category name was entered # try to see if a category name was entered
if query in all_categories: if query in all_categories:
self.msg_help( self.msg_help(
self.format_help_list({ self.format_help_list(
query: [ {
cmd.auto_help_display_key if hasattr(cmd, "auto_help_display_key") else cmd.key query: [
for cmd in all_cmds if cmd.help_category == query]}, cmd.auto_help_display_key
if hasattr(cmd, "auto_help_display_key")
else cmd.key
for cmd in all_cmds
if cmd.help_category == query
]
},
{query: [topic.key for topic in all_topics if topic.help_category == query]}, {query: [topic.key for topic in all_topics if topic.help_category == query]},
) )
) )

View file

@ -971,8 +971,11 @@ class TestBuilding(CommandTest):
self.call(building.CmdSetHome(), "Obj = Room2", "Home location of Obj was set to Room") self.call(building.CmdSetHome(), "Obj = Room2", "Home location of Obj was set to Room")
def test_list_cmdsets(self): def test_list_cmdsets(self):
self.call(building.CmdListCmdSets(), "", self.call(
"<CmdSetHandler> stack:\n <CmdSet DefaultCharacter, Union, perm, prio 0>:") building.CmdListCmdSets(),
"",
"<CmdSetHandler> stack:\n <CmdSet DefaultCharacter, Union, perm, prio 0>:",
)
self.call(building.CmdListCmdSets(), "NotFound", "Could not find 'NotFound'") self.call(building.CmdListCmdSets(), "NotFound", "Could not find 'NotFound'")
def test_typeclass(self): def test_typeclass(self):

View file

@ -339,7 +339,7 @@ class TestOptionTransferTrue(TestCase):
b.no_objs = False b.no_objs = False
d.duplicates = False d.duplicates = False
# higher-prio sets will change the option up the chain # higher-prio sets will change the option up the chain
cmdset_f = d + c + b + a # reverse, high prio cmdset_f = d + c + b + a # reverse, high prio
self.assertTrue(cmdset_f.no_exits) self.assertTrue(cmdset_f.no_exits)
self.assertTrue(cmdset_f.no_objs) self.assertTrue(cmdset_f.no_objs)
self.assertTrue(cmdset_f.no_channels) self.assertTrue(cmdset_f.no_channels)
@ -407,7 +407,7 @@ class TestOptionTransferTrue(TestCase):
c.priority = 1 c.priority = 1
d.priority = 2 d.priority = 2
c.no_exits = False c.no_exits = False
c.no_channels = None # passthrough c.no_channels = None # passthrough
b.no_objs = False b.no_objs = False
d.duplicates = False d.duplicates = False
# higher-prio sets will change the option up the chain # higher-prio sets will change the option up the chain
@ -639,7 +639,7 @@ class TestOptionTransferFalse(TestCase):
b.no_objs = True b.no_objs = True
d.duplicates = True d.duplicates = True
# higher-prio sets will change the option up the chain # higher-prio sets will change the option up the chain
cmdset_f = d + c + b + a # reverse, high prio cmdset_f = d + c + b + a # reverse, high prio
self.assertFalse(cmdset_f.no_exits) self.assertFalse(cmdset_f.no_exits)
self.assertFalse(cmdset_f.no_objs) self.assertFalse(cmdset_f.no_objs)
self.assertFalse(cmdset_f.no_channels) self.assertFalse(cmdset_f.no_channels)
@ -663,7 +663,7 @@ class TestOptionTransferFalse(TestCase):
b.no_objs = True b.no_objs = True
d.duplicates = True d.duplicates = True
# higher-prio sets will change the option up the chain # higher-prio sets will change the option up the chain
cmdset_f = a + b + c + d # forward, high prio, never happens cmdset_f = a + b + c + d # forward, high prio, never happens
self.assertFalse(cmdset_f.no_exits) self.assertFalse(cmdset_f.no_exits)
self.assertFalse(cmdset_f.no_objs) self.assertFalse(cmdset_f.no_objs)
self.assertFalse(cmdset_f.no_channels) self.assertFalse(cmdset_f.no_channels)
@ -707,7 +707,7 @@ class TestOptionTransferFalse(TestCase):
c.priority = 1 c.priority = 1
d.priority = 2 d.priority = 2
c.no_exits = True c.no_exits = True
c.no_channels = None # passthrough c.no_channels = None # passthrough
b.no_objs = True b.no_objs = True
d.duplicates = True d.duplicates = True
# higher-prio sets will change the option up the chain # higher-prio sets will change the option up the chain
@ -908,6 +908,7 @@ class TestOptionTransferReplace(TestCase):
""" """
Test option transfer through more complex merge types. Test option transfer through more complex merge types.
""" """
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.cmdset_a = _CmdSetA() self.cmdset_a = _CmdSetA()

View file

@ -21,7 +21,9 @@ class ObjectCreationTest(EvenniaTest):
class ChannelWholistTests(EvenniaTest): class ChannelWholistTests(EvenniaTest):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.default_channel, _ = DefaultChannel.create("coffeetalk", description="A place to talk about coffee.") self.default_channel, _ = DefaultChannel.create(
"coffeetalk", description="A place to talk about coffee."
)
self.default_channel.connect(self.obj1) self.default_channel.connect(self.obj1)
def test_wholist_shows_subscribed_objects(self): def test_wholist_shows_subscribed_objects(self):
@ -31,7 +33,9 @@ class ChannelWholistTests(EvenniaTest):
def test_wholist_shows_none_when_empty(self): def test_wholist_shows_none_when_empty(self):
# No one hates dogs # No one hates dogs
empty_channel, _ = DefaultChannel.create("doghaters", description="A place where dog haters unite.") empty_channel, _ = DefaultChannel.create(
"doghaters", description="A place where dog haters unite."
)
expected = "<None>" expected = "<None>"
result = empty_channel.wholist result = empty_channel.wholist
self.assertEqual(expected, result) self.assertEqual(expected, result)

View file

@ -1158,7 +1158,8 @@ class WeaponRack(TutorialObject):
|wstab/thrust/pierce <target>|n - poke at the enemy. More damage but harder to hit. |wstab/thrust/pierce <target>|n - poke at the enemy. More damage but harder to hit.
|wslash/chop/bash <target>|n - swipe at the enemy. Less damage but easier to hit. |wslash/chop/bash <target>|n - swipe at the enemy. Less damage but easier to hit.
|wdefend/parry|n - protect yourself and make yourself harder to hit.) |wdefend/parry|n - protect yourself and make yourself harder to hit.)
""").strip() """
).strip()
self.db.no_more_weapons_msg = "you find nothing else of use." self.db.no_more_weapons_msg = "you find nothing else of use."
self.db.available_weapons = ["knife", "dagger", "sword", "club"] self.db.available_weapons = ["knife", "dagger", "sword", "club"]

View file

@ -78,6 +78,7 @@ class CmdTutorial(Command):
helptext += "\n\n (Write 'give up' if you want to abandon your quest.)" helptext += "\n\n (Write 'give up' if you want to abandon your quest.)"
caller.msg(helptext) caller.msg(helptext)
# for the @detail command we inherit from MuxCommand, since # for the @detail command we inherit from MuxCommand, since
# we want to make use of MuxCommand's pre-parsing of '=' in the # we want to make use of MuxCommand's pre-parsing of '=' in the
# argument. # argument.
@ -202,22 +203,26 @@ class CmdTutorialLook(default_cmds.CmdLook):
looking_at_obj.at_desc(looker=caller) looking_at_obj.at_desc(looker=caller)
return return
class CmdTutorialGiveUp(default_cmds.MuxCommand): class CmdTutorialGiveUp(default_cmds.MuxCommand):
""" """
Give up the tutorial-world quest and return to Limbo, the start room of the Give up the tutorial-world quest and return to Limbo, the start room of the
server. server.
""" """
key = "give up" key = "give up"
aliases = ['abort'] aliases = ["abort"]
def func(self): def func(self):
outro_room = OutroRoom.objects.all() outro_room = OutroRoom.objects.all()
if outro_room: if outro_room:
outro_room = outro_room[0] outro_room = outro_room[0]
else: else:
self.caller.msg("That didn't work (seems like a bug). " self.caller.msg(
"Try to use the |wteleport|n command instead.") "That didn't work (seems like a bug). "
"Try to use the |wteleport|n command instead."
)
return return
self.caller.move_to(outro_room) self.caller.move_to(outro_room)
@ -385,6 +390,7 @@ SUPERUSER_WARNING = (
# #
# ------------------------------------------------------------- # -------------------------------------------------------------
class CmdEvenniaIntro(Command): class CmdEvenniaIntro(Command):
""" """
Start the Evennia intro wizard. Start the Evennia intro wizard.
@ -393,10 +399,12 @@ class CmdEvenniaIntro(Command):
intro intro
""" """
key = "intro" key = "intro"
def func(self): def func(self):
from .intro_menu import init_menu from .intro_menu import init_menu
# quell also superusers # quell also superusers
if self.caller.account: if self.caller.account:
self.caller.account.execute_cmd("quell") self.caller.account.execute_cmd("quell")
@ -452,6 +460,7 @@ class IntroRoom(TutorialRoom):
character.account.execute_cmd("quell") character.account.execute_cmd("quell")
character.msg("(Auto-quelling while in tutorial-world)") character.msg("(Auto-quelling while in tutorial-world)")
# ------------------------------------------------------------- # -------------------------------------------------------------
# #
# Bridge - unique room # Bridge - unique room
@ -1165,4 +1174,3 @@ class OutroRoom(TutorialRoom):
def at_object_leave(self, character, destination): def at_object_leave(self, character, destination):
if character.account: if character.account:
character.account.execute_cmd("unquell") character.account.execute_cmd("unquell")

View file

@ -1940,7 +1940,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# whisper mode # whisper mode
msg_type = "whisper" msg_type = "whisper"
msg_self = ( msg_self = (
'{self} whisper to {all_receivers}, "|n{speech}|n"' if msg_self is True else msg_self '{self} whisper to {all_receivers}, "|n{speech}|n"'
if msg_self is True
else msg_self
) )
msg_receivers = msg_receivers or '{object} whispers: "|n{speech}|n"' msg_receivers = msg_receivers or '{object} whispers: "|n{speech}|n"'
msg_location = None msg_location = None

View file

@ -31,8 +31,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
# Attribute manager methods # Attribute manager methods
def get_attribute( def get_attribute(
self, key=None, category=None, value=None, strvalue=None, self, key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None, **kwargs
obj=None, attrtype=None, **kwargs): ):
""" """
Return Attribute objects by key, by category, by value, by Return Attribute objects by key, by category, by value, by
`strvalue`, by object (it is stored on) or with a combination of `strvalue`, by object (it is stored on) or with a combination of

View file

@ -1660,9 +1660,7 @@ def get_input(caller, prompt, callback, session=None, *args, **kwargs):
_RE_NODE = re.compile(r"##\s*?NODE\s+?(?P<nodename>\S[\S\s]*?)$", re.I + re.M) _RE_NODE = re.compile(r"##\s*?NODE\s+?(?P<nodename>\S[\S\s]*?)$", re.I + re.M)
_RE_OPTIONS_SEP = re.compile(r"##\s*?OPTIONS\s*?$", re.I + re.M) _RE_OPTIONS_SEP = re.compile(r"##\s*?OPTIONS\s*?$", re.I + re.M)
_RE_CALLABLE = re.compile(r"\S+?\(\)", re.I + re.M) _RE_CALLABLE = re.compile(r"\S+?\(\)", re.I + re.M)
_RE_CALLABLE = re.compile( _RE_CALLABLE = re.compile(r"(?P<funcname>\S+?)(?:\((?P<kwargs>[\S\s]+?)\)|\(\))", re.I + re.M)
r"(?P<funcname>\S+?)(?:\((?P<kwargs>[\S\s]+?)\)|\(\))", re.I + re.M
)
_HELP_NO_OPTION_MATCH = _("Choose an option or try 'help'.") _HELP_NO_OPTION_MATCH = _("Choose an option or try 'help'.")
@ -1676,8 +1674,8 @@ _OPTION_COMMENT_START = "#"
# Input/option/goto handler functions that allows for dynamically generated # Input/option/goto handler functions that allows for dynamically generated
# nodes read from the menu template. # nodes read from the menu template.
def _process_callable(caller, goto, goto_callables, raw_string,
current_nodename, kwargs): def _process_callable(caller, goto, goto_callables, raw_string, current_nodename, kwargs):
""" """
Central helper for parsing a goto-callable (`funcname(**kwargs)`) out of Central helper for parsing a goto-callable (`funcname(**kwargs)`) out of
the right-hand-side of the template options and map this to an actual the right-hand-side of the template options and map this to an actual
@ -1693,12 +1691,18 @@ def _process_callable(caller, goto, goto_callables, raw_string,
for kwarg in gotokwargs.split(","): for kwarg in gotokwargs.split(","):
if kwarg and "=" in kwarg: if kwarg and "=" in kwarg:
key, value = [part.strip() for part in kwarg.split("=", 1)] key, value = [part.strip() for part in kwarg.split("=", 1)]
if key in ("evmenu_goto", "evmenu_gotomap", "_current_nodename", if key in (
"evmenu_current_nodename", "evmenu_goto_callables"): "evmenu_goto",
"evmenu_gotomap",
"_current_nodename",
"evmenu_current_nodename",
"evmenu_goto_callables",
):
raise RuntimeError( raise RuntimeError(
f"EvMenu template error: goto-callable '{goto}' uses a " f"EvMenu template error: goto-callable '{goto}' uses a "
f"kwarg ({kwarg}) that is reserved for the EvMenu templating " f"kwarg ({kwarg}) that is reserved for the EvMenu templating "
"system. Rename the kwarg.") "system. Rename the kwarg."
)
try: try:
key = literal_eval(key) key = literal_eval(key)
except ValueError: except ValueError:
@ -1725,8 +1729,7 @@ def _generated_goto_func(caller, raw_string, **kwargs):
goto = kwargs["evmenu_goto"] goto = kwargs["evmenu_goto"]
goto_callables = kwargs["evmenu_goto_callables"] goto_callables = kwargs["evmenu_goto_callables"]
current_nodename = kwargs["evmenu_current_nodename"] current_nodename = kwargs["evmenu_current_nodename"]
return _process_callable(caller, goto, goto_callables, raw_string, return _process_callable(caller, goto, goto_callables, raw_string, current_nodename, kwargs)
current_nodename, kwargs)
def _generated_input_goto_func(caller, raw_string, **kwargs): def _generated_input_goto_func(caller, raw_string, **kwargs):
@ -1746,13 +1749,15 @@ def _generated_input_goto_func(caller, raw_string, **kwargs):
# start with glob patterns # start with glob patterns
for pattern, goto in gotomap.items(): for pattern, goto in gotomap.items():
if fnmatch(raw_string.lower(), pattern): if fnmatch(raw_string.lower(), pattern):
return _process_callable(caller, goto, goto_callables, raw_string, return _process_callable(
current_nodename, kwargs) caller, goto, goto_callables, raw_string, current_nodename, kwargs
)
# no glob pattern match; try regex # no glob pattern match; try regex
for pattern, goto in gotomap.items(): for pattern, goto in gotomap.items():
if pattern and re.match(pattern, raw_string.lower(), flags=re.I + re.M): if pattern and re.match(pattern, raw_string.lower(), flags=re.I + re.M):
return _process_callable(caller, goto, goto_callables, raw_string, return _process_callable(
current_nodename, kwargs) caller, goto, goto_callables, raw_string, current_nodename, kwargs
)
# no match, show error # no match, show error
raise EvMenuGotoAbortMessage(_HELP_NO_OPTION_MATCH) raise EvMenuGotoAbortMessage(_HELP_NO_OPTION_MATCH)
@ -1783,6 +1788,7 @@ def parse_menu_template(caller, menu_template, goto_callables=None):
dict: A `{"node": nodefunc}` menutree suitable to pass into EvMenu. dict: A `{"node": nodefunc}` menutree suitable to pass into EvMenu.
""" """
def _validate_kwarg(goto, kwarg): def _validate_kwarg(goto, kwarg):
""" """
Validate goto-callable kwarg is on correct form. Validate goto-callable kwarg is on correct form.
@ -1792,14 +1798,21 @@ def parse_menu_template(caller, menu_template, goto_callables=None):
f"EvMenu template error: goto-callable '{goto}' has a " f"EvMenu template error: goto-callable '{goto}' has a "
f"non-kwarg argument ({kwarg}). All callables in the " f"non-kwarg argument ({kwarg}). All callables in the "
"template must have only keyword-arguments, or no " "template must have only keyword-arguments, or no "
"args at all.") "args at all."
)
key, _ = [part.strip() for part in kwarg.split("=", 1)] key, _ = [part.strip() for part in kwarg.split("=", 1)]
if key in ("evmenu_goto", "evmenu_gotomap", "_current_nodename", if key in (
"evmenu_current_nodename", "evmenu_goto_callables"): "evmenu_goto",
"evmenu_gotomap",
"_current_nodename",
"evmenu_current_nodename",
"evmenu_goto_callables",
):
raise RuntimeError( raise RuntimeError(
f"EvMenu template error: goto-callable '{goto}' uses a " f"EvMenu template error: goto-callable '{goto}' uses a "
f"kwarg ({kwarg}) that is reserved for the EvMenu templating " f"kwarg ({kwarg}) that is reserved for the EvMenu templating "
"system. Rename the kwarg.") "system. Rename the kwarg."
)
def _parse_options(nodename, optiontxt, goto_callables): def _parse_options(nodename, optiontxt, goto_callables):
""" """
@ -1829,7 +1842,7 @@ def parse_menu_template(caller, menu_template, goto_callables=None):
if match: if match:
kwargs = match.group("kwargs") kwargs = match.group("kwargs")
if kwargs: if kwargs:
for kwarg in kwargs.split(','): for kwarg in kwargs.split(","):
_validate_kwarg(goto, kwarg) _validate_kwarg(goto, kwarg)
# parse key [;aliases|pattern] # parse key [;aliases|pattern]
@ -1841,7 +1854,7 @@ def parse_menu_template(caller, menu_template, goto_callables=None):
if main_key.startswith(_OPTION_INPUT_MARKER): if main_key.startswith(_OPTION_INPUT_MARKER):
# if we have a pattern, build the arguments for _default later # if we have a pattern, build the arguments for _default later
pattern = main_key[len(_OPTION_INPUT_MARKER):].strip() pattern = main_key[len(_OPTION_INPUT_MARKER) :].strip()
inputparsemap[pattern] = goto inputparsemap[pattern] = goto
else: else:
# a regular goto string/callable target # a regular goto string/callable target
@ -1902,12 +1915,7 @@ def parse_menu_template(caller, menu_template, goto_callables=None):
def template2menu( def template2menu(
caller, caller, menu_template, goto_callables=None, startnode="start", persistent=False, **kwargs,
menu_template,
goto_callables=None,
startnode="start",
persistent=False,
**kwargs,
): ):
""" """
Helper function to generate and start an EvMenu based on a menu template Helper function to generate and start an EvMenu based on a menu template
@ -1932,9 +1940,4 @@ def template2menu(
""" """
goto_callables = goto_callables or {} goto_callables = goto_callables or {}
menu_tree = parse_menu_template(caller, menu_template, goto_callables) menu_tree = parse_menu_template(caller, menu_template, goto_callables)
return EvMenu( return EvMenu(caller, menu_tree, persistent=persistent, **kwargs,)
caller,
menu_tree,
persistent=persistent,
**kwargs,
)

View file

@ -321,8 +321,7 @@ class TestMenuTemplateParse(EvenniaTest):
def test_parse_menu_template(self): def test_parse_menu_template(self):
"""EvMenu template testing""" """EvMenu template testing"""
menutree = evmenu.parse_menu_template(self.char1, self.menu_template, menutree = evmenu.parse_menu_template(self.char1, self.menu_template, self.goto_callables)
self.goto_callables)
self.assertEqual(menutree, {"start": Anything, "node1": Anything, "node2": Anything}) self.assertEqual(menutree, {"start": Anything, "node1": Anything, "node2": Anything})
def test_template2menu(self): def test_template2menu(self):