diff --git a/docs/source/Setup/Settings-Default.md b/docs/source/Setup/Settings-Default.md index ce49ad724b..519021f7b2 100644 --- a/docs/source/Setup/Settings-Default.md +++ b/docs/source/Setup/Settings-Default.md @@ -1055,17 +1055,17 @@ MIDDLEWARE = [ # A list of Django apps (see INSTALLED_APPS) that will be listed first (if present) # in the Django web Admin page. DJANGO_ADMIN_APP_ORDER = [ - "accounts", - "objects", - "scripts", - "comms", - "help", - "typeclasses", - "server", - "sites", - "flatpages", - "auth", - ] + "accounts", + "objects", + "scripts", + "comms", + "help", + "typeclasses", + "server", + "sites", + "flatpages", + "auth", +] # The following apps will be excluded from the Django web Admin page. DJANGO_ADMIN_APP_EXCLUDE = list() diff --git a/evennia/__init__.py b/evennia/__init__.py index fc68e75c9d..9b5107023f 100644 --- a/evennia/__init__.py +++ b/evennia/__init__.py @@ -179,7 +179,12 @@ def _init(portal_mode=False): from .comms.models import ChannelDB, Msg from .locks import lockfuncs from .objects.models import ObjectDB - from .objects.objects import DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom + from .objects.objects import ( + DefaultCharacter, + DefaultExit, + DefaultObject, + DefaultRoom, + ) from .prototypes.spawner import spawn from .scripts.models import ScriptDB from .scripts.monitorhandler import MONITOR_HANDLER diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 3f11882b08..17f17ad9b8 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -14,13 +14,14 @@ import re import time from random import getrandbits -import evennia from django.conf import settings from django.contrib.auth import authenticate, password_validation from django.core.exceptions import ImproperlyConfigured, ValidationError from django.utils import timezone from django.utils.module_loading import import_string from django.utils.translation import gettext as _ + +import evennia from evennia.accounts.manager import AccountManager from evennia.accounts.models import AccountDB from evennia.commands.cmdsethandler import CmdSetHandler @@ -38,7 +39,13 @@ from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler from evennia.typeclasses.models import TypeclassBase from evennia.utils import class_from_module, create, logger from evennia.utils.optionhandler import OptionHandler -from evennia.utils.utils import is_iter, lazy_property, make_iter, to_str, variable_from_module +from evennia.utils.utils import ( + is_iter, + lazy_property, + make_iter, + to_str, + variable_from_module, +) __all__ = ("DefaultAccount", "DefaultGuest") @@ -1565,9 +1572,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): else: # In this mode we don't auto-connect but by default end up at a character selection # screen. We execute look on the account. - self.msg( - self.at_look(target=self.characters, session=session), session=session - ) + self.msg(self.at_look(target=self.characters, session=session), session=session) def at_failed_login(self, session, **kwargs): """ diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index c881664982..82bd3e2d57 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -410,7 +410,9 @@ class RSSBot(Bot): # instruct the server and portal to create a new session with # the stored configuration configdict = {"uid": self.dbid, "url": self.db.rss_url, "rate": self.db.rss_rate} - evennia.SESSION_HANDLER.start_bot_session("evennia.server.portal.rss.RSSBotFactory", configdict) + evennia.SESSION_HANDLER.start_bot_session( + "evennia.server.portal.rss.RSSBotFactory", configdict + ) def execute_cmd(self, txt=None, session=None, **kwargs): """ @@ -658,7 +660,7 @@ class DiscordBot(Bot): guild_id (int) - The guild the role will be assigned in. user_id (int) - The user the given role will be assigned to. """ - + super().msg(role=(role_id, guild_id, user_id)) def direct_msg(self, message, sender, **kwargs): diff --git a/evennia/accounts/tests.py b/evennia/accounts/tests.py index 18b4025d96..c85131d48d 100644 --- a/evennia/accounts/tests.py +++ b/evennia/accounts/tests.py @@ -357,9 +357,7 @@ class TestAccountPuppetDeletion(BaseEvenniaTest): @override_settings(MULTISESSION_MODE=2) def test_puppet_deletion(self): # Check for existing chars - self.assertFalse( - self.account.characters, "Account should not have any chars by default." - ) + self.assertFalse(self.account.characters, "Account should not have any chars by default.") # Add char1 to account's playable characters self.account.characters.add(self.char1) @@ -410,9 +408,7 @@ class TestDefaultAccountEv(BaseEvenniaTest): self.assertEqual(idle, 10) # test no sessions - with patch( - "evennia.SESSION_HANDLER.sessions_from_account", return_value=[] - ) as mock_sessh: + with patch("evennia.SESSION_HANDLER.sessions_from_account", return_value=[]) as mock_sessh: idle = self.account.idle_time self.assertEqual(idle, None) @@ -423,9 +419,7 @@ class TestDefaultAccountEv(BaseEvenniaTest): self.assertEqual(conn, 10) # test no sessions - with patch( - "evennia.SESSION_HANDLER.sessions_from_account", return_value=[] - ) as mock_sessh: + with patch("evennia.SESSION_HANDLER.sessions_from_account", return_value=[]) as mock_sessh: idle = self.account.connection_time self.assertEqual(idle, None) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 4bbf3225cb..78e400f7da 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -36,13 +36,14 @@ from weakref import WeakValueDictionary from django.conf import settings from django.utils.translation import gettext as _ -from evennia.commands.command import InterruptCommand -from evennia.utils import logger, utils -from evennia.utils.utils import string_suggestions from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, returnValue from twisted.internet.task import deferLater +from evennia.commands.command import InterruptCommand +from evennia.utils import logger, utils +from evennia.utils.utils import string_suggestions + _IN_GAME_ERRORS = settings.IN_GAME_ERRORS __all__ = ("cmdhandler", "InterruptCommand") diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 288e96e753..9f7b89e674 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -71,6 +71,7 @@ from traceback import format_exc from django.conf import settings from django.utils.translation import gettext as _ + from evennia.commands.cmdset import CmdSet from evennia.server.models import ServerConfig from evennia.utils import logger, utils diff --git a/evennia/commands/command.py b/evennia/commands/command.py index cca0e35754..9368381ef0 100644 --- a/evennia/commands/command.py +++ b/evennia/commands/command.py @@ -11,6 +11,7 @@ import re from django.conf import settings from django.urls import reverse from django.utils.text import slugify + from evennia.locks.lockhandler import LockHandler from evennia.utils.ansi import ANSIString from evennia.utils.evtable import EvTable diff --git a/evennia/commands/default/account.py b/evennia/commands/default/account.py index 5e3c4f404d..acbd071ddf 100644 --- a/evennia/commands/default/account.py +++ b/evennia/commands/default/account.py @@ -22,6 +22,7 @@ import time from codecs import lookup as codecs_lookup from django.conf import settings + import evennia from evennia.utils import create, logger, search, utils @@ -74,6 +75,7 @@ class MuxAccountLookCommand(COMMAND_DEFAULT_CLASS): # use self.account instead of self.caller, just to be sure. Also self.msg() # is used to make sure returns go to the right session + # note that this is inheriting from MuxAccountLookCommand, # and has the .playable property. class CmdOOCLook(MuxAccountLookCommand): @@ -307,7 +309,7 @@ class CmdIC(COMMAND_DEFAULT_CLASS): else: # argument given - if (playables := account.characters): + if playables := account.characters: # look at the playable_characters list first character_candidates.extend( utils.make_iter( diff --git a/evennia/commands/default/admin.py b/evennia/commands/default/admin.py index 69f9dee59f..c39ffc24f5 100644 --- a/evennia/commands/default/admin.py +++ b/evennia/commands/default/admin.py @@ -9,9 +9,8 @@ import time from django.conf import settings -from evennia.server.models import ServerConfig - import evennia +from evennia.server.models import ServerConfig from evennia.utils import class_from_module, evtable, logger, search COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) @@ -512,7 +511,6 @@ class CmdPerm(COMMAND_DEFAULT_CLASS): permissions = obj.permissions.all() for perm in self.rhslist: - # don't allow to set a permission higher in the hierarchy than # the one the caller has (to prevent self-escalation) if perm.lower() in PERMISSION_HIERARCHY and not obj.locks.check_lockstring( diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index fd1434e2cb..9f7c5fa627 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -6,6 +6,7 @@ import re from django.conf import settings from django.core.paginator import Paginator from django.db.models import Max, Min, Q + from evennia import InterruptCommand from evennia.commands.cmdhandler import get_and_merge_cmdsets from evennia.locks.lockhandler import LockException diff --git a/evennia/commands/default/comms.py b/evennia/commands/default/comms.py index 67a86f1125..0ef77a7bb8 100644 --- a/evennia/commands/default/comms.py +++ b/evennia/commands/default/comms.py @@ -8,6 +8,7 @@ Communication commands: """ from django.conf import settings + from evennia.accounts import bots from evennia.accounts.models import AccountDB from evennia.comms.comms import DefaultChannel diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index 9fa6f52b22..f8b53250a8 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -173,7 +173,6 @@ class CmdNick(COMMAND_DEFAULT_CLASS): ) if "list" in switches or self.cmdstring in ("nicks",): - if not nicklist: string = "|wNo nicks defined.|n" else: diff --git a/evennia/commands/default/help.py b/evennia/commands/default/help.py index 4b8cdccbed..888530c906 100644 --- a/evennia/commands/default/help.py +++ b/evennia/commands/default/help.py @@ -13,13 +13,20 @@ from dataclasses import dataclass from itertools import chain from django.conf import settings + from evennia.help.filehelp import FILE_HELP_ENTRIES from evennia.help.models import HelpEntry from evennia.help.utils import help_search_with_index, parse_entry_for_subcategories from evennia.utils import create, evmore from evennia.utils.ansi import ANSIString from evennia.utils.eveditor import EvEditor -from evennia.utils.utils import class_from_module, dedent, format_grid, inherits_from, pad +from evennia.utils.utils import ( + class_from_module, + dedent, + format_grid, + inherits_from, + pad, +) CMD_IGNORE_PREFIXES = settings.CMD_IGNORE_PREFIXES COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index e4c22664e2..fa68adf199 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -13,9 +13,10 @@ import time import traceback import django -import evennia import twisted from django.conf import settings + +import evennia from evennia.accounts.models import AccountDB from evennia.scripts.taskhandler import TaskHandlerTask from evennia.utils import gametime, logger, search, utils diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 774bd83335..340c5271a6 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -17,6 +17,9 @@ from unittest.mock import MagicMock, Mock, patch from anything import Anything from django.conf import settings from django.test import override_settings +from parameterized import parameterized +from twisted.internet import task + import evennia from evennia import ( DefaultCharacter, @@ -29,7 +32,14 @@ from evennia import ( from evennia.commands import cmdparser from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command, InterruptCommand -from evennia.commands.default import account, admin, batchprocess, building, comms, general +from evennia.commands.default import ( + account, + admin, + batchprocess, + building, + comms, + general, +) from evennia.commands.default import help as help_module from evennia.commands.default import syscommands, system, unloggedin from evennia.commands.default.cmdset_character import CharacterCmdSet @@ -38,8 +48,6 @@ from evennia.prototypes import prototypes as protlib from evennia.utils import create, gametime, utils from evennia.utils.test_resources import BaseEvenniaCommandTest # noqa from evennia.utils.test_resources import BaseEvenniaTest, EvenniaCommandTest -from parameterized import parameterized -from twisted.internet import task # ------------------------------------------------------------ # Command testing @@ -1597,8 +1605,9 @@ class TestBuilding(BaseEvenniaCommandTest): self.call( building.CmdTeleport(), "Obj = Room2", - "Obj(#{}) is leaving Room(#{}), heading for Room2(#{}).|Teleported Obj -> Room2." - .format(oid, rid, rid2), + "Obj(#{}) is leaving Room(#{}), heading for Room2(#{}).|Teleported Obj -> Room2.".format( + oid, rid, rid2 + ), ) self.call(building.CmdTeleport(), "NotFound = Room", "Could not find 'NotFound'.") self.call( @@ -1714,8 +1723,7 @@ class TestBuilding(BaseEvenniaCommandTest): self.call( building.CmdSpawn(), "{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', " - "'key':'goblin', 'location':'%s'}" - % spawnLoc.dbref, + "'key':'goblin', 'location':'%s'}" % spawnLoc.dbref, "Spawned goblin", ) goblin = get_object(self, "goblin") @@ -1763,8 +1771,7 @@ class TestBuilding(BaseEvenniaCommandTest): self.call( building.CmdSpawn(), "/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo'," - " 'location':'%s'}" - % spawnLoc.dbref, + " 'location':'%s'}" % spawnLoc.dbref, "Spawned Ball", ) ball = get_object(self, "Ball") diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index 7bc58dc115..d149fb314a 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -6,8 +6,9 @@ import datetime import re from codecs import lookup as codecs_lookup -import evennia from django.conf import settings + +import evennia from evennia.commands.cmdhandler import CMD_LOGINSTART from evennia.comms.models import ChannelDB from evennia.utils import class_from_module, create, gametime, logger, utils diff --git a/evennia/commands/tests.py b/evennia/commands/tests.py index a70572e6fc..dcd11b9865 100644 --- a/evennia/commands/tests.py +++ b/evennia/commands/tests.py @@ -4,6 +4,7 @@ Unit testing for the Command system itself. """ from django.test import override_settings + from evennia.commands import cmdparser from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command @@ -990,9 +991,10 @@ class TestOptionTransferReplace(TestCase): import sys -from evennia.commands import cmdhandler from twisted.trial.unittest import TestCase as TwistedTestCase +from evennia.commands import cmdhandler + def _mockdelay(time, func, *args, **kwargs): return func(*args, **kwargs) @@ -1250,7 +1252,6 @@ class TestIssue3090(BaseEvenniaTest): """ def test_long_aliases(self): - cmdset_g = _CmdSetG() # print(cmdset_g.commands[0]._keyaliases) diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index 7e370b23f1..ffaae7c543 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -7,6 +7,7 @@ import re from django.contrib.contenttypes.models import ContentType from django.urls import reverse from django.utils.text import slugify + from evennia.comms.managers import ChannelManager from evennia.comms.models import ChannelDB from evennia.typeclasses.models import TypeclassBase diff --git a/evennia/comms/managers.py b/evennia/comms/managers.py index 224e25a278..b55b814009 100644 --- a/evennia/comms/managers.py +++ b/evennia/comms/managers.py @@ -7,6 +7,7 @@ Comm system components. from django.conf import settings from django.db.models import Q + from evennia.server import signals from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager from evennia.utils import logger diff --git a/evennia/comms/models.py b/evennia/comms/models.py index 80dfa69d79..0e7b288281 100644 --- a/evennia/comms/models.py +++ b/evennia/comms/models.py @@ -21,6 +21,7 @@ necessary to easily be able to delete connections on the fly). from django.conf import settings from django.db import models from django.utils import timezone + from evennia.comms import managers from evennia.locks.lockhandler import LockHandler from evennia.typeclasses.models import TypedObject diff --git a/evennia/contrib/base_systems/building_menu/building_menu.py b/evennia/contrib/base_systems/building_menu/building_menu.py index 518ae14f66..fbe35c1bb4 100644 --- a/evennia/contrib/base_systems/building_menu/building_menu.py +++ b/evennia/contrib/base_systems/building_menu/building_menu.py @@ -126,6 +126,7 @@ from inspect import getfullargspec from textwrap import dedent from django.conf import settings + from evennia import CmdSet, Command from evennia.commands import cmdhandler from evennia.utils.ansi import strip_ansi diff --git a/evennia/contrib/base_systems/building_menu/tests.py b/evennia/contrib/base_systems/building_menu/tests.py index cd29faaf4e..778e03f0b5 100644 --- a/evennia/contrib/base_systems/building_menu/tests.py +++ b/evennia/contrib/base_systems/building_menu/tests.py @@ -98,6 +98,7 @@ class TestBuildingMenu(BaseEvenniaCommandTest): def test_multi_level(self): """Test multi-level choices.""" + # Creaste three succeeding menu (t2 is contained in t1, t3 is contained in t2) def on_nomatch_t1(caller, menu): menu.move("whatever") # this will be valid since after t1 is a joker diff --git a/evennia/contrib/base_systems/components/tests.py b/evennia/contrib/base_systems/components/tests.py index eb1717c939..0bb662f218 100644 --- a/evennia/contrib/base_systems/components/tests.py +++ b/evennia/contrib/base_systems/components/tests.py @@ -58,7 +58,7 @@ class TestComponents(EvenniaTest): InheritedTCWithComponents, key="char_with_c", location=self.room1, home=self.room1 ) assert self.char1.test_a - assert not self.char1.cmp.get('test_c') + assert not self.char1.cmp.get("test_c") assert char_with_c.test_c def test_character_instances_components_properly(self): diff --git a/evennia/contrib/base_systems/godotwebsocket/webclient.py b/evennia/contrib/base_systems/godotwebsocket/webclient.py index 0c8001825f..8e8f02958b 100644 --- a/evennia/contrib/base_systems/godotwebsocket/webclient.py +++ b/evennia/contrib/base_systems/godotwebsocket/webclient.py @@ -70,6 +70,7 @@ def start_plugin_services(portal): factory.noisy = False factory.protocol = GodotWebSocketClient from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS + factory.sessionhandler = PORTAL_SESSIONS interface = "127.0.0.1" if LOCKDOWN_MODE else settings.GODOT_CLIENT_WEBSOCKET_CLIENT_INTERFACE diff --git a/evennia/contrib/base_systems/menu_login/menu_login.py b/evennia/contrib/base_systems/menu_login/menu_login.py index 78f6aac998..98c560186e 100644 --- a/evennia/contrib/base_systems/menu_login/menu_login.py +++ b/evennia/contrib/base_systems/menu_login/menu_login.py @@ -167,7 +167,6 @@ def node_enter_password(caller, raw_string, **kwargs): username = kwargs["username"] if kwargs["new_user"]: - if kwargs.get("retry_password"): # Attempting to fix password text = "Enter a new password:" diff --git a/evennia/contrib/full_systems/evscaperoom/commands.py b/evennia/contrib/full_systems/evscaperoom/commands.py index 6501bb7525..e573e1c8ba 100644 --- a/evennia/contrib/full_systems/evscaperoom/commands.py +++ b/evennia/contrib/full_systems/evscaperoom/commands.py @@ -296,7 +296,6 @@ class CmdWho(CmdEvscapeRoom, default_cmds.CmdWho): obj2_search = False def func(self): - caller = self.caller if self.args == "all": @@ -344,7 +343,6 @@ class CmdSpeak(Command): arg_regex = r"\w|\s|$" def func(self): - args = self.args.strip() caller = self.caller action = self.cmdname @@ -584,7 +582,6 @@ class CmdFocusInteraction(CmdEvscapeRoom): self.room = self.caller.location def func(self): - focused = self.focus action = self.action @@ -604,7 +601,6 @@ class CmdStand(CmdEvscapeRoom): key = "stand" def func(self): - # Positionable objects will set this flag on you. pos = self.caller.attributes.get("position", category=self.room.tagcategory) @@ -710,7 +706,6 @@ class CmdSetFlag(CmdEvscapeRoom): obj2_search = False def func(self): - if not self.arg2: self.caller.msg("Usage: flag with ") return diff --git a/evennia/contrib/full_systems/evscaperoom/menu.py b/evennia/contrib/full_systems/evscaperoom/menu.py index 96ff22551a..8e76fb67fe 100644 --- a/evennia/contrib/full_systems/evscaperoom/menu.py +++ b/evennia/contrib/full_systems/evscaperoom/menu.py @@ -66,7 +66,6 @@ def _move_to_room(caller, raw_string, **kwargs): def _create_new_room(caller, raw_string, **kwargs): - # create a random name, retrying until we find # a unique one key = create_fantasy_word(length=5, capitalize=True) @@ -147,7 +146,6 @@ def node_start(caller, raw_string, **kwargs): def node_set_desc(caller, raw_string, **kwargs): - current_desc = kwargs.get("desc", caller.db.desc) text = ( @@ -176,7 +174,6 @@ def node_set_desc(caller, raw_string, **kwargs): def node_create_room(caller, raw_string, **kwargs): - text = _CREATE_ROOM_TEXT options = ( @@ -188,7 +185,6 @@ def node_create_room(caller, raw_string, **kwargs): def node_join_room(caller, raw_string, **kwargs): - room = kwargs["room"] stats = room.db.stats or {"progress": 0} @@ -282,7 +278,6 @@ def _set_thing_style(caller, raw_string, **kwargs): def _toggle_screen_reader(caller, raw_string, **kwargs): - session = kwargs["session"] # flip old setting session.protocol_flags["SCREENREADER"] = not session.protocol_flags.get("SCREENREADER", False) diff --git a/evennia/contrib/full_systems/evscaperoom/objects.py b/evennia/contrib/full_systems/evscaperoom/objects.py index e0b91146c6..627c931472 100644 --- a/evennia/contrib/full_systems/evscaperoom/objects.py +++ b/evennia/contrib/full_systems/evscaperoom/objects.py @@ -416,7 +416,6 @@ class Rotatable(EvscaperoomObject): self.set_flag("rotatable") def at_focus_rotate(self, caller, **kwargs): - if self.check_flag("rotatable"): self.at_rotate(caller) else: @@ -501,7 +500,6 @@ class Readable(EvscaperoomObject): self.set_flag(self.read_flag) def at_focus_read(self, caller, **kwargs): - if self.read_flag is None or self.check_flag(self.read_flag): self.at_read(caller) else: @@ -525,7 +523,6 @@ class IndexReadable(Readable): index = {"page1": "This is page1", "page2": "This is page2", "page two": "page2"} # alias def at_focus_read(self, caller, **kwargs): - topic = kwargs.get("args").strip().lower() entry = self.index.get(topic, None) @@ -931,7 +928,6 @@ class CodeInput(EvscaperoomObject): infinitely_locked = False def at_focus_code(self, caller, **kwargs): - args = self.parse(kwargs["args"].strip()) if not args: diff --git a/evennia/contrib/full_systems/evscaperoom/scripts.py b/evennia/contrib/full_systems/evscaperoom/scripts.py index 003e740566..583c59ebf8 100644 --- a/evennia/contrib/full_systems/evscaperoom/scripts.py +++ b/evennia/contrib/full_systems/evscaperoom/scripts.py @@ -14,7 +14,6 @@ from .room import EvscapeRoom class CleanupScript(DefaultScript): def at_script_creation(self): - self.key = "evscaperoom_cleanup" self.desc = "Cleans up empty evscaperooms" @@ -23,7 +22,6 @@ class CleanupScript(DefaultScript): self.persistent = True def at_repeat(self): - for room in EvscapeRoom.objects.all(): if not room.get_all_characters(): # this room is empty diff --git a/evennia/contrib/full_systems/evscaperoom/tests.py b/evennia/contrib/full_systems/evscaperoom/tests.py index 16d41622dc..92c214d785 100644 --- a/evennia/contrib/full_systems/evscaperoom/tests.py +++ b/evennia/contrib/full_systems/evscaperoom/tests.py @@ -24,7 +24,6 @@ class TestEvscaperoomCommands(BaseEvenniaCommandTest): self.obj1.location = self.room1 def test_base_search(self): - cmd = commands.CmdEvscapeRoom() cmd.caller = self.char1 @@ -35,7 +34,6 @@ class TestEvscaperoomCommands(BaseEvenniaCommandTest): self.assertRaises(InterruptCommand, cmd._search, "Foo", True) def test_base_parse(self): - cmd = commands.CmdEvscapeRoom() cmd.caller = self.char1 @@ -211,7 +209,6 @@ class TestUtils(BaseEvenniaTest): self.assertTrue(bool(obj2.pk)) def test_parse_for_perspectives(self): - second, third = utils.parse_for_perspectives("~You ~look at the nice book", "TestGuy") self.assertTrue(second, "You look at the nice book") self.assertTrue(third, "TestGuy looks at the nice book") @@ -221,7 +218,6 @@ class TestUtils(BaseEvenniaTest): self.assertTrue(third, "With a smile, TestGuy was gone") def test_parse_for_things(self): - string = "Looking at *book and *key." self.assertEqual(utils.parse_for_things(string, 0), "Looking at book and key.") self.assertEqual(utils.parse_for_things(string, 1), "Looking at |ybook|n and |ykey|n.") @@ -240,7 +236,6 @@ class TestEvScapeRoom(BaseEvenniaTest): self.room.delete() def test_room_methods(self): - room = self.room self.char1.location = room @@ -279,7 +274,6 @@ class TestStates(BaseEvenniaTest): return states def test_base_state(self): - st = basestate.BaseState(self.room.statehandler, self.room) st.init() obj = st.create_object(objects.Edible, key="apple") @@ -291,7 +285,6 @@ class TestStates(BaseEvenniaTest): "Tick through all defined states" for mod in self._get_all_state_modules(): - state = mod.State(self.room.statehandler, self.room) state.init() diff --git a/evennia/contrib/game_systems/containers/containers.py b/evennia/contrib/game_systems/containers/containers.py index 67c9494314..66c31b7175 100644 --- a/evennia/contrib/game_systems/containers/containers.py +++ b/evennia/contrib/game_systems/containers/containers.py @@ -33,7 +33,7 @@ or implement the same locks/hooks in your own typeclasses. from django.conf import settings from evennia import AttributeProperty, CmdSet, DefaultObject -from evennia.commands.default.general import CmdLook, CmdGet, CmdDrop +from evennia.commands.default.general import CmdDrop, CmdGet, CmdLook from evennia.utils import class_from_module # establish the right inheritance for container objects diff --git a/evennia/contrib/game_systems/containers/tests.py b/evennia/contrib/game_systems/containers/tests.py index ded594708e..45769a59d6 100644 --- a/evennia/contrib/game_systems/containers/tests.py +++ b/evennia/contrib/game_systems/containers/tests.py @@ -1,6 +1,7 @@ from evennia import create_object -from evennia.utils.test_resources import BaseEvenniaTest, BaseEvenniaCommandTest # noqa -from .containers import ContribContainer, CmdContainerGet, CmdContainerLook, CmdPut +from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest # noqa + +from .containers import CmdContainerGet, CmdContainerLook, CmdPut, ContribContainer class TestContainer(BaseEvenniaTest): @@ -52,7 +53,7 @@ class TestContainerCmds(BaseEvenniaCommandTest): # move object to character to try putting self.obj1.location = self.char1 self.call(CmdPut(), "obj in box", "You can't put things in that.") - + def test_at_capacity_put(self): # set container capacity self.container.capacity = 1 @@ -61,5 +62,3 @@ class TestContainerCmds(BaseEvenniaCommandTest): # move object to character to try putting self.obj1.location = self.char1 self.call(CmdPut(), "obj in box", "You can't fit anything else in a Box.") - - diff --git a/evennia/contrib/game_systems/crafting/crafting.py b/evennia/contrib/game_systems/crafting/crafting.py index 541040a038..bc1d0e140b 100644 --- a/evennia/contrib/game_systems/crafting/crafting.py +++ b/evennia/contrib/game_systems/crafting/crafting.py @@ -318,7 +318,6 @@ class CraftingRecipeBase: """ craft_result = None if self.allow_craft: - # override/extend craft_kwargs from initialization. craft_kwargs = copy(self.craft_kwargs) craft_kwargs.update(kwargs) @@ -626,7 +625,6 @@ class CraftingRecipe(CraftingRecipeBase): self.allow_reuse = not bool(self.consumable_tags) def _format_message(self, message, **kwargs): - missing = iter_to_str(kwargs.get("missing", "")) excess = iter_to_str(kwargs.get("excess", "")) involved_tools = iter_to_str(kwargs.get("tools", "")) @@ -702,7 +700,6 @@ class CraftingRecipe(CraftingRecipeBase): tools = [] for itag, tag in enumerate(cls.tool_tags): - tools.append( create_object( key=tool_key or (cls.tool_names[itag] if cls.tool_names else tag.capitalize()), diff --git a/evennia/contrib/game_systems/crafting/example_recipes.py b/evennia/contrib/game_systems/crafting/example_recipes.py index 607608d609..772d62f851 100644 --- a/evennia/contrib/game_systems/crafting/example_recipes.py +++ b/evennia/contrib/game_systems/crafting/example_recipes.py @@ -511,7 +511,6 @@ class CmdCast(Command): self.target = self.caller def func(self): - # all items carried by the caller could work possible_tools = self.caller.contents diff --git a/evennia/contrib/game_systems/puzzles/puzzles.py b/evennia/contrib/game_systems/puzzles/puzzles.py index 2194e1daa2..c32630c56a 100644 --- a/evennia/contrib/game_systems/puzzles/puzzles.py +++ b/evennia/contrib/game_systems/puzzles/puzzles.py @@ -646,7 +646,6 @@ class CmdUsePuzzleParts(MuxCommand): return if not part.tags.get(_PUZZLES_TAG_MEMBER, category=_PUZZLES_TAG_CATEGORY): - # not a puzzle part ... abort caller.msg("You have no idea how %s can be used" % (many)) return diff --git a/evennia/contrib/game_systems/puzzles/tests.py b/evennia/contrib/game_systems/puzzles/tests.py index cfd2fe205d..d3871cadd0 100644 --- a/evennia/contrib/game_systems/puzzles/tests.py +++ b/evennia/contrib/game_systems/puzzles/tests.py @@ -184,7 +184,6 @@ class TestPuzzles(BaseEvenniaCommandTest): return msg def test_cmd_use(self): - self._use("", "Use what?") self._use("something", "There is no something around.") self._use("steel", "You have no idea how this can be used") diff --git a/evennia/contrib/game_systems/turnbattle/tb_basic.py b/evennia/contrib/game_systems/turnbattle/tb_basic.py index 6757f6b852..fde8b453e6 100644 --- a/evennia/contrib/game_systems/turnbattle/tb_basic.py +++ b/evennia/contrib/game_systems/turnbattle/tb_basic.py @@ -323,7 +323,7 @@ class TBBasicCharacter(DefaultCharacter): can be changed at creation and factor into combat calculations. """ - def at_pre_move(self, destination, move_type='move', **kwargs): + def at_pre_move(self, destination, move_type="move", **kwargs): """ Called just before starting to move this object to destination. diff --git a/evennia/contrib/game_systems/turnbattle/tb_items.py b/evennia/contrib/game_systems/turnbattle/tb_items.py index 6d6de267f0..3d3f3cd640 100644 --- a/evennia/contrib/game_systems/turnbattle/tb_items.py +++ b/evennia/contrib/game_systems/turnbattle/tb_items.py @@ -259,7 +259,6 @@ class ItemCombatRules(tb_basic.BasicCombatRules): user.msg("%s has %i uses remaining." % (item.key.capitalize(), item.db.item_uses)) else: # All uses spent - if not item.db.item_consumable: # Item isn't consumable # Just inform the player that the uses are gone user.msg("%s has no uses remaining." % item.key.capitalize()) diff --git a/evennia/contrib/game_systems/turnbattle/tests.py b/evennia/contrib/game_systems/turnbattle/tests.py index 6b11858dd1..92dcb707f6 100644 --- a/evennia/contrib/game_systems/turnbattle/tests.py +++ b/evennia/contrib/game_systems/turnbattle/tests.py @@ -14,7 +14,6 @@ from . import tb_basic, tb_equip, tb_items, tb_magic, tb_range class TestTurnBattleBasicCmd(BaseEvenniaCommandTest): - # Test basic combat commands def test_turnbattlecmd(self): self.call(tb_basic.CmdFight(), "", "You can't start a fight if you've been defeated!") @@ -81,7 +80,6 @@ class TestTurnBattleItemsCmd(BaseEvenniaCommandTest): class TestTurnBattleMagicCmd(BaseEvenniaCommandTest): - # Test magic commands def test_turnbattlemagiccmd(self): self.call(tb_magic.CmdStatus(), "", "You have 100 / 100 HP and 20 / 20 MP.") diff --git a/evennia/contrib/grid/extended_room/extended_room.py b/evennia/contrib/grid/extended_room/extended_room.py index f222ec08ed..19e2b0bb75 100644 --- a/evennia/contrib/grid/extended_room/extended_room.py +++ b/evennia/contrib/grid/extended_room/extended_room.py @@ -47,6 +47,7 @@ from collections import deque from django.conf import settings from django.db.models import Q + from evennia import ( CmdSet, DefaultRoom, diff --git a/evennia/contrib/grid/extended_room/tests.py b/evennia/contrib/grid/extended_room/tests.py index 05e1143f75..715bda03a7 100644 --- a/evennia/contrib/grid/extended_room/tests.py +++ b/evennia/contrib/grid/extended_room/tests.py @@ -6,11 +6,12 @@ Testing of ExtendedRoom contrib import datetime from django.conf import settings -from evennia import create_object -from evennia.utils.test_resources import BaseEvenniaCommandTest, EvenniaTestCase from mock import Mock, patch from parameterized import parameterized +from evennia import create_object +from evennia.utils.test_resources import BaseEvenniaCommandTest, EvenniaTestCase + from . import extended_room diff --git a/evennia/contrib/grid/wilderness/wilderness.py b/evennia/contrib/grid/wilderness/wilderness.py index 78e0d6d5cd..f78217bfac 100644 --- a/evennia/contrib/grid/wilderness/wilderness.py +++ b/evennia/contrib/grid/wilderness/wilderness.py @@ -123,7 +123,13 @@ create a new wilderness (with the name "default") but using our new map provider """ -from evennia import DefaultExit, DefaultRoom, DefaultScript, create_object, create_script +from evennia import ( + DefaultExit, + DefaultRoom, + DefaultScript, + create_object, + create_script, +) from evennia.typeclasses.attributes import AttributeProperty from evennia.utils import inherits_from diff --git a/evennia/contrib/grid/xyzgrid/__init__.py b/evennia/contrib/grid/xyzgrid/__init__.py index 5b885b4693..cc2ad276e1 100644 --- a/evennia/contrib/grid/xyzgrid/__init__.py +++ b/evennia/contrib/grid/xyzgrid/__init__.py @@ -2,6 +2,16 @@ XYZGrid - Griatch 2021 """ -from . import example, launchcmd, prototypes, tests, utils, xymap, xymap_legend, xyzgrid, xyzroom +from . import ( + example, + launchcmd, + prototypes, + tests, + utils, + xymap, + xymap_legend, + xyzgrid, + xyzroom, +) from . import commands # isort:skip - this needs to be imported last diff --git a/evennia/contrib/grid/xyzgrid/commands.py b/evennia/contrib/grid/xyzgrid/commands.py index cb92ca3bf0..88451ffd82 100644 --- a/evennia/contrib/grid/xyzgrid/commands.py +++ b/evennia/contrib/grid/xyzgrid/commands.py @@ -10,6 +10,7 @@ the commands with XYZ-aware equivalents. from collections import namedtuple from django.conf import settings + from evennia import CmdSet, InterruptCommand, default_cmds from evennia.commands.default import building from evennia.contrib.grid.xyzgrid.xyzgrid import get_xyzgrid @@ -227,7 +228,6 @@ class CmdGoto(COMMAND_DEFAULT_CLASS): step_sequence=None, step=True, ): - path_data = caller.ndb.xy_path_data if target: @@ -244,7 +244,6 @@ class CmdGoto(COMMAND_DEFAULT_CLASS): ) if step and path_data: - step_sequence = path_data.step_sequence try: diff --git a/evennia/contrib/grid/xyzgrid/example.py b/evennia/contrib/grid/xyzgrid/example.py index f0dbc5cb8d..7fe49f0302 100644 --- a/evennia/contrib/grid/xyzgrid/example.py +++ b/evennia/contrib/grid/xyzgrid/example.py @@ -172,6 +172,7 @@ MAP2 = r""" """ + # custom map node class TransitionToLargeTree(xymap_legend.TransitionMapNode): """ diff --git a/evennia/contrib/grid/xyzgrid/tests.py b/evennia/contrib/grid/xyzgrid/tests.py index 4e8b229bdb..28e06cfe73 100644 --- a/evennia/contrib/grid/xyzgrid/tests.py +++ b/evennia/contrib/grid/xyzgrid/tests.py @@ -7,9 +7,10 @@ from random import randint from unittest import mock from django.test import TestCase -from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest from parameterized import parameterized +from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest + from . import commands, xymap, xymap_legend, xyzgrid, xyzroom MAP1 = """ diff --git a/evennia/contrib/grid/xyzgrid/xymap.py b/evennia/contrib/grid/xyzgrid/xymap.py index df7926b0b4..25e89ffdc5 100644 --- a/evennia/contrib/grid/xyzgrid/xymap.py +++ b/evennia/contrib/grid/xyzgrid/xymap.py @@ -563,7 +563,6 @@ class XYMap: def _scan_neighbors( start_node, points, dist=2, xmin=BIGVAL, ymin=BIGVAL, xmax=0, ymax=0, depth=0 ): - x0, y0 = start_node.x, start_node.y points.append((x0, y0)) xmin, xmax = min(xmin, x0), max(xmax, x0) @@ -930,7 +929,7 @@ class XYMap: # now different from the original for future cropping width, height = xmax - xmin + 1, ymax - ymin + 1 gridmap = [[" "] * width for _ in range(height)] - for (ix0, iy0) in points: + for ix0, iy0 in points: gridmap[iy0 - ymin][ix0 - xmin] = display_map[iy0][ix0] elif mode == "scan": diff --git a/evennia/contrib/grid/xyzgrid/xymap_legend.py b/evennia/contrib/grid/xyzgrid/xymap_legend.py index 0e8ea1c244..17f8252fc8 100644 --- a/evennia/contrib/grid/xyzgrid/xymap_legend.py +++ b/evennia/contrib/grid/xyzgrid/xymap_legend.py @@ -20,6 +20,7 @@ import uuid from collections import defaultdict from django.core import exceptions as django_exceptions + from evennia.prototypes import spawner from evennia.utils.utils import class_from_module @@ -182,7 +183,6 @@ class MapNode: # scan in all directions for links for direction, (dx, dy) in MAPSCAN.items(): - lx, ly = x + dx, y + dy if lx in xygrid and ly in xygrid[lx]: @@ -273,7 +273,6 @@ class MapNode: return self.X, self.Y, self.Z def get_exit_spawn_name(self, direction, return_aliases=True): - """ Retrieve the spawn name for the exit being created by this link. @@ -365,7 +364,6 @@ class MapNode: maplinks = {} for direction, link in self.first_links.items(): - key, *aliases = self.get_exit_spawn_name(direction) if not link.prototype.get("prototype_key"): # generate a deterministic prototype_key if it doesn't exist @@ -389,7 +387,6 @@ class MapNode: # build all exits first run) differing_keys = set(maplinks.keys()).symmetric_difference(set(linkobjs.keys())) for differing_key in differing_keys: - if differing_key not in maplinks: # an exit without a maplink - delete the exit-object self.log(f" deleting exit at xyz={xyz}, direction={differing_key}") diff --git a/evennia/contrib/grid/xyzgrid/xyzgrid.py b/evennia/contrib/grid/xyzgrid/xyzgrid.py index 6b800bd1b5..2065eeea12 100644 --- a/evennia/contrib/grid/xyzgrid/xyzgrid.py +++ b/evennia/contrib/grid/xyzgrid/xyzgrid.py @@ -150,7 +150,6 @@ class XYZGrid(DefaultScript): # generate all Maps - this will also initialize their components # and bake any pathfinding paths (or load from disk-cache) for zcoord, old_mapdata in mapdata.items(): - self.log(f"Loading map '{zcoord}'...") # we reload the map from module diff --git a/evennia/contrib/grid/xyzgrid/xyzroom.py b/evennia/contrib/grid/xyzgrid/xyzroom.py index 5a9efcdd14..5f9ab61e40 100644 --- a/evennia/contrib/grid/xyzgrid/xyzroom.py +++ b/evennia/contrib/grid/xyzgrid/xyzroom.py @@ -9,6 +9,7 @@ used as stand-alone XYZ-coordinate-aware rooms. from django.conf import settings from django.db.models import Q + from evennia.objects.manager import ObjectManager from evennia.objects.objects import DefaultExit, DefaultRoom @@ -440,7 +441,6 @@ class XYZRoom(DefaultRoom): xymap = self.xyzgrid.get_map(xyz[2]) if xymap and kwargs.get("map_display", xymap.options.get("map_display", self.map_display)): - # show the near-area map. map_character_symbol = kwargs.get( "map_character_symbol", diff --git a/evennia/contrib/rpg/buffs/buff.py b/evennia/contrib/rpg/buffs/buff.py index acd712e76b..e09a070125 100644 --- a/evennia/contrib/rpg/buffs/buff.py +++ b/evennia/contrib/rpg/buffs/buff.py @@ -168,7 +168,8 @@ class BaseBuff: Args: handler: The handler this buff is attached to buffkey: The key this buff uses on the cache - cache: The cache dictionary (what you get if you use `handler.buffcache.get(key)`)""" + cache: The cache dictionary (what you get if you use `handler.buffcache.get(key)`) + """ required = {"handler": handler, "buffkey": buffkey, "cache": cache} self.__dict__.update(cache) self.__dict__.update(required) @@ -196,7 +197,8 @@ class BaseBuff: loud: (optional) Whether to call at_remove or not (default: True) expire: (optional) Whether to call at_expire or not (default: False) delay: (optional) How long you want to delay the remove call for - context: (optional) A dictionary you wish to pass to the at_remove/at_expire method as kwargs""" + context: (optional) A dictionary you wish to pass to the at_remove/at_expire method as kwargs + """ if not context: context = {} self.handler.remove(self.buffkey, loud=loud, expire=expire, context=context) @@ -207,7 +209,8 @@ class BaseBuff: Args: loud: (optional) Whether to call at_remove or not (default: True) delay: (optional) How long you want to delay the remove call for - context: (optional) A dictionary you wish to pass to the at_remove/at_dispel method as kwargs""" + context: (optional) A dictionary you wish to pass to the at_remove/at_dispel method as kwargs + """ if not context: context = {} self.handler.remove(self.buffkey, loud=loud, dispel=True, delay=delay, context=context) @@ -225,7 +228,8 @@ class BaseBuff: """Helper method which unpauses this buff on its handler. Args: - context: (optional) A dictionary you wish to pass to the at_unpause method as kwargs""" + context: (optional) A dictionary you wish to pass to the at_unpause method as kwargs + """ if not context: context = {} self.handler.unpause(self.buffkey, context) @@ -322,7 +326,6 @@ class Mod: class BuffHandler: - ownerref = None dbkey = "buffs" autopause = False @@ -333,7 +336,8 @@ class BuffHandler: Args: owner: The object this handler is attached to dbkey: (optional) The string key of the db attribute to use for the buff cache - autopause: (optional) Whether this handler autopauses playtime buffs on owning object's unpuppet""" + autopause: (optional) Whether this handler autopauses playtime buffs on owning object's unpuppet + """ self.ownerref = owner.dbref self.dbkey = dbkey self.autopause = autopause @@ -434,7 +438,6 @@ class BuffHandler: *args, **kwargs, ): - """Add a buff to this object, respecting all stacking/refresh/reapplication rules. Takes a number of optional parameters to allow for customization. @@ -702,7 +705,8 @@ class BuffHandler: buff: The buff class to search for to_filter: (optional) A dictionary you wish to slice. If not provided, uses the whole buffcache. - Returns a dictionary of instanced buffs of the specified type in the format {buffkey: instance}.""" + Returns a dictionary of instanced buffs of the specified type in the format {buffkey: instance}. + """ _cache = self.get_all() if not to_filter else to_filter return {k: _buff for k, _buff in _cache.items() if isinstance(_buff, buff)} @@ -713,7 +717,8 @@ class BuffHandler: stat: The string identifier to find relevant mods to_filter: (optional) A dictionary you wish to slice. If not provided, uses the whole buffcache. - Returns a dictionary of instanced buffs which modify the specified stat in the format {buffkey: instance}.""" + Returns a dictionary of instanced buffs which modify the specified stat in the format {buffkey: instance}. + """ _cache = self.traits if not to_filter else to_filter buffs = {k: buff for k, buff in _cache.items() for m in buff.mods if m.stat == stat} return buffs @@ -725,7 +730,8 @@ class BuffHandler: trigger: The string identifier to find relevant buffs to_filter: (optional) A dictionary you wish to slice. If not provided, uses the whole buffcache. - Returns a dictionary of instanced buffs which fire off the designated trigger, in the format {buffkey: instance}.""" + Returns a dictionary of instanced buffs which fire off the designated trigger, in the format {buffkey: instance}. + """ _cache = self.effects if not to_filter else to_filter buffs = {k: buff for k, buff in _cache.items() if trigger in buff.triggers} return buffs @@ -737,7 +743,8 @@ class BuffHandler: source: The source you want to filter buffs by to_filter: (optional) A dictionary you wish to slice. If not provided, uses the whole buffcache. - Returns a dictionary of instanced buffs which came from the provided source, in the format {buffkey: instance}.""" + Returns a dictionary of instanced buffs which came from the provided source, in the format {buffkey: instance}. + """ _cache = self.all if not to_filter else to_filter buffs = {k: buff for k, buff in _cache.items() if buff.source == source} return buffs @@ -750,7 +757,8 @@ class BuffHandler: value: (optional) The value to match to. If None, merely checks to see if the value exists to_filter: (optional) A dictionary you wish to slice. If not provided, uses the whole buffcache. - Returns a dictionary of instanced buffs with cache values matching the specified value, in the format {buffkey: instance}.""" + Returns a dictionary of instanced buffs with cache values matching the specified value, in the format {buffkey: instance}. + """ _cache = self.all if not to_filter else to_filter if not value: buffs = {k: buff for k, buff in _cache.items() if buff.cache.get(key)} @@ -907,7 +915,8 @@ class BuffHandler: Args: key: The key for the buff you wish to pause - context: (optional) A dictionary you wish to pass to the at_unpause method as kwargs""" + context: (optional) A dictionary you wish to pass to the at_unpause method as kwargs + """ if key in self.buffcache.keys(): # Mark the buff as unpaused buff = dict(self.buffcache.get(key)) @@ -945,7 +954,8 @@ class BuffHandler: """Returns a buff flavor text as a dictionary of tuples in the format {key: (name, flavor)}. Common use for this is a buff readout of some kind. Args: - to_filter: (optional) The dictionary of buffs to iterate over. If none is provided, returns all buffs (default: None)""" + to_filter: (optional) The dictionary of buffs to iterate over. If none is provided, returns all buffs (default: None) + """ if not isinstance(to_filter, dict): raise TypeError self.cleanup() @@ -1156,7 +1166,8 @@ def tick_buff(handler: BuffHandler, buffkey: str, context=None, initial=True): handler: The handler managing the ticking buff buffkey: The key of the ticking buff context: (optional) A dictionary you wish to pass to the at_tick method as kwargs - initial: (optional) Whether this tick_buff call is the first one. Starts True, changes to False for future ticks""" + initial: (optional) Whether this tick_buff call is the first one. Starts True, changes to False for future ticks + """ # Cache a reference and find the buff on the object if buffkey not in handler.buffcache.keys(): return diff --git a/evennia/contrib/rpg/dice/dice.py b/evennia/contrib/rpg/dice/dice.py index 33ce0ac741..5551ca7f64 100644 --- a/evennia/contrib/rpg/dice/dice.py +++ b/evennia/contrib/rpg/dice/dice.py @@ -302,8 +302,7 @@ class CmdDice(default_cmds.MuxCommand): except ValueError: self.caller.msg( "You need to enter valid integer numbers, modifiers and operators." - " |w%s|n was not understood." - % self.args + " |w%s|n was not understood." % self.args ) return # format output diff --git a/evennia/contrib/rpg/dice/tests.py b/evennia/contrib/rpg/dice/tests.py index 9283941514..ba5621b409 100644 --- a/evennia/contrib/rpg/dice/tests.py +++ b/evennia/contrib/rpg/dice/tests.py @@ -3,9 +3,10 @@ Testing of TestDice. """ -from evennia.commands.default.tests import BaseEvenniaCommandTest from mock import patch +from evennia.commands.default.tests import BaseEvenniaCommandTest + from . import dice diff --git a/evennia/contrib/rpg/llm/llm_client.py b/evennia/contrib/rpg/llm/llm_client.py index 3284d5c1ce..51fa4ea2c1 100644 --- a/evennia/contrib/rpg/llm/llm_client.py +++ b/evennia/contrib/rpg/llm/llm_client.py @@ -25,8 +25,6 @@ DEFAULT_LLM_REQUEST_BODY = {...} # see below, this controls how to prompt the import json from django.conf import settings -from evennia import logger -from evennia.utils.utils import make_iter from twisted.internet import defer, protocol, reactor from twisted.internet.defer import inlineCallbacks from twisted.web.client import Agent, HTTPConnectionPool, _HTTP11ClientFactory @@ -34,6 +32,9 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IBodyProducer from zope.interface import implementer +from evennia import logger +from evennia.utils.utils import make_iter + DEFAULT_LLM_HOST = "http://127.0.0.1:5000" DEFAULT_LLM_PATH = "/api/v1/generate" DEFAULT_LLM_HEADERS = {"Content-Type": "application/json"} diff --git a/evennia/contrib/rpg/llm/llm_npc.py b/evennia/contrib/rpg/llm/llm_npc.py index ad6c1caa1a..3fa118bd29 100644 --- a/evennia/contrib/rpg/llm/llm_npc.py +++ b/evennia/contrib/rpg/llm/llm_npc.py @@ -14,11 +14,12 @@ from collections import defaultdict from random import choice from django.conf import settings -from evennia import AttributeProperty, Command, DefaultCharacter -from evennia.utils.utils import make_iter from twisted.internet import reactor, task from twisted.internet.defer import CancelledError, inlineCallbacks +from evennia import AttributeProperty, Command, DefaultCharacter +from evennia.utils.utils import make_iter + from .llm_client import LLMClient # fallback if not specified anywhere else. Check order is diff --git a/evennia/contrib/rpg/llm/tests.py b/evennia/contrib/rpg/llm/tests.py index 0275cd8dc4..b37dfe94df 100644 --- a/evennia/contrib/rpg/llm/tests.py +++ b/evennia/contrib/rpg/llm/tests.py @@ -5,9 +5,10 @@ Unit tests for the LLM Client and npc. from anything import Something from django.test import override_settings +from mock import Mock, patch + from evennia.utils.create import create_object from evennia.utils.test_resources import EvenniaTestCase -from mock import Mock, patch from .llm_npc import LLMNPC diff --git a/evennia/contrib/rpg/rpsystem/rpsystem.py b/evennia/contrib/rpg/rpsystem/rpsystem.py index c17a7103f5..384259ee61 100644 --- a/evennia/contrib/rpg/rpsystem/rpsystem.py +++ b/evennia/contrib/rpg/rpsystem/rpsystem.py @@ -154,12 +154,18 @@ from string import punctuation import inflect from django.conf import settings + from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command from evennia.objects.models import ObjectDB from evennia.objects.objects import DefaultCharacter, DefaultObject from evennia.utils import ansi, logger -from evennia.utils.utils import iter_to_str, lazy_property, make_iter, variable_from_module +from evennia.utils.utils import ( + iter_to_str, + lazy_property, + make_iter, + variable_from_module, +) _INFLECT = inflect.engine() diff --git a/evennia/contrib/rpg/rpsystem/tests.py b/evennia/contrib/rpg/rpsystem/tests.py index 6f9390201c..f0378c7b71 100644 --- a/evennia/contrib/rpg/rpsystem/tests.py +++ b/evennia/contrib/rpg/rpsystem/tests.py @@ -5,6 +5,7 @@ Tests for RP system import time from anything import Anything + from evennia import create_object from evennia.commands.default.tests import BaseEvenniaCommandTest from evennia.utils.test_resources import BaseEvenniaTest @@ -329,7 +330,6 @@ class TestRPSystemCommands(BaseEvenniaCommandTest): self.char2.swap_typeclass(rpsystem.ContribRPCharacter) def test_commands(self): - self.call( rpsystem.CmdSdesc(), "Foobar Character", "Char's sdesc was set to 'Foobar Character'." ) diff --git a/evennia/contrib/tutorials/evadventure/chargen.py b/evennia/contrib/tutorials/evadventure/chargen.py index ab440d2f45..35b68a39b9 100644 --- a/evennia/contrib/tutorials/evadventure/chargen.py +++ b/evennia/contrib/tutorials/evadventure/chargen.py @@ -3,6 +3,7 @@ EvAdventure character generation. """ from django.conf import settings + from evennia.objects.models import ObjectDB from evennia.prototypes.spawner import spawn from evennia.utils.create import create_object diff --git a/evennia/contrib/tutorials/evadventure/combat_twitch.py b/evennia/contrib/tutorials/evadventure/combat_twitch.py index e9e0c8e6c3..787081fc28 100644 --- a/evennia/contrib/tutorials/evadventure/combat_twitch.py +++ b/evennia/contrib/tutorials/evadventure/combat_twitch.py @@ -8,7 +8,14 @@ This implements a 'twitch' (aka DIKU or other traditional muds) style of MUD com """ from evennia import AttributeProperty, CmdSet, default_cmds from evennia.commands.command import Command, InterruptCommand -from evennia.utils.utils import display_len, inherits_from, list_to_string, pad, repeat, unrepeat +from evennia.utils.utils import ( + display_len, + inherits_from, + list_to_string, + pad, + repeat, + unrepeat, +) from .characters import EvAdventureCharacter from .combat_base import ( diff --git a/evennia/contrib/tutorials/evadventure/rules.py b/evennia/contrib/tutorials/evadventure/rules.py index a714907bed..b0075b8e1f 100644 --- a/evennia/contrib/tutorials/evadventure/rules.py +++ b/evennia/contrib/tutorials/evadventure/rules.py @@ -316,11 +316,9 @@ class EvAdventureRollEngine: setattr(character, abi, current_abi) character.msg( - "~" * 78 - + "\n|yYou survive your brush with death, " + "~" * 78 + "\n|yYou survive your brush with death, " f"but are |r{result.upper()}|y and permanently |rlose {loss} {abi}|y.|n\n" - f"|GYou recover |g{new_hp}|G health|.\n" - + "~" * 78 + f"|GYou recover |g{new_hp}|G health|.\n" + "~" * 78 ) diff --git a/evennia/contrib/tutorials/evadventure/tests/test_chargen.py b/evennia/contrib/tutorials/evadventure/tests/test_chargen.py index 8e6ef351b0..f6eaf1461c 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_chargen.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_chargen.py @@ -43,7 +43,6 @@ class EvAdventureCharacterGenerationTest(BaseEvenniaTest): @patch("evennia.contrib.tutorials.evadventure.chargen.spawn") def test_apply(self, mock_spawn): - gambeson = create_object(objects.EvAdventureArmor, key="gambeson") mock_spawn.return_value = [gambeson] account = MagicMock() diff --git a/evennia/contrib/tutorials/evadventure/tests/test_combat.py b/evennia/contrib/tutorials/evadventure/tests/test_combat.py index 76c3ed0a46..ffea1ea4ba 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_combat.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_combat.py @@ -7,7 +7,11 @@ from unittest.mock import Mock, call, patch from evennia.utils import create from evennia.utils.ansi import strip_ansi -from evennia.utils.test_resources import BaseEvenniaTest, EvenniaCommandTestMixin, EvenniaTestCase +from evennia.utils.test_resources import ( + BaseEvenniaTest, + EvenniaCommandTestMixin, + EvenniaTestCase, +) from .. import combat_base, combat_turnbased, combat_twitch from ..characters import EvAdventureCharacter diff --git a/evennia/contrib/tutorials/evadventure/tests/test_commands.py b/evennia/contrib/tutorials/evadventure/tests/test_commands.py index f669665c9a..15aa73c3bd 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_commands.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_commands.py @@ -6,6 +6,7 @@ Test the EvAdventure commands. from unittest.mock import call, patch from anything import Something + from evennia.utils.create import create_object from evennia.utils.test_resources import BaseEvenniaCommandTest diff --git a/evennia/contrib/tutorials/evadventure/tests/test_utils.py b/evennia/contrib/tutorials/evadventure/tests/test_utils.py index 192e6b44f6..d0253e8ef7 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_utils.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_utils.py @@ -12,7 +12,6 @@ from ..objects import EvAdventureObject class TestUtils(BaseEvenniaTest): def test_get_obj_stats(self): - obj = create.create_object( EvAdventureObject, key="testobj", attributes=(("desc", "A test object"),) ) diff --git a/evennia/contrib/tutorials/tutorial_world/intro_menu.py b/evennia/contrib/tutorials/tutorial_world/intro_menu.py index 9e8548cc3c..331ea09bf5 100644 --- a/evennia/contrib/tutorials/tutorial_world/intro_menu.py +++ b/evennia/contrib/tutorials/tutorial_world/intro_menu.py @@ -748,7 +748,6 @@ class TutorialEvMenu(EvMenu): self.caller.account.execute_cmd("unquell") def options_formatter(self, optionslist): - navigation_keys = ("next", "back", "back to start") other = [] diff --git a/evennia/help/utils.py b/evennia/help/utils.py index d7ea8f311c..7cd551393e 100644 --- a/evennia/help/utils.py +++ b/evennia/help/utils.py @@ -190,7 +190,6 @@ def parse_entry_for_subcategories(entry): # from evennia import set_trace;set_trace() for part in _RE_HELP_SUBTOPIC_SPLIT.split(subtopics.strip()): - subtopic_match = _RE_HELP_SUBTOPIC_PARSE.match(part.strip()) if subtopic_match: # a new sub(-sub..) category starts. diff --git a/evennia/locks/lockfuncs.py b/evennia/locks/lockfuncs.py index f6e67644ef..bf407fc821 100644 --- a/evennia/locks/lockfuncs.py +++ b/evennia/locks/lockfuncs.py @@ -17,6 +17,7 @@ a certain object type. from ast import literal_eval from django.conf import settings + from evennia.utils import utils _PERMISSION_HIERARCHY = [pe.lower() for pe in settings.PERMISSION_HIERARCHY] diff --git a/evennia/objects/manager.py b/evennia/objects/manager.py index 2957e6aa42..576312ce1b 100644 --- a/evennia/objects/manager.py +++ b/evennia/objects/manager.py @@ -451,7 +451,6 @@ class ObjectDBManager(TypedObjectManager): return query if not searchdata and searchdata != 0: - if tags: return _search_by_tag(make_iter(tags)) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index f8f98b552c..c710e96498 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -10,10 +10,11 @@ This is the v1.0 develop version (for ref in doc building). import time from collections import defaultdict -import evennia import inflect from django.conf import settings from django.utils.translation import gettext as _ + +import evennia from evennia.commands import cmdset from evennia.commands.cmdsethandler import CmdSetHandler from evennia.objects.manager import ObjectManager diff --git a/evennia/prototypes/menus.py b/evennia/prototypes/menus.py index 00c7f67e06..d7644b3f9d 100644 --- a/evennia/prototypes/menus.py +++ b/evennia/prototypes/menus.py @@ -462,7 +462,6 @@ def _search_object(caller): is_account = searchstring.startswith("*") if is_dbref or is_account: - if is_dbref: # a dbref search results = caller.search(searchstring, global_search=True, quiet=True) @@ -508,14 +507,12 @@ def _object_search_actions(caller, raw_inp, **kwargs): raw_inp = raw_inp.strip() if obj_entry: - num = choices.index(obj_entry) matches = caller.ndb._menutree.olc_search_object_matches obj = matches[num] prot = spawner.prototype_from_object(obj) if action == "examine": - if not obj.access(caller, "examine"): caller.msg("\n|rYou don't have 'examine' access on this object.|n") del caller.ndb._menutree.olc_search_object_term @@ -738,7 +735,6 @@ def _check_prototype_key(caller, key): def node_prototype_key(caller): - text = """ The |cPrototype-Key|n uniquely identifies the prototype and is |wmandatory|n. It is used to find and use the prototype to spawn new entities. It is not case sensitive. @@ -840,7 +836,6 @@ def _prototype_parent_actions(caller, raw_inp, **kwargs): def _prototype_parent_select(caller, new_parent): - ret = None prototype_parent = protlib.search_prototype(new_parent) try: @@ -1090,7 +1085,6 @@ def _aliases_actions(caller, raw_inp, **kwargs): @list_node(_all_aliases, _aliases_select) def node_aliases(caller): - text = """ |cAliases|n are alternative ways to address an object, next to its |cKey|n. Aliases are not case sensitive. @@ -1393,7 +1387,6 @@ def _add_tag(caller, tag_string, **kwargs): old_tag = _get_tup_by_tagname(caller, tag) if "delete" in kwargs: - if old_tag: tags.pop(tags.index(old_tag)) text = "Removed Tag '{}'.".format(tag) @@ -1745,7 +1738,6 @@ def node_permissions(caller): def node_location(caller): - text = """ The |cLocation|n of this object in the world. If not given, the object will spawn in the inventory of |c{caller}|n by default. @@ -1782,7 +1774,6 @@ def node_location(caller): def node_home(caller): - text = """ The |cHome|n location of an object is often only used as a backup - this is where the object will be moved to if its location is deleted. The home location can also be used as an actual @@ -1823,7 +1814,6 @@ def node_home(caller): def node_destination(caller): - text = """ The object's |cDestination|n is generally only used by Exit-like objects to designate where the exit 'leads to'. It's usually unset for all other types of objects. @@ -1859,7 +1849,6 @@ def node_destination(caller): def node_prototype_desc(caller): - text = """ The |cPrototype-Description|n briefly describes the prototype when it's viewed in listings. @@ -1967,7 +1956,6 @@ def _prototype_tags_actions(caller, raw_inp, **kwargs): @list_node(_caller_prototype_tags, _prototype_tag_select) def node_prototype_tags(caller): - text = """ |cPrototype-Tags|n can be used to classify and find prototypes in listings Tag names are not case-sensitive and can have not have a custom category. @@ -2067,7 +2055,6 @@ def _prototype_locks_actions(caller, raw_inp, **kwargs): @list_node(_caller_prototype_locks, _prototype_lock_select) def node_prototype_locks(caller): - text = """ |cPrototype-Locks|n are used to limit access to this prototype when someone else is trying to access it. By default any prototype can be edited only by the creator and by Admins while @@ -2608,7 +2595,6 @@ def _prototype_load_actions(caller, raw_inp, **kwargs): ) if prototype: - # which action to apply on the selection if action == "examine": # examine the prototype diff --git a/evennia/prototypes/prototypes.py b/evennia/prototypes/prototypes.py index 1a2b50b35f..e6441ba137 100644 --- a/evennia/prototypes/prototypes.py +++ b/evennia/prototypes/prototypes.py @@ -12,6 +12,7 @@ from django.conf import settings from django.core.paginator import Paginator from django.db.models import Q from django.utils.translation import gettext as _ + from evennia.locks.lockhandler import check_lockstring, validate_lockstring from evennia.objects.models import ObjectDB from evennia.scripts.scripts import DefaultScript diff --git a/evennia/prototypes/spawner.py b/evennia/prototypes/spawner.py index a21077119d..20a39bf4ac 100644 --- a/evennia/prototypes/spawner.py +++ b/evennia/prototypes/spawner.py @@ -137,9 +137,10 @@ import copy import hashlib import time -import evennia from django.conf import settings from django.utils.translation import gettext as _ + +import evennia from evennia.objects.models import ObjectDB from evennia.prototypes import prototypes as protlib from evennia.prototypes.prototypes import ( @@ -396,7 +397,6 @@ def prototype_diff(prototype1, prototype2, maxdepth=2, homogenize=False, implici _unset = Unset() def _recursive_diff(old, new, depth=0): - old_type = type(old) new_type = type(new) @@ -693,7 +693,6 @@ def batch_update_objects_with_prototype( try: for key, directive in diff.items(): - if key not in new_prototype and not exact: # we don't update the object if the prototype does not actually # contain the key (the diff will report REMOVE but we ignore it @@ -701,7 +700,6 @@ def batch_update_objects_with_prototype( continue if directive in ("UPDATE", "REPLACE"): - if key in _PROTOTYPE_META_NAMES: # prototype meta keys are not stored on-object continue @@ -855,7 +853,6 @@ def batch_create_object(*objparams): objs = [] for objparam in objparams: - obj = ObjectDB(**objparam[0]) # setup @@ -930,7 +927,6 @@ def spawn(*prototypes, caller=None, **kwargs): objsparams = [] for prototype in prototypes: - # run validation and homogenization of provided prototypes protlib.validate_prototype( prototype, None, protparents=custom_protparents, is_prototype_base=True @@ -996,7 +992,7 @@ def spawn(*prototypes, caller=None, **kwargs): val = prot.pop("tags", []) tags = [] - for (tag, category, *data) in val: + for tag, category, *data in val: tags.append( ( init_spawn_value(tag, str, **init_spawn_kwargs), @@ -1026,7 +1022,7 @@ def spawn(*prototypes, caller=None, **kwargs): # the rest are attribute tuples (attrname, value, category, locks) val = make_iter(prot.pop("attrs", [])) attributes = [] - for (attrname, value, *rest) in val: + for attrname, value, *rest in val: attributes.append( ( attrname, diff --git a/evennia/prototypes/tests.py b/evennia/prototypes/tests.py index c7cc8fbbbc..4a0b1d1a1b 100644 --- a/evennia/prototypes/tests.py +++ b/evennia/prototypes/tests.py @@ -10,6 +10,7 @@ from time import time import mock from anything import Something from django.test.utils import override_settings + from evennia.commands.default import building from evennia.objects.models import ObjectDB from evennia.prototypes import menus as olc_menus @@ -135,7 +136,6 @@ class TestUtils(BaseEvenniaTest): ) def test_update_objects_from_prototypes(self): - self.maxDiff = None self.obj1.attributes.add("oldtest", "to_keep") @@ -438,7 +438,6 @@ class TestPrototypeStorage(BaseEvenniaTest): self.prot3["prototype_tags"] = [("foo1", _PROTOTYPE_TAG_META_CATEGORY)] def test_prototype_storage(self): - # from evennia import set_trace;set_trace(term_size=(180, 50)) prot1 = protlib.create_prototype(self.prot1) @@ -500,7 +499,6 @@ class _MockMenu(object): class TestMenuModule(BaseEvenniaTest): - maxDiff = None def setUp(self): @@ -518,7 +516,6 @@ class TestMenuModule(BaseEvenniaTest): } def test_helpers(self): - caller = self.caller # general helpers @@ -579,7 +576,6 @@ class TestMenuModule(BaseEvenniaTest): self.assertEqual(olc_menus._default_parse("f5", choices, *actions), (None, None)) def test_node_helpers(self): - caller = self.caller with mock.patch( @@ -820,7 +816,6 @@ class TestMenuModule(BaseEvenniaTest): new=mock.MagicMock(return_value={"TypeclassTest": None}), ) class TestOLCMenu(TestEvMenu): - maxDiff = None menutree = "evennia.prototypes.menus" startnode = "node_index" @@ -941,7 +936,6 @@ class TestOLCMenu(TestEvMenu): class PrototypeCrashTest(BaseEvenniaTest): - # increase this to 1000 for optimization testing num_prototypes = 10 @@ -1038,7 +1032,6 @@ class TestIssue2908(BaseEvenniaTest): """ def test_spawn_with_protfunc(self): - self.room1.tags.add("beach", category="zone") prot = { diff --git a/evennia/scripts/manager.py b/evennia/scripts/manager.py index c42866aa9e..b0a57df162 100644 --- a/evennia/scripts/manager.py +++ b/evennia/scripts/manager.py @@ -4,6 +4,7 @@ The custom manager for Scripts. from django.conf import settings from django.db.models import Q + from evennia.server import signals from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager from evennia.utils.utils import class_from_module, dbid_to_obj, make_iter diff --git a/evennia/scripts/monitorhandler.py b/evennia/scripts/monitorhandler.py index ea3808826e..07e9d04f25 100644 --- a/evennia/scripts/monitorhandler.py +++ b/evennia/scripts/monitorhandler.py @@ -73,7 +73,7 @@ class MonitorHandler(object): restored_monitors = ServerConfig.objects.conf(key=self.savekey) if restored_monitors: restored_monitors = dbunserialize(restored_monitors) - for (obj, fieldname, idstring, path, persistent, kwargs) in restored_monitors: + for obj, fieldname, idstring, path, persistent, kwargs in restored_monitors: try: if not server_reload and not persistent: # this monitor will not be restarted @@ -120,7 +120,7 @@ class MonitorHandler(object): to_delete.append((obj, fieldname, idstring)) logger.log_trace("Monitor callback was removed.") # we cleanup non-found monitors (has to be done after loop) - for (obj, fieldname, idstring) in to_delete: + for obj, fieldname, idstring in to_delete: del self.monitors[obj][fieldname][idstring] def add(self, obj, fieldname, callback, idstring="", persistent=False, category=None, **kwargs): diff --git a/evennia/scripts/scripthandler.py b/evennia/scripts/scripthandler.py index 553834b911..8b8eb4bb45 100644 --- a/evennia/scripts/scripthandler.py +++ b/evennia/scripts/scripthandler.py @@ -6,6 +6,7 @@ added to all game objects. You access it through the property """ from django.utils.translation import gettext as _ + from evennia.scripts.models import ScriptDB from evennia.utils import create, logger diff --git a/evennia/scripts/scripts.py b/evennia/scripts/scripts.py index fcf2c76f29..c4417af3ad 100644 --- a/evennia/scripts/scripts.py +++ b/evennia/scripts/scripts.py @@ -6,12 +6,13 @@ ability to run timers. """ from django.utils.translation import gettext as _ +from twisted.internet.defer import Deferred, maybeDeferred +from twisted.internet.task import LoopingCall + from evennia.scripts.manager import ScriptManager from evennia.scripts.models import ScriptDB from evennia.typeclasses.models import TypeclassBase from evennia.utils import create, logger -from twisted.internet.defer import Deferred, maybeDeferred -from twisted.internet.task import LoopingCall __all__ = ["DefaultScript", "DoNothing", "Store"] diff --git a/evennia/scripts/tests.py b/evennia/scripts/tests.py index eb5f205d13..11492ef43e 100644 --- a/evennia/scripts/tests.py +++ b/evennia/scripts/tests.py @@ -6,6 +6,8 @@ Unit tests for the scripts package from collections import defaultdict from unittest import TestCase, mock +from parameterized import parameterized + from evennia import DefaultScript from evennia.objects.objects import DefaultObject from evennia.scripts.manager import ScriptDBManager @@ -16,7 +18,6 @@ from evennia.scripts.tickerhandler import TickerHandler from evennia.utils.create import create_script from evennia.utils.dbserialize import dbserialize from evennia.utils.test_resources import BaseEvenniaTest -from parameterized import parameterized class TestScript(BaseEvenniaTest): diff --git a/evennia/server/connection_wizard.py b/evennia/server/connection_wizard.py index c672804d69..2b17c9786b 100644 --- a/evennia/server/connection_wizard.py +++ b/evennia/server/connection_wizard.py @@ -217,7 +217,6 @@ def node_game_index_start(wizard, **kwargs): def node_game_index_fields(wizard, status=None): - # reset the listing if needed if not hasattr(wizard, "game_index_listing"): wizard.game_index_listing = settings.GAME_INDEX_LISTING @@ -420,7 +419,6 @@ def node_game_index_fields(wizard, status=None): def node_mssp_start(wizard): - mssp_module = mod_import(settings.MSSP_META_MODULE or "server.conf.mssp") try: filename = mssp_module.__file__ diff --git a/evennia/server/game_index_client/client.py b/evennia/server/game_index_client/client.py index 38d37cb157..02b9241379 100644 --- a/evennia/server/game_index_client/client.py +++ b/evennia/server/game_index_client/client.py @@ -8,10 +8,7 @@ import urllib.parse import urllib.request import django -import evennia from django.conf import settings -from evennia.accounts.models import AccountDB -from evennia.utils import get_evennia_version, logger from twisted.internet import defer, protocol, reactor from twisted.internet.defer import inlineCallbacks from twisted.web.client import Agent, HTTPConnectionPool, _HTTP11ClientFactory @@ -19,6 +16,10 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IBodyProducer from zope.interface import implementer +import evennia +from evennia.accounts.models import AccountDB +from evennia.utils import get_evennia_version, logger + _EGI_HOST = "http://evennia-game-index.appspot.com" _EGI_REPORT_PATH = "/api/v1/game/check_in" diff --git a/evennia/server/portal/discord.py b/evennia/server/portal/discord.py index babae8a495..e38c08aea9 100644 --- a/evennia/server/portal/discord.py +++ b/evennia/server/portal/discord.py @@ -353,9 +353,9 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS): url = f"{DISCORD_API_BASE_URL}/{url}" body = FileBodyProducer(BytesIO(json.dumps(data).encode("utf-8"))) request_type = kwargs.pop("type", "POST") - + d = _AGENT.request( - request_type.encode("utf-8"), + request_type.encode("utf-8"), url.encode("utf-8"), Headers( { @@ -501,7 +501,6 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS): self._post_json(f"guilds/{guild_id}/members/{user_id}", data, type="PATCH") def send_role(self, role_id, guild_id, user_id, **kwargs): - data = kwargs self._post_json(f"guilds/{guild_id}/members/{user_id}/roles/{role_id}", data, type="PUT") @@ -570,4 +569,4 @@ class DiscordClient(WebSocketClientProtocol, _BASE_SESSION_CLASS): # send the data for any other action types on to the bot as-is for optional server-side handling keywords = {"type": action_type} keywords.update(data["d"]) - self.sessionhandler.data_in(self, bot_data_in=("", keywords)) \ No newline at end of file + self.sessionhandler.data_in(self, bot_data_in=("", keywords)) diff --git a/evennia/server/portal/grapevine.py b/evennia/server/portal/grapevine.py index 11060129f4..b9eba92c57 100644 --- a/evennia/server/portal/grapevine.py +++ b/evennia/server/portal/grapevine.py @@ -47,7 +47,6 @@ class RestartingWebsocketServerFactory(WebSocketClientFactory, protocol.Reconnec maxDelay = 60 def __init__(self, sessionhandler, *args, **kwargs): - self.uid = kwargs.pop("uid") self.channel = kwargs.pop("grapevine_channel") self.sessionhandler = sessionhandler diff --git a/evennia/server/portal/portal.py b/evennia/server/portal/portal.py index 87077b0ac7..cfff662c4c 100644 --- a/evennia/server/portal/portal.py +++ b/evennia/server/portal/portal.py @@ -26,7 +26,6 @@ import evennia evennia._init(portal_mode=True) from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS - from evennia.server.webserver import EvenniaReverseProxyResource from evennia.utils import logger from evennia.utils.utils import ( @@ -264,11 +263,9 @@ if "--nodaemon" not in sys.argv and "test" not in sys.argv: PORTAL = Portal(application) if LOCKDOWN_MODE: - INFO_DICT["lockdown_mode"] = " LOCKDOWN_MODE active: Only local connections." if AMP_ENABLED: - # The AMP protocol handles the communication between # the portal and the mud server. Only reason to ever deactivate # it would be during testing and debugging. @@ -287,7 +284,6 @@ if AMP_ENABLED: # These will gradually be started as they are initialized below. if TELNET_ENABLED: - # Start telnet game connections from evennia.server.portal import telnet @@ -312,7 +308,6 @@ if TELNET_ENABLED: if SSL_ENABLED: - # Start Telnet+SSL game connection (requires PyOpenSSL). from evennia.server.portal import telnet_ssl @@ -346,7 +341,6 @@ if SSL_ENABLED: if SSH_ENABLED: - # Start SSH game connections. Will create a keypair in # evennia/game if necessary. diff --git a/evennia/server/portal/ssh.py b/evennia/server/portal/ssh.py index 9da30e1c88..966d065be9 100644 --- a/evennia/server/portal/ssh.py +++ b/evennia/server/portal/ssh.py @@ -342,7 +342,6 @@ class SshProtocol(Manhole, _BASE_SESSION_CLASS): class ExtraInfoAuthServer(SSHUserAuthServer): - noisy = False def auth_password(self, packet): diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 98a095833c..cb577f3835 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -10,11 +10,6 @@ sessions etc. import re from django.conf import settings -from evennia.server.portal import mssp, naws, suppress_ga, telnet_oob, ttype -from evennia.server.portal.mccp import MCCP, Mccp, mccp_compress -from evennia.server.portal.mxp import Mxp, mxp_parse -from evennia.utils import ansi -from evennia.utils.utils import class_from_module, to_bytes from twisted.conch.telnet import ( ECHO, GA, @@ -33,6 +28,12 @@ from twisted.conch.telnet import ( from twisted.internet import protocol from twisted.internet.task import LoopingCall +from evennia.server.portal import mssp, naws, suppress_ga, telnet_oob, ttype +from evennia.server.portal.mccp import MCCP, Mccp, mccp_compress +from evennia.server.portal.mxp import Mxp, mxp_parse +from evennia.utils import ansi +from evennia.utils.utils import class_from_module, to_bytes + _RE_N = re.compile(r"\|n$") _RE_LEND = re.compile(rb"\n$|\r$|\r\n$|\r\x00$|", re.MULTILINE) _RE_LINEBREAK = re.compile(rb"\n\r|\r\n|\n|\r", re.DOTALL + re.MULTILINE) diff --git a/evennia/server/portal/telnet_ssl.py b/evennia/server/portal/telnet_ssl.py index 60202cce7a..46717c0a61 100644 --- a/evennia/server/portal/telnet_ssl.py +++ b/evennia/server/portal/telnet_ssl.py @@ -103,7 +103,6 @@ def verify_or_create_SSL_key_and_cert(keyfile, certfile): return False else: - try: # create certificate cert = crypto.X509() diff --git a/evennia/server/profiling/dummyrunner.py b/evennia/server/profiling/dummyrunner.py index 650090e132..da7c9f43b2 100644 --- a/evennia/server/profiling/dummyrunner.py +++ b/evennia/server/profiling/dummyrunner.py @@ -600,7 +600,6 @@ def start_all_dummy_clients(nclients): if __name__ == "__main__": - try: settings.DUMMYRUNNER_MIXIN except AttributeError: diff --git a/evennia/server/profiling/memplot.py b/evennia/server/profiling/memplot.py index 3f2d56dd5d..42e2754d83 100644 --- a/evennia/server/profiling/memplot.py +++ b/evennia/server/profiling/memplot.py @@ -53,7 +53,6 @@ class Memplot(evennia.DefaultScript): if __name__ == "__main__": - # plot output from the file import numpy diff --git a/evennia/server/profiling/test_queries.py b/evennia/server/profiling/test_queries.py index ce3b9af660..bfeb28b0bf 100644 --- a/evennia/server/profiling/test_queries.py +++ b/evennia/server/profiling/test_queries.py @@ -30,7 +30,6 @@ def count_queries(exec_string, setup_string): if __name__ == "__main__": - # setup tests here setup_string = """ diff --git a/evennia/server/server.py b/evennia/server/server.py index 1491550cfc..bce588f733 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -31,6 +31,7 @@ from django.conf import settings from django.db import connection from django.db.utils import OperationalError from django.utils.translation import gettext as _ + from evennia.accounts.models import AccountDB from evennia.scripts.models import ScriptDB from evennia.server.models import ServerConfig diff --git a/evennia/server/serversession.py b/evennia/server/serversession.py index 1ea0778f97..2836609c57 100644 --- a/evennia/server/serversession.py +++ b/evennia/server/serversession.py @@ -10,10 +10,15 @@ import time from django.conf import settings from django.utils import timezone + from evennia.commands.cmdsethandler import CmdSetHandler from evennia.comms.models import ChannelDB from evennia.scripts.monitorhandler import MONITOR_HANDLER -from evennia.typeclasses.attributes import AttributeHandler, DbHolder, InMemoryAttributeBackend +from evennia.typeclasses.attributes import ( + AttributeHandler, + DbHolder, + InMemoryAttributeBackend, +) from evennia.utils import logger from evennia.utils.utils import class_from_module, lazy_property, make_iter @@ -444,4 +449,3 @@ class ServerSession(_BASE_SESSION_CLASS): return self.account.get_display_name(*args, **kwargs) else: return f"{self.protocol_key}({self.address})" - diff --git a/evennia/server/signals.py b/evennia/server/signals.py index bb87d62f6b..6bf8b1a968 100644 --- a/evennia/server/signals.py +++ b/evennia/server/signals.py @@ -95,9 +95,9 @@ SIGNAL_EXIT_TRAVERSED = Signal() from django.core.signals import request_finished # " ends. from django.core.signals import request_started # Sent when HTTP request begins. -from django.db.backends.signals import ( +from django.db.backends.signals import ( # Sent when making initial connection to database connection_created, -) # Sent when making initial connection to database +) from django.db.models.signals import m2m_changed # Sent when a ManyToManyField changes. from django.db.models.signals import post_delete # after " from django.db.models.signals import post_init # end @@ -105,9 +105,15 @@ from django.db.models.signals import post_migrate # after " from django.db.models.signals import post_save # after " from django.db.models.signals import pre_delete # Sent before an object is deleted. from django.db.models.signals import pre_migrate # Sent before migration starts -from django.db.models.signals import pre_save # Sent before a typeclass' .save is called. from django.db.models.signals import ( + pre_save, # Sent before a typeclass' .save is called. +) +from django.db.models.signals import ( # Sent at start of typeclass __init__ (before at_init) pre_init, -) # Sent at start of typeclass __init__ (before at_init) -from django.test.signals import setting_changed # Sent when setting changes from override -from django.test.signals import template_rendered # Sent when test system renders template +) +from django.test.signals import ( + setting_changed, # Sent when setting changes from override +) +from django.test.signals import ( + template_rendered, # Sent when test system renders template +) diff --git a/evennia/server/tests/test_amp_connection.py b/evennia/server/tests/test_amp_connection.py index dbf3f83d03..05e9e82017 100644 --- a/evennia/server/tests/test_amp_connection.py +++ b/evennia/server/tests/test_amp_connection.py @@ -17,6 +17,7 @@ from evennia.utils import create DelayedCall.debug = True + # @patch("evennia.server.initial_setup.get_god_account", # MagicMock(return_value=create.account("TestAMPAccount", "test@test.com", "testpassword"))) class _TestAMP(TwistedTestCase): diff --git a/evennia/server/tests/test_server.py b/evennia/server/tests/test_server.py index ca53cd5d65..a5b62ccf93 100644 --- a/evennia/server/tests/test_server.py +++ b/evennia/server/tests/test_server.py @@ -116,7 +116,6 @@ class TestServer(TestCase): def test_evennia_start(self): with patch.multiple("evennia.server.server", time=DEFAULT, service=DEFAULT) as mocks: - mocks["time"].time = MagicMock(return_value=1000) evennia = self.server.Evennia(MagicMock()) self.assertEqual(evennia.start_time, 1000) @@ -127,7 +126,6 @@ class TestServer(TestCase): @patch("evennia.comms.models.ChannelDB") def test_update_defaults(self, mockchan, mockscript, mockacct, mockobj): with patch.multiple("evennia.server.server", ServerConfig=DEFAULT) as mocks: - mockchan.objects.filter = MagicMock() mockscript.objects.filter = MagicMock() mockacct.objects.filter = MagicMock() @@ -199,7 +197,6 @@ class TestServer(TestCase): class TestInitHooks(TestCase): def setUp(self): - from evennia.server import server from evennia.utils import create @@ -235,7 +232,6 @@ class TestInitHooks(TestCase): @override_settings(_TEST_ENVIRONMENT=True) def test_run_init_hooks(self): - evennia = self.server.Evennia(MagicMock()) evennia.at_server_reload_start = MagicMock() diff --git a/evennia/server/tests/testrunner.py b/evennia/server/tests/testrunner.py index 1d6b63fa85..9d9f8b9265 100644 --- a/evennia/server/tests/testrunner.py +++ b/evennia/server/tests/testrunner.py @@ -38,7 +38,6 @@ class EvenniaTestSuiteRunner(DiscoverRunner): super().setup_test_environment(**kwargs) def teardown_test_environment(self, **kwargs): - # remove testing flag after suite has run from django.conf import settings diff --git a/evennia/server/validators.py b/evennia/server/validators.py index 234a52fbef..1a48e87732 100644 --- a/evennia/server/validators.py +++ b/evennia/server/validators.py @@ -3,6 +3,7 @@ import re from django.conf import settings from django.core.exceptions import ValidationError from django.utils.translation import gettext as _ + from evennia.accounts.models import AccountDB diff --git a/evennia/settings_default.py b/evennia/settings_default.py index c9f171d107..3ec5f55776 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -1036,17 +1036,17 @@ MIDDLEWARE = [ # A list of Django apps (see INSTALLED_APPS) that will be listed first (if present) # in the Django web Admin page. DJANGO_ADMIN_APP_ORDER = [ - "accounts", - "objects", - "scripts", - "comms", - "help", - "typeclasses", - "server", - "sites", - "flatpages", - "auth", - ] + "accounts", + "objects", + "scripts", + "comms", + "help", + "typeclasses", + "server", + "sites", + "flatpages", + "auth", +] # The following apps will be excluded from the Django web Admin page. DJANGO_ADMIN_APP_EXCLUDE = list() diff --git a/evennia/typeclasses/attributes.py b/evennia/typeclasses/attributes.py index d65b73b661..ac274614b0 100644 --- a/evennia/typeclasses/attributes.py +++ b/evennia/typeclasses/attributes.py @@ -15,6 +15,7 @@ from collections import defaultdict from django.conf import settings from django.db import models from django.utils.encoding import smart_str + from evennia.locks.lockhandler import LockHandler from evennia.utils.dbserialize import from_pickle, to_pickle from evennia.utils.idmapper.models import SharedMemoryModel diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index 5fe225dabe..61d68d4693 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -34,6 +34,7 @@ from django.db.models.base import ModelBase from django.urls import reverse from django.utils.encoding import smart_str from django.utils.text import slugify + from evennia.locks.lockhandler import LockHandler from evennia.server.signals import SIGNAL_TYPED_OBJECT_POST_RENAME from evennia.typeclasses import managers @@ -626,8 +627,7 @@ class TypedObject(SharedMemoryModel): raise RuntimeError( "Cannot use swap_typeclass on time-dependent " "Script '%s'.\nStop and start a new Script of the " - "right type instead." - % self.key + "right type instead." % self.key ) self.typeclass_path = new_typeclass.path diff --git a/evennia/typeclasses/tags.py b/evennia/typeclasses/tags.py index a8054e17d3..ed23d73708 100644 --- a/evennia/typeclasses/tags.py +++ b/evennia/typeclasses/tags.py @@ -13,6 +13,7 @@ from collections import defaultdict from django.conf import settings from django.db import models + from evennia.locks.lockfuncs import perm as perm_lockfunc from evennia.utils.utils import make_iter, to_str diff --git a/evennia/typeclasses/tests.py b/evennia/typeclasses/tests.py index d8a0c47f55..f76344feab 100644 --- a/evennia/typeclasses/tests.py +++ b/evennia/typeclasses/tests.py @@ -4,11 +4,12 @@ Unit tests for typeclass base system """ from django.test import override_settings -from evennia.objects.objects import DefaultObject -from evennia.utils.test_resources import BaseEvenniaTest, EvenniaTestCase from mock import patch from parameterized import parameterized +from evennia.objects.objects import DefaultObject +from evennia.utils.test_resources import BaseEvenniaTest, EvenniaTestCase + # ------------------------------------------------------------ # Manager tests # ------------------------------------------------------------ diff --git a/evennia/utils/ansi.py b/evennia/utils/ansi.py index c68dc18469..2cc03f4aec 100644 --- a/evennia/utils/ansi.py +++ b/evennia/utils/ansi.py @@ -335,7 +335,6 @@ class ANSIParser(object): red, green, blue = gray, gray, gray if use_xterm256: - if not grayscale: colval = 16 + (red * 36) + (green * 6) + blue @@ -347,56 +346,55 @@ class ANSIParser(object): else: # xterm256 not supported, convert the rgb value to ansi instead rgb = (red, green, blue) - + def _convert_for_ansi(val): - return int((val+1)//2) + return int((val + 1) // 2) # greys if (max(rgb) - min(rgb)) <= 1: match rgb: - case (0,0,0): + case (0, 0, 0): return ANSI_BACK_BLACK if background else ANSI_NORMAL + ANSI_BLACK - case ((1|2), (1|2), (1|2)): + case ((1 | 2), (1 | 2), (1 | 2)): return ANSI_BACK_BLACK if background else ANSI_HILITE + ANSI_BLACK - case ((2|3), (2|3), (2|3)): + case ((2 | 3), (2 | 3), (2 | 3)): return ANSI_BACK_WHITE if background else ANSI_NORMAL + ANSI_WHITE - case ((3|4), (3|4), (3|4)): + case ((3 | 4), (3 | 4), (3 | 4)): return ANSI_BACK_WHITE if background else ANSI_NORMAL + ANSI_WHITE - case ((4|5), (4|5), (4|5)): + case ((4 | 5), (4 | 5), (4 | 5)): return ANSI_BACK_WHITE if background else ANSI_HILITE + ANSI_WHITE match tuple(_convert_for_ansi(c) for c in rgb): # red - case ((2|3), (0|1), (0|1)): + case ((2 | 3), (0 | 1), (0 | 1)): return ANSI_BACK_RED if background else ANSI_HILITE + ANSI_RED - case ((1|2), 0, 0): + case ((1 | 2), 0, 0): return ANSI_BACK_RED if background else ANSI_NORMAL + ANSI_RED # green - case ((0|1), (2|3), (0|1)): + case ((0 | 1), (2 | 3), (0 | 1)): return ANSI_BACK_GREEN if background else ANSI_HILITE + ANSI_GREEN case ((0 | 1), 1, 0) if green > red: return ANSI_BACK_GREEN if background else ANSI_NORMAL + ANSI_GREEN # blue - case ((0|1), (0|1), (2|3)): + case ((0 | 1), (0 | 1), (2 | 3)): return ANSI_BACK_BLUE if background else ANSI_HILITE + ANSI_BLUE case (0, 0, 1): return ANSI_BACK_BLUE if background else ANSI_NORMAL + ANSI_BLUE # cyan - case ((0|1|2), (2|3), (2|3)) if red == min(rgb): + case ((0 | 1 | 2), (2 | 3), (2 | 3)) if red == min(rgb): return ANSI_BACK_CYAN if background else ANSI_HILITE + ANSI_CYAN - case (0, (1|2), (1|2)): + case (0, (1 | 2), (1 | 2)): return ANSI_BACK_CYAN if background else ANSI_NORMAL + ANSI_CYAN # yellow - case ((2|3), (2|3), (0|1|2)) if blue == min(rgb): + case ((2 | 3), (2 | 3), (0 | 1 | 2)) if blue == min(rgb): return ANSI_BACK_YELLOW if background else ANSI_HILITE + ANSI_YELLOW - case ((2|1), (2|1), (0|1)): + case ((2 | 1), (2 | 1), (0 | 1)): return ANSI_BACK_YELLOW if background else ANSI_NORMAL + ANSI_YELLOW # magenta - case ((2|3), (0|1|2), (2|3)) if green == min(rgb): + case ((2 | 3), (0 | 1 | 2), (2 | 3)) if green == min(rgb): return ANSI_BACK_MAGENTA if background else ANSI_HILITE + ANSI_MAGENTA - case ((1|2), 0, (1|2)): + case ((1 | 2), 0, (1 | 2)): return ANSI_BACK_MAGENTA if background else ANSI_NORMAL + ANSI_MAGENTA - def strip_raw_codes(self, string): """ diff --git a/evennia/utils/dbserialize.py b/evennia/utils/dbserialize.py index e6ff52ded4..2d59f9b803 100644 --- a/evennia/utils/dbserialize.py +++ b/evennia/utils/dbserialize.py @@ -30,6 +30,7 @@ except ImportError: from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.utils.safestring import SafeString + import evennia from evennia.utils import logger from evennia.utils.utils import is_iter, to_bytes, uses_database @@ -130,6 +131,7 @@ def _init_globals(): _TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None) _IGNORE_DATETIME_MODELS.append(src_key) + # # SaverList, SaverDict, SaverSet - Attribute-specific helper classes and functions # diff --git a/evennia/utils/evform.py b/evennia/utils/evform.py index 111c8b8722..c71a8f0670 100644 --- a/evennia/utils/evform.py +++ b/evennia/utils/evform.py @@ -431,8 +431,7 @@ class EvForm: return rects # Map EvCells into form rectangles - for (key, y, x, width, height) in _get_rectangles(formchar): - + for key, y, x, width, height in _get_rectangles(formchar): # get data to populate cell data = self.cells_mapping.get(key, "") if isinstance(data, EvCell): @@ -455,8 +454,7 @@ class EvForm: mapping[key] = (y, x, width, height, cell) # Map EvTables into form rectangles - for (key, y, x, width, height) in _get_rectangles(tablechar): - + for key, y, x, width, height in _get_rectangles(tablechar): # get EvTable from mapping table = self.tables_mapping.get(key, None) @@ -479,7 +477,6 @@ class EvForm: mapping = self.mapping for key, (y, x, width, height, cell_or_table) in mapping.items(): - # rect is a list of lines, each wide rect = cell_or_table.get() for il, rectline in enumerate(rect): diff --git a/evennia/utils/evmenu.py b/evennia/utils/evmenu.py index 4e8a2004ff..cbf2cf45fe 100644 --- a/evennia/utils/evmenu.py +++ b/evennia/utils/evmenu.py @@ -276,12 +276,22 @@ from django.conf import settings # i18n from django.utils.translation import gettext as _ + from evennia import CmdSet, Command from evennia.commands import cmdhandler from evennia.utils import logger from evennia.utils.ansi import strip_ansi from evennia.utils.evtable import EvColumn, EvTable -from evennia.utils.utils import crop, dedent, is_iter, m_len, make_iter, mod_import, pad, to_str +from evennia.utils.utils import ( + crop, + dedent, + is_iter, + m_len, + make_iter, + mod_import, + pad, + to_str, +) # read from protocol NAWS later? _MAX_TEXT_WIDTH = settings.CLIENT_DEFAULT_WIDTH @@ -919,7 +929,7 @@ class EvMenu: # ((key,aliases)-value) pairs. # make sure helptext is defined - helptext = "" + helptext = "" if is_iter(nodetext): nodetext, *helptext = nodetext helptext = helptext[0] if helptext else "" diff --git a/evennia/utils/evmore.py b/evennia/utils/evmore.py index f989b6d8b7..cf72eccec3 100644 --- a/evennia/utils/evmore.py +++ b/evennia/utils/evmore.py @@ -40,6 +40,7 @@ from django.conf import settings from django.core.paginator import Paginator from django.db.models.query import QuerySet from django.utils.translation import gettext as _ + from evennia.commands import cmdhandler from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command diff --git a/evennia/utils/evtable.py b/evennia/utils/evtable.py index 6235fc1254..4c3a501172 100644 --- a/evennia/utils/evtable.py +++ b/evennia/utils/evtable.py @@ -118,6 +118,7 @@ from copy import copy, deepcopy from textwrap import TextWrapper from django.conf import settings + from evennia.utils.ansi import ANSIString from evennia.utils.utils import display_len as d_len from evennia.utils.utils import is_iter, justify @@ -220,7 +221,6 @@ class ANSITextWrapper(TextWrapper): chunks.reverse() while chunks: - # Start the list of chunks that will make up the current line. # cur_len is just the length of all the chunks in cur_line. cur_line = [] @@ -1401,7 +1401,6 @@ class EvTable: if self.height: # if we are fixing the table height, it means cells must crop text instead of resizing. if nrowmax: - # get minimum possible cell heights for each column cheights_min = [ max(cell.get_min_height() for cell in (col[iy] for col in self.worktable)) diff --git a/evennia/utils/funcparser.py b/evennia/utils/funcparser.py index 6145487f09..9417767467 100644 --- a/evennia/utils/funcparser.py +++ b/evennia/utils/funcparser.py @@ -48,6 +48,7 @@ import inspect import random from django.conf import settings + from evennia.utils import logger, search from evennia.utils.utils import ( callables_from_module, @@ -333,7 +334,6 @@ class FuncParser: literal_infuncstr = False for char in string: - if escaped: # always store escaped characters verbatim if curr_func: @@ -1298,8 +1298,11 @@ def funcparser_callable_your( if caller == receiver: return "Your" if capitalize else "your" - name = caller.get_display_name(looker=receiver) \ - if hasattr(caller, "get_display_name") else str(caller) + name = ( + caller.get_display_name(looker=receiver) + if hasattr(caller, "get_display_name") + else str(caller) + ) return name + "'s" diff --git a/evennia/utils/tests/test_create_functions.py b/evennia/utils/tests/test_create_functions.py index 8c0559885b..ba265812fb 100644 --- a/evennia/utils/tests/test_create_functions.py +++ b/evennia/utils/tests/test_create_functions.py @@ -84,7 +84,6 @@ class TestCreateScript(BaseEvenniaTest): class TestCreateHelpEntry(TestCase): - help_entry = """ Qui laborum voluptas quis commodi ipsum quo temporibus eum. Facilis assumenda facilis architecto in corrupti. Est placeat eum amet qui beatae @@ -130,7 +129,6 @@ class TestCreateHelpEntry(TestCase): class TestCreateMessage(BaseEvenniaTest): - msgtext = """ Qui laborum voluptas quis commodi ipsum quo temporibus eum. Facilis assumenda facilis architecto in corrupti. Est placeat eum amet qui beatae diff --git a/evennia/utils/tests/test_dbserialize.py b/evennia/utils/tests/test_dbserialize.py index 2c0ef1ab2b..f70bf702a0 100644 --- a/evennia/utils/tests/test_dbserialize.py +++ b/evennia/utils/tests/test_dbserialize.py @@ -5,9 +5,10 @@ Tests for dbserialize module from collections import defaultdict, deque from django.test import TestCase +from parameterized import parameterized + from evennia.objects.objects import DefaultObject from evennia.utils import dbserialize -from parameterized import parameterized class TestDbSerialize(TestCase): @@ -203,7 +204,6 @@ class DbObjWrappers(TestCase): self.assertEqual(self.dbobj1.db.dict["key2"].hidden_obj, self.dbobj2) def test_dbobj_hidden_defaultdict(self): - con1 = _ValidContainer(self.dbobj2) con2 = _ValidContainer(self.dbobj2) diff --git a/evennia/utils/tests/test_evform.py b/evennia/utils/tests/test_evform.py index a3d7dd4d0f..4d879cfafb 100644 --- a/evennia/utils/tests/test_evform.py +++ b/evennia/utils/tests/test_evform.py @@ -10,7 +10,6 @@ from evennia.utils import ansi, evform, evtable class TestEvForm(TestCase): - maxDiff = None def _parse_form(self): @@ -275,7 +274,6 @@ class TestEvFormErrors(TestCase): maxDiff = None def _form(self, form, **kwargs): - formdict = { "form": form, "formchar": "x", diff --git a/evennia/utils/tests/test_evmenu.py b/evennia/utils/tests/test_evmenu.py index 7b5e3f43c2..9a83b440df 100644 --- a/evennia/utils/tests/test_evmenu.py +++ b/evennia/utils/tests/test_evmenu.py @@ -21,9 +21,10 @@ import copy from anything import Anything from django.test import TestCase +from mock import MagicMock + from evennia.utils import ansi, evmenu from evennia.utils.test_resources import BaseEvenniaTest -from mock import MagicMock class TestEvMenu(TestCase): diff --git a/evennia/utils/tests/test_funcparser.py b/evennia/utils/tests/test_funcparser.py index dd2894f5f6..ed59006cb0 100644 --- a/evennia/utils/tests/test_funcparser.py +++ b/evennia/utils/tests/test_funcparser.py @@ -113,7 +113,6 @@ class TestFuncParser(TestCase): """ def setUp(self): - self.parser = funcparser.FuncParser(_test_callables) def test_constructor_wrong_args(self): @@ -154,55 +153,55 @@ class TestFuncParser(TestCase): (r'Test args10 $foo(",")', "Test args10 _test(,)"), ("Test args11 $foo(()", "Test args11 $foo(()"), # invalid syntax ( - r'Test kwarg1 $bar(foo=1, bar="foo", too=ere)', - "Test kwarg1 _test(foo=1, bar=foo, too=ere)", + r'Test kwarg1 $bar(foo=1, bar="foo", too=ere)', + "Test kwarg1 _test(foo=1, bar=foo, too=ere)", ), ("Test kwarg2 $bar(foo,bar,too=ere)", "Test kwarg2 _test(foo, bar, too=ere)"), ("test kwarg3 $foo(foo = bar, bar = ere )", "test kwarg3 _test(foo=bar, bar=ere)"), ( - r"test kwarg4 $foo(foo =' bar ',\" bar \"= ere )", - "test kwarg4 _test(foo=' bar ', \" bar \"=ere)", + r"test kwarg4 $foo(foo =' bar ',\" bar \"= ere )", + "test kwarg4 _test(foo=' bar ', \" bar \"=ere)", ), ( - "Test nest1 $foo($bar(foo,bar,too=ere))", - "Test nest1 _test(_test(foo, bar, too=ere))", + "Test nest1 $foo($bar(foo,bar,too=ere))", + "Test nest1 _test(_test(foo, bar, too=ere))", ), ( - "Test nest2 $foo(bar,$repl(a),$repl()=$repl(),a=b) etc", - "Test nest2 _test(bar, rar, rr=rr, a=b) etc", + "Test nest2 $foo(bar,$repl(a),$repl()=$repl(),a=b) etc", + "Test nest2 _test(bar, rar, rr=rr, a=b) etc", ), ("Test nest3 $foo(bar,$repl($repl($repl(c))))", "Test nest3 _test(bar, rrrcrrr)"), ( - "Test nest4 $foo($bar(a,b),$bar(a,$repl()),$bar())", - "Test nest4 _test(_test(a, b), _test(a, rr), _test())", + "Test nest4 $foo($bar(a,b),$bar(a,$repl()),$bar())", + "Test nest4 _test(_test(a, b), _test(a, rr), _test())", ), ("Test escape1 \\$repl(foo)", "Test escape1 $repl(foo)"), ( - 'Test escape2 "This is $foo() and $bar($bar())", $repl()', - 'Test escape2 "This is _test() and _test(_test())", rr', + 'Test escape2 "This is $foo() and $bar($bar())", $repl()', + 'Test escape2 "This is _test() and _test(_test())", rr', ), ( - "Test escape3 'This is $foo() and $bar($bar())', $repl()", - "Test escape3 'This is _test() and _test(_test())', rr", + "Test escape3 'This is $foo() and $bar($bar())', $repl()", + "Test escape3 'This is _test() and _test(_test())', rr", ), ( - "Test escape4 $$foo() and $$bar(a,b), $repl()", - "Test escape4 $foo() and $bar(a,b), rr", + "Test escape4 $$foo() and $$bar(a,b), $repl()", + "Test escape4 $foo() and $bar(a,b), rr", ), ("Test with color |r$foo(a,b)|n is ok", "Test with color |r_test(a, b)|n is ok"), ("Test malformed1 This is $foo( and $bar(", "Test malformed1 This is $foo( and $bar("), ( - "Test malformed2 This is $foo( and $bar()", - "Test malformed2 This is $foo( and _test()", + "Test malformed2 This is $foo( and $bar()", + "Test malformed2 This is $foo( and _test()", ), ("Test malformed3 $", "Test malformed3 $"), ( - "Test malformed4 This is $foo(a=b and $bar(", - "Test malformed4 This is $foo(a=b and $bar(", + "Test malformed4 This is $foo(a=b and $bar(", + "Test malformed4 This is $foo(a=b and $bar(", ), ( - "Test malformed5 This is $foo(a=b, and $repl()", - "Test malformed5 This is $foo(a=b, and rr", + "Test malformed5 This is $foo(a=b, and $repl()", + "Test malformed5 This is $foo(a=b, and rr", ), ("Test nonstr 4x2 = $double(4)", "Test nonstr 4x2 = 8"), ("Test nonstr 4x2 = $double(foo)", "Test nonstr 4x2 = N/A"), @@ -212,8 +211,8 @@ class TestFuncParser(TestCase): ("Test eval3 $eval(\"'21' + 'foo' + 'bar'\")", "Test eval3 21foobar"), (r"Test eval4 $eval('21' + '$repl()' + \"\" + str(10 // 2))", "Test eval4 21rr5"), ( - r"Test eval5 $eval(\'21\' + \'\$repl()\' + \'\' + str(10 // 2))", - "Test eval5 21$repl()5", + r"Test eval5 $eval(\'21\' + \'\$repl()\' + \'\' + str(10 // 2))", + "Test eval5 21$repl()5", ), ("Test eval6 $eval(\"'$repl(a)' + '$repl(b)'\")", "Test eval6 rarrbr"), ("Test type1 $typ([1,2,3,4])", "Test type1 "), @@ -222,8 +221,8 @@ class TestFuncParser(TestCase): ("Test type4 $typ({1:2,3:4})", "Test type4 "), ("Test type5 $typ(1), $typ(1.0)", "Test type5 , "), ( - "Test type6 $typ(\"'1'\"), $typ('\"1.0\"')", - "Test type6 , ", + "Test type6 $typ(\"'1'\"), $typ('\"1.0\"')", + "Test type6 , ", ), ("Test add1 $add(1, 2)", "Test add1 3"), ("Test add2 $add([1,2,3,4], [5,6])", "Test add2 [1, 2, 3, 4, 5, 6]"), @@ -248,8 +247,8 @@ class TestFuncParser(TestCase): @parameterized.expand( ( - "Test malformed This is $dummy(a, b) and $bar(", - "Test $funcNotFound()", + "Test malformed This is $dummy(a, b) and $bar(", + "Test $funcNotFound()", ) ) def test_parse_raise_unparseable(self, unparseable): @@ -437,24 +436,24 @@ class TestDefaultCallables(TestCase): ("$You() $conj(smile) at $You(char1).", "You smile at You.", "Char1 smiles at Char1."), ("$You() $conj(smile) at $You(char2).", "You smile at Char2.", "Char1 smiles at You."), ( - "$You(char2) $conj(smile) at $you(char1).", - "Char2 smile at you.", - "You smiles at Char1.", + "$You(char2) $conj(smile) at $you(char1).", + "Char2 smile at you.", + "You smiles at Char1.", ), ( - "$You() $conj(smile) to $pron(yourself,m).", - "You smile to yourself.", - "Char1 smiles to himself.", + "$You() $conj(smile) to $pron(yourself,m).", + "You smile to yourself.", + "Char1 smiles to himself.", ), ( - "$You() $conj(smile) to $pron(herself).", - "You smile to yourself.", - "Char1 smiles to herself.", + "$You() $conj(smile) to $pron(herself).", + "You smile to yourself.", + "Char1 smiles to herself.", ), # reverse reference ( - "$Your() smile is the greatest ever.", - "Your smile is the greatest ever.", - "Char1's smile is the greatest ever." + "$Your() smile is the greatest ever.", + "Your smile is the greatest ever.", + "Char1's smile is the greatest ever.", ), ] ) @@ -516,8 +515,8 @@ class TestDefaultCallables(TestCase): [ ("Test $pad(Hello, 20, c, -) there", "Test -------Hello-------- there"), ( - "Test $pad(Hello, width=20, align=c, fillchar=-) there", - "Test -------Hello-------- there", + "Test $pad(Hello, width=20, align=c, fillchar=-) there", + "Test -------Hello-------- there", ), ("Test $crop(This is a long test, 12)", "Test This is[...]"), ("Some $space(10) here", "Some here"), @@ -533,16 +532,16 @@ class TestDefaultCallables(TestCase): ("Some $rjust(Hello, width=30)", "Some Hello"), ("Some $cjust(Hello, 30)", "Some Hello "), ( - "There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.", - "There is one goose here.", + "There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.", + "There is one goose here.", ), ( - "There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.", - "There are two geese here.", + "There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.", + "There are two geese here.", ), ( - "There is $int2str(1) murderer, but $int2str(12) suspects.", - "There is one murderer, but twelve suspects.", + "There is $int2str(1) murderer, but $int2str(12) suspects.", + "There is one murderer, but twelve suspects.", ), ("There is $an(thing) here", "There is a thing here"), ("Some $eval(\"'-'*20\")Hello", "Some --------------------Hello"), diff --git a/evennia/utils/tests/test_utils.py b/evennia/utils/tests/test_utils.py index e831bbf623..8a76a695a4 100644 --- a/evennia/utils/tests/test_utils.py +++ b/evennia/utils/tests/test_utils.py @@ -318,7 +318,6 @@ class LatinifyTest(TestCase): class TestFormatGrid(TestCase): - maxDiff = None def setUp(self): diff --git a/evennia/utils/tests/test_validatorfuncs.py b/evennia/utils/tests/test_validatorfuncs.py index 958708d9dd..f691d92836 100644 --- a/evennia/utils/tests/test_validatorfuncs.py +++ b/evennia/utils/tests/test_validatorfuncs.py @@ -128,7 +128,6 @@ class TestValidatorFuncs(TestCase): validatorfuncs.boolean(b) def test_timezone_ok(self): - for tz in ["America/Chicago", "GMT", "UTC"]: self.assertEqual(tz, validatorfuncs.timezone(tz).zone) diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index f5338ba242..f44e78c372 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -27,7 +27,6 @@ from os.path import join as osjoin from string import punctuation from unicodedata import east_asian_width -import evennia from django.apps import apps from django.conf import settings from django.core.exceptions import ValidationError as DjangoValidationError @@ -35,12 +34,14 @@ from django.core.validators import validate_email as django_validate_email from django.utils import timezone from django.utils.html import strip_tags from django.utils.translation import gettext as _ -from evennia.utils import logger from simpleeval import simple_eval from twisted.internet import reactor, threads from twisted.internet.defer import returnValue # noqa - used as import target from twisted.internet.task import deferLater +import evennia +from evennia.utils import logger + _MULTIMATCH_TEMPLATE = settings.SEARCH_MULTIMATCH_TEMPLATE _EVENNIA_DIR = settings.EVENNIA_DIR _GAME_DIR = settings.GAME_DIR @@ -2941,4 +2942,3 @@ def str2int(number): # invalid number-word, raise ValueError raise ValueError(f"String {original_input} cannot be converted to int.") return sum(sums) - diff --git a/evennia/web/admin/scripts.py b/evennia/web/admin/scripts.py index faafe4acac..f5358613f8 100644 --- a/evennia/web/admin/scripts.py +++ b/evennia/web/admin/scripts.py @@ -14,7 +14,6 @@ from .tags import TagInline class ScriptForm(forms.ModelForm): - db_key = forms.CharField( label="Name/Key", help_text="Script identifier, shown in listings etc." ) diff --git a/evennia/web/admin/urls.py b/evennia/web/admin/urls.py index e9c4d399d6..0a59fcf752 100644 --- a/evennia/web/admin/urls.py +++ b/evennia/web/admin/urls.py @@ -19,7 +19,6 @@ urlpatterns = [ ] if settings.EVENNIA_ADMIN: - urlpatterns += [ # Our override for the admin. path("", frontpage.evennia_admin, name="evennia_admin"), diff --git a/evennia/web/utils/adminsite.py b/evennia/web/utils/adminsite.py index 3c02e66102..249b1cfc4d 100644 --- a/evennia/web/utils/adminsite.py +++ b/evennia/web/utils/adminsite.py @@ -34,7 +34,11 @@ class EvenniaAdminSite(admin.AdminSite): def get_app_list(self, request, app_label=None): app_list = super().get_app_list(request, app_label=app_label) app_mapping = {app["app_label"]: app for app in app_list} - out = [app_mapping.pop(app_label) for app_label in settings.DJANGO_ADMIN_APP_ORDER if app_label in app_mapping] + out = [ + app_mapping.pop(app_label) + for app_label in settings.DJANGO_ADMIN_APP_ORDER + if app_label in app_mapping + ] for app in settings.DJANGO_ADMIN_APP_EXCLUDE: app_mapping.pop(app, None) out += app_mapping.values() diff --git a/evennia/web/utils/general_context.py b/evennia/web/utils/general_context.py index cd41d518e4..e38d564d2e 100644 --- a/evennia/web/utils/general_context.py +++ b/evennia/web/utils/general_context.py @@ -71,7 +71,7 @@ def load_game_settings(): SERVER_HOSTNAME = settings.SERVER_HOSTNAME REGISTER_ENABLED = settings.NEW_ACCOUNT_REGISTRATION_ENABLED - + TELNET_ENABLED = settings.TELNET_ENABLED TELNET_PORTS = settings.TELNET_PORTS TELNET_SSL_ENABLED = settings.SSL_ENABLED diff --git a/evennia/web/website/forms.py b/evennia/web/website/forms.py index bec84a0734..db7d513d58 100644 --- a/evennia/web/website/forms.py +++ b/evennia/web/website/forms.py @@ -3,6 +3,7 @@ from django.conf import settings from django.contrib.auth.forms import UserCreationForm, UsernameField from django.forms import ModelForm from django.utils.html import escape + from evennia.utils import class_from_module diff --git a/evennia/web/website/tests.py b/evennia/web/website/tests.py index 230d4442f7..40e453c173 100644 --- a/evennia/web/website/tests.py +++ b/evennia/web/website/tests.py @@ -12,7 +12,6 @@ _FILE_HELP_ENTRIES = None class EvenniaWebTest(BaseEvenniaTest): - # Use the same classes the views are expecting account_typeclass = settings.BASE_ACCOUNT_TYPECLASS object_typeclass = settings.BASE_OBJECT_TYPECLASS diff --git a/evennia/web/website/views/accounts.py b/evennia/web/website/views/accounts.py index 70a811dee7..5ecb5128ee 100644 --- a/evennia/web/website/views/accounts.py +++ b/evennia/web/website/views/accounts.py @@ -8,6 +8,7 @@ from django.conf import settings from django.contrib import messages from django.http import HttpResponseRedirect from django.urls import reverse_lazy + from evennia.utils import class_from_module from evennia.web.website import forms