diff --git a/docs/source/conf.py b/docs/source/conf.py index 193eafcb25..e63efefcd1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -374,8 +374,12 @@ def setup(app): # build toctree file sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) - from docs.pylib import (auto_link_remapper, contrib_readmes2docs, - update_default_cmd_index, update_dynamic_pages) + from docs.pylib import ( + auto_link_remapper, + contrib_readmes2docs, + update_default_cmd_index, + update_dynamic_pages, + ) _no_autodoc = os.environ.get("NOAUTODOC") update_default_cmd_index.run_update(no_autodoc=_no_autodoc) diff --git a/evennia/__init__.py b/evennia/__init__.py index bf5eafa8c6..5e8a53f776 100644 --- a/evennia/__init__.py +++ b/evennia/__init__.py @@ -16,6 +16,7 @@ to launch such a shell (using python or ipython depending on your install). See www.evennia.com for full documentation. """ + import evennia # docstring header diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index e683aa8dd1..b01592ddfa 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -10,18 +10,20 @@ character object, so you should customize that instead for most things). """ + import re import time import typing 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 @@ -29,17 +31,24 @@ from evennia.comms.models import ChannelDB from evennia.objects.models import ObjectDB from evennia.scripts.scripthandler import ScriptHandler from evennia.server.models import ServerConfig -from evennia.server.signals import (SIGNAL_ACCOUNT_POST_CREATE, - SIGNAL_ACCOUNT_POST_LOGIN_FAIL, - SIGNAL_OBJECT_POST_PUPPET, - SIGNAL_OBJECT_POST_UNPUPPET) +from evennia.server.signals import ( + SIGNAL_ACCOUNT_POST_CREATE, + SIGNAL_ACCOUNT_POST_LOGIN_FAIL, + SIGNAL_OBJECT_POST_PUPPET, + SIGNAL_OBJECT_POST_UNPUPPET, +) from evennia.server.throttle import Throttle 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") diff --git a/evennia/accounts/manager.py b/evennia/accounts/manager.py index 83478654b8..f5d91e5fcf 100644 --- a/evennia/accounts/manager.py +++ b/evennia/accounts/manager.py @@ -7,6 +7,7 @@ import datetime from django.conf import settings from django.contrib.auth.models import UserManager from django.utils import timezone + 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/accounts/models.py b/evennia/accounts/models.py index ea00e24d9d..e8ecabea45 100644 --- a/evennia/accounts/models.py +++ b/evennia/accounts/models.py @@ -15,6 +15,7 @@ persistently store attributes of its own. This is ideal for extra account info and OOC account configuration variables etc. """ + from django.conf import settings from django.contrib.auth.models import AbstractUser from django.db import models diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 0da3039aaa..45605f758b 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 twisted.internet import reactor +from twisted.internet.defer import inlineCallbacks, returnValue +from twisted.internet.task import deferLater + from evennia.commands.cmdset import CmdSet 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 _IN_GAME_ERRORS = settings.IN_GAME_ERRORS diff --git a/evennia/commands/cmdparser.py b/evennia/commands/cmdparser.py index 6ae209c258..98b94638ea 100644 --- a/evennia/commands/cmdparser.py +++ b/evennia/commands/cmdparser.py @@ -6,7 +6,6 @@ same inputs as the default one. """ - import re from django.conf import settings diff --git a/evennia/commands/cmdset.py b/evennia/commands/cmdset.py index 618d78cfad..cac54816cb 100644 --- a/evennia/commands/cmdset.py +++ b/evennia/commands/cmdset.py @@ -26,6 +26,7 @@ Set theory. to affect the low-priority cmdset. Ex: A1,A3 + B1,B2,B4,B5 = B2,B4,B5 """ + from weakref import WeakKeyDictionary from django.utils.translation import gettext as _ diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 9f7b89e674..19b2f27391 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -64,6 +64,7 @@ example, you can have a 'On a boat' set, onto which you then tack on the 'Fishing' set. Fishing from a boat? No problem! """ + import sys from importlib import import_module from inspect import trace diff --git a/evennia/commands/command.py b/evennia/commands/command.py index 3d0d93dbff..8dbac1c3a7 100644 --- a/evennia/commands/command.py +++ b/evennia/commands/command.py @@ -4,6 +4,7 @@ The base Command class. All commands in Evennia inherit from the 'Command' class in this module. """ + import inspect import math import re @@ -11,6 +12,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 @@ -19,9 +21,7 @@ from evennia.utils.utils import fill, is_iter, lazy_property, make_iter CMD_IGNORE_PREFIXES = settings.CMD_IGNORE_PREFIXES - class InterruptCommand(Exception): - """Cleanly interrupt a command.""" pass @@ -491,22 +491,22 @@ class Command(metaclass=CommandMeta): Command \"{cmdname}\" has no defined `func()` method. Available properties on this command are: {variables}""" - variables = [" |w{}|n ({}): {}".format( - key, type(val), f'"{val}"' if isinstance(val, str) else val + variables = [ + " |w{}|n ({}): {}".format(key, type(val), f'"{val}"' if isinstance(val, str) else val) + for key, val in ( + ("self.key", self.key), + ("self.cmdname", self.cmdstring), + ("self.raw_cmdname", self.raw_cmdname), + ("self.raw_string", self.raw_string), + ("self.aliases", self.aliases), + ("self.args", self.args), + ("self.caller", self.caller), + ("self.obj", self.obj), + ("self.session", self.session), + ("self.locks", self.locks), + ("self.help_category", self.help_category), + ("self.cmdset", self.cmdset), ) - for key, val in - (("self.key", self.key), - ("self.cmdname", self.cmdstring), - ("self.raw_cmdname", self.raw_cmdname), - ("self.raw_string", self.raw_string), - ("self.aliases", self.aliases), - ("self.args", self.args), - ("self.caller", self.caller), - ("self.obj", self.obj), - ("self.session", self.session), - ("self.locks", self.locks), - ("self.help_category", self.help_category), - ("self.cmdset", self.cmdset)) ] output = output_string.format(cmdname=self.key, variables="\n ".join(variables)) self.msg(output) diff --git a/evennia/commands/default/account.py b/evennia/commands/default/account.py index 7b966eb7cf..f51b079e17 100644 --- a/evennia/commands/default/account.py +++ b/evennia/commands/default/account.py @@ -18,6 +18,7 @@ self.msg() and similar methods to reroute returns to the correct method. Otherwise all text will be returned to all connected sessions. """ + import time from codecs import lookup as codecs_lookup diff --git a/evennia/commands/default/batchprocess.py b/evennia/commands/default/batchprocess.py index 2d1ef758e4..694fd20972 100644 --- a/evennia/commands/default/batchprocess.py +++ b/evennia/commands/default/batchprocess.py @@ -17,6 +17,7 @@ the Evennia API. It is also a severe security risk and should therefore always be limited to superusers only. """ + import re from django.conf import settings diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index e99455d0f9..ff4111643e 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -1,16 +1,17 @@ """ Building and world design commands """ + import re import typing -import evennia from django.conf import settings from django.core.paginator import Paginator from django.db.models import Max, Min, Q + +import evennia from evennia import InterruptCommand -from evennia.commands.cmdhandler import (generate_cmdset_providers, - get_and_merge_cmdsets) +from evennia.commands.cmdhandler import generate_cmdset_providers, get_and_merge_cmdsets from evennia.locks.lockhandler import LockException from evennia.objects.models import ObjectDB from evennia.prototypes import menus as olc_menus @@ -23,10 +24,18 @@ from evennia.utils.dbserialize import deserialize from evennia.utils.eveditor import EvEditor from evennia.utils.evmore import EvMore from evennia.utils.evtable import EvTable -from evennia.utils.utils import (class_from_module, crop, dbref, display_len, - format_grid, get_all_typeclasses, - inherits_from, interactive, list_to_string, - variable_from_module) +from evennia.utils.utils import ( + class_from_module, + crop, + dbref, + display_len, + format_grid, + get_all_typeclasses, + inherits_from, + interactive, + list_to_string, + variable_from_module, +) COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) @@ -259,7 +268,7 @@ class CmdSetObjAlias(COMMAND_DEFAULT_CLASS): obj = caller.search(objname) if not obj: return - if self.rhs is None and 'delete' not in self.switches: + if self.rhs is None and "delete" not in self.switches: # no =, and not deleting, so we just list aliases on object. aliases = obj.aliases.all(return_key_and_category=True) if aliases: @@ -300,7 +309,7 @@ class CmdSetObjAlias(COMMAND_DEFAULT_CLASS): if "delete" in self.switches: # delete all matching keys, regardless of category existed = False - for key, category in obj.aliases.all(return_key_and_category=True): + for key, category in obj.aliases.all(return_key_and_category=True): if key == self.rhs: obj.aliases.remove(key=self.rhs, category=category) existed = True @@ -2956,9 +2965,9 @@ class CmdExamine(ObjManipCommand): ): objdata["Stored Cmdset(s)"] = self.format_stored_cmdsets(obj) objdata["Merged Cmdset(s)"] = self.format_merged_cmdsets(obj, current_cmdset) - objdata[ - f"Commands available to {obj.key} (result of Merged Cmdset(s))" - ] = self.format_current_cmds(obj, current_cmdset) + objdata[f"Commands available to {obj.key} (result of Merged Cmdset(s))"] = ( + self.format_current_cmds(obj, current_cmdset) + ) if self.object_type == "script": objdata["Description"] = self.format_script_desc(obj) objdata["Persistent"] = self.format_script_is_persistent(obj) @@ -3415,9 +3424,11 @@ class ScriptEvMore(EvMore): table.add_row( f"#{script.id}", - f"{script.obj.key}({script.obj.dbref})" - if (hasattr(script, "obj") and script.obj) - else "", + ( + f"{script.obj.key}({script.obj.dbref})" + if (hasattr(script, "obj") and script.obj) + else "" + ), script.key, script.interval if script.interval > 0 else "--", nextrep, diff --git a/evennia/commands/default/cmdset_character.py b/evennia/commands/default/cmdset_character.py index f8294dd6b7..df06f3f893 100644 --- a/evennia/commands/default/cmdset_character.py +++ b/evennia/commands/default/cmdset_character.py @@ -4,6 +4,7 @@ available (i.e. IC commands). Note that some commands, such as communication-commands are instead put on the account level, in the Account cmdset. Account commands remain available also to Characters. """ + from evennia.commands.cmdset import CmdSet from evennia.commands.default import ( admin, diff --git a/evennia/commands/default/cmdset_session.py b/evennia/commands/default/cmdset_session.py index f81e8b9636..eca352c44e 100644 --- a/evennia/commands/default/cmdset_session.py +++ b/evennia/commands/default/cmdset_session.py @@ -1,6 +1,7 @@ """ This module stores session-level commands. """ + from evennia.commands.cmdset import CmdSet from evennia.commands.default import account diff --git a/evennia/commands/default/cmdset_unloggedin.py b/evennia/commands/default/cmdset_unloggedin.py index b668325bd8..1ce4e7749d 100644 --- a/evennia/commands/default/cmdset_unloggedin.py +++ b/evennia/commands/default/cmdset_unloggedin.py @@ -3,6 +3,7 @@ This module describes the unlogged state of the default game. The setting STATE_UNLOGGED should be set to the python path of the state instance in this module. """ + from evennia.commands.cmdset import CmdSet from evennia.commands.default import unloggedin diff --git a/evennia/commands/default/comms.py b/evennia/commands/default/comms.py index 2cec5ddf08..cac9905a5a 100644 --- a/evennia/commands/default/comms.py +++ b/evennia/commands/default/comms.py @@ -9,6 +9,7 @@ Communication commands: from django.conf import settings from django.db.models import Q + from evennia.accounts import bots from evennia.accounts.models import AccountDB from evennia.comms.comms import DefaultChannel @@ -1412,13 +1413,17 @@ class CmdPage(COMMAND_DEFAULT_CLASS): message = f"{caller.key} {message.strip(':').strip()}" # create the persistent message object - create.create_message(caller, message, receivers=targets, - locks=(f"read:id({caller.id}) or perm(Admin);" - f"delete:id({caller.id}) or perm(Admin);" - f"edit:id({caller.id}) or perm(Admin)" - ), - tags = [("page", "comms")], - ) + create.create_message( + caller, + message, + receivers=targets, + locks=( + f"read:id({caller.id}) or perm(Admin);" + f"delete:id({caller.id}) or perm(Admin);" + f"edit:id({caller.id}) or perm(Admin)" + ), + tags=[("page", "comms")], + ) # tell the accounts they got a message. received = [] diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index 4a65b63b2d..e46fbe2cf5 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -1,10 +1,12 @@ """ General Character commands usually available to all characters """ + import re -import evennia from django.conf import settings + +import evennia from evennia.typeclasses.attributes import NickTemplateInvalid from evennia.utils import utils diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index 546945367e..d6e2466dc5 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -4,7 +4,6 @@ System commands """ - import code import datetime import os @@ -112,7 +111,6 @@ class CmdReset(COMMAND_DEFAULT_CLASS): class CmdShutdown(COMMAND_DEFAULT_CLASS): - """ stop the server completely @@ -277,7 +275,6 @@ def evennia_local_vars(caller): class EvenniaPythonConsole(code.InteractiveConsole): - """Evennia wrapper around a Python interactive console.""" def __init__(self, caller): diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index e60ee3ddc2..b3fe5b5fd7 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -14,17 +14,32 @@ main test suite started with import datetime from unittest.mock import MagicMock, Mock, patch -import evennia from anything import Anything from django.conf import settings from django.test import override_settings -from evennia import (DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom, - ObjectDB, search_object) +from parameterized import parameterized +from twisted.internet import task + +import evennia +from evennia import ( + DefaultCharacter, + DefaultExit, + DefaultObject, + DefaultRoom, + ObjectDB, + search_object, +) 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 @@ -33,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 @@ -368,8 +381,7 @@ class TestCmdTasks(BaseEvenniaCommandTest): self.timedelay = 5 global _TASK_HANDLER if _TASK_HANDLER is None: - from evennia.scripts.taskhandler import \ - TASK_HANDLER as _TASK_HANDLER + from evennia.scripts.taskhandler import TASK_HANDLER as _TASK_HANDLER _TASK_HANDLER.clock = task.Clock() self.task_handler = _TASK_HANDLER self.task_handler.clear() @@ -787,19 +799,20 @@ class TestBuilding(BaseEvenniaCommandTest): self.call(building.CmdSetObjAlias(), "Obj2 =", "No aliases to clear.") self.call(building.CmdSetObjAlias(), "Obj =", "Cleared aliases from Obj: testobj1b") - self.call(building.CmdSetObjAlias(), + self.call( + building.CmdSetObjAlias(), "/category Obj = testobj1b:category1", - "Alias(es) for 'Obj' set to 'testobj1b' (category: 'category1')." + "Alias(es) for 'Obj' set to 'testobj1b' (category: 'category1').", ) self.call( building.CmdSetObjAlias(), "/category Obj = testobj1b:category2", - "Alias(es) for 'Obj' set to 'testobj1b,testobj1b' (category: 'category2')." + "Alias(es) for 'Obj' set to 'testobj1b,testobj1b' (category: 'category2').", ) self.call( - building.CmdSetObjAlias(), # delete both occurences of alias 'testobj1b' + building.CmdSetObjAlias(), # delete both occurences of alias 'testobj1b' "/delete Obj = testobj1b", - "Alias 'testobj1b' deleted from Obj." + "Alias 'testobj1b' deleted from Obj.", ) self.call(building.CmdSetObjAlias(), "Obj =", "No aliases to clear.") @@ -1773,8 +1786,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") @@ -1822,8 +1834,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") @@ -2068,6 +2079,7 @@ class TestComms(BaseEvenniaCommandTest): receiver=self.account, ) from evennia.comms.models import Msg + msgs = Msg.objects.filter(db_tags__db_key="page", db_tags__db_category="comms") self.assertEqual(msgs[0].senders, [self.account]) self.assertEqual(msgs[0].receivers, [self.account2]) diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index 75fff10ccd..a69e20068e 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -2,6 +2,7 @@ Commands that are available from the connect screen. """ + import datetime import re from codecs import lookup as codecs_lookup diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index ea2a512b5c..a32b425df8 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -2,6 +2,7 @@ Base typeclass for in-game Channels. """ + import re from django.contrib.contenttypes.models import ContentType diff --git a/evennia/comms/managers.py b/evennia/comms/managers.py index b55b814009..7cd720a8dd 100644 --- a/evennia/comms/managers.py +++ b/evennia/comms/managers.py @@ -4,7 +4,6 @@ Comm system components. """ - from django.conf import settings from django.db.models import Q diff --git a/evennia/comms/models.py b/evennia/comms/models.py index 0869eaac09..a37cb733bc 100644 --- a/evennia/comms/models.py +++ b/evennia/comms/models.py @@ -18,6 +18,7 @@ connect to channels by use of a ChannelConnect object (this object is 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 diff --git a/evennia/contrib/base_systems/awsstorage/aws_s3_cdn.py b/evennia/contrib/base_systems/awsstorage/aws_s3_cdn.py index f8633933ca..1123c66f1a 100644 --- a/evennia/contrib/base_systems/awsstorage/aws_s3_cdn.py +++ b/evennia/contrib/base_systems/awsstorage/aws_s3_cdn.py @@ -221,7 +221,6 @@ def get_available_overwrite_name(name, max_length): @deconstructible class S3Boto3StorageFile(File): - """ The default file object used by the S3Boto3Storage backend. This file implements file streaming using boto's multipart diff --git a/evennia/contrib/base_systems/building_menu/__init__.py b/evennia/contrib/base_systems/building_menu/__init__.py index 5ab8549d2d..0b7e8cbf05 100644 --- a/evennia/contrib/base_systems/building_menu/__init__.py +++ b/evennia/contrib/base_systems/building_menu/__init__.py @@ -2,5 +2,6 @@ Build-menu contrib - vincent-lg 2018 """ + from .building_menu import BuildingMenu # noqa from .building_menu import GenericBuildingCmd # noqa diff --git a/evennia/contrib/base_systems/building_menu/building_menu.py b/evennia/contrib/base_systems/building_menu/building_menu.py index e8bfd291e6..63d52c3211 100644 --- a/evennia/contrib/base_systems/building_menu/building_menu.py +++ b/evennia/contrib/base_systems/building_menu/building_menu.py @@ -331,7 +331,6 @@ def menu_edit(caller, choice, obj): class CmdNoInput(Command): - """No input has been found.""" key = _CMD_NOINPUT @@ -352,7 +351,6 @@ class CmdNoInput(Command): class CmdNoMatch(Command): - """No input has been found.""" key = _CMD_NOMATCH @@ -394,7 +392,6 @@ class CmdNoMatch(Command): class BuildingMenuCmdSet(CmdSet): - """Building menu CmdSet.""" key = "building_menu" @@ -421,7 +418,6 @@ class BuildingMenuCmdSet(CmdSet): class Choice: - """A choice object, created by `add_choice`.""" def __init__( @@ -557,7 +553,6 @@ class Choice: class BuildingMenu: - """ Class allowing to create and set building menus to edit specific objects. @@ -1200,7 +1195,6 @@ class BuildingMenu: # Generic building menu and command class GenericBuildingMenu(BuildingMenu): - """A generic building menu, allowing to edit any object. This is more a demonstration menu. By default, it allows to edit the @@ -1241,7 +1235,6 @@ class GenericBuildingMenu(BuildingMenu): class GenericBuildingCmd(Command): - """ Generic building command. diff --git a/evennia/contrib/base_systems/components/__init__.py b/evennia/contrib/base_systems/components/__init__.py index 21867e7528..931b156f88 100644 --- a/evennia/contrib/base_systems/components/__init__.py +++ b/evennia/contrib/base_systems/components/__init__.py @@ -7,6 +7,7 @@ This helps writing isolated code and reusing it over multiple objects. See the docs for more information. """ + from . import exceptions # noqa from .component import Component # noqa from .dbfield import DBField, NDBField, TagField # noqa diff --git a/evennia/contrib/base_systems/components/dbfield.py b/evennia/contrib/base_systems/components/dbfield.py index c5e0eb2eae..4b9c6d4fa8 100644 --- a/evennia/contrib/base_systems/components/dbfield.py +++ b/evennia/contrib/base_systems/components/dbfield.py @@ -3,6 +3,7 @@ Components - ChrisLR 2022 This file contains the Descriptors used to set Fields in Components """ + import typing from evennia.typeclasses.attributes import AttributeProperty, NAttributeProperty diff --git a/evennia/contrib/base_systems/custom_gametime/custom_gametime.py b/evennia/contrib/base_systems/custom_gametime/custom_gametime.py index ca6b26363e..f3f9ad3596 100644 --- a/evennia/contrib/base_systems/custom_gametime/custom_gametime.py +++ b/evennia/contrib/base_systems/custom_gametime/custom_gametime.py @@ -309,7 +309,6 @@ def schedule(callback, repeat=False, **kwargs): class GametimeScript(DefaultScript): - """Gametime-sensitive script.""" def at_script_creation(self): diff --git a/evennia/contrib/base_systems/godotwebsocket/__init__.py b/evennia/contrib/base_systems/godotwebsocket/__init__.py index 8311d5d7da..cb618d85d0 100644 --- a/evennia/contrib/base_systems/godotwebsocket/__init__.py +++ b/evennia/contrib/base_systems/godotwebsocket/__init__.py @@ -10,6 +10,7 @@ You could also pass extra data to this client for advanced functionality. See the docs for more information. """ + from evennia.contrib.base_systems.godotwebsocket.text2bbcode import ( BBCODE_PARSER, parse_to_bbcode, diff --git a/evennia/contrib/base_systems/godotwebsocket/text2bbcode.py b/evennia/contrib/base_systems/godotwebsocket/text2bbcode.py index ac16fb2743..5b94243941 100644 --- a/evennia/contrib/base_systems/godotwebsocket/text2bbcode.py +++ b/evennia/contrib/base_systems/godotwebsocket/text2bbcode.py @@ -3,6 +3,7 @@ Godot Websocket - ChrisLR 2022 This file contains the necessary code and data to convert text with color tags to bbcode (For godot) """ + from evennia.utils.ansi import * from evennia.utils.text2html import TextToHTMLparser diff --git a/evennia/contrib/base_systems/godotwebsocket/webclient.py b/evennia/contrib/base_systems/godotwebsocket/webclient.py index 3e77800abd..bd8576ff17 100644 --- a/evennia/contrib/base_systems/godotwebsocket/webclient.py +++ b/evennia/contrib/base_systems/godotwebsocket/webclient.py @@ -4,6 +4,7 @@ Godot Websocket - ChrisLR 2022 This file contains the code necessary to dedicate a port to communicate with Godot via Websockets. It uses the plugin system and should be plugged via settings as detailed in the readme. """ + import json from autobahn.twisted import WebSocketServerFactory diff --git a/evennia/contrib/base_systems/ingame_python/callbackhandler.py b/evennia/contrib/base_systems/ingame_python/callbackhandler.py index adb44395a0..e0bac0c3b3 100644 --- a/evennia/contrib/base_systems/ingame_python/callbackhandler.py +++ b/evennia/contrib/base_systems/ingame_python/callbackhandler.py @@ -6,7 +6,6 @@ from collections import namedtuple class CallbackHandler(object): - """ The callback handler for a specific object. diff --git a/evennia/contrib/base_systems/ingame_python/commands.py b/evennia/contrib/base_systems/ingame_python/commands.py index a3331648be..1d109aa888 100644 --- a/evennia/contrib/base_systems/ingame_python/commands.py +++ b/evennia/contrib/base_systems/ingame_python/commands.py @@ -70,7 +70,6 @@ Use the /del switch to remove callbacks that should not be connected. class CmdCallback(COMMAND_DEFAULT_CLASS): - """ Command to edit callbacks. """ diff --git a/evennia/contrib/base_systems/ingame_python/scripts.py b/evennia/contrib/base_systems/ingame_python/scripts.py index 63c0477008..047dbb10b7 100644 --- a/evennia/contrib/base_systems/ingame_python/scripts.py +++ b/evennia/contrib/base_systems/ingame_python/scripts.py @@ -27,7 +27,6 @@ RE_LINE_ERROR = re.compile(r'^ File "\", line (\d+)') class EventHandler(DefaultScript): - """ The event handler that contains all events in a global script. @@ -600,7 +599,6 @@ class EventHandler(DefaultScript): # Script to call time-related events class TimeEventScript(DefaultScript): - """Gametime-sensitive script.""" def at_script_creation(self): diff --git a/evennia/contrib/base_systems/ingame_python/tests.py b/evennia/contrib/base_systems/ingame_python/tests.py index b3f7d14a32..a0e420cb67 100644 --- a/evennia/contrib/base_systems/ingame_python/tests.py +++ b/evennia/contrib/base_systems/ingame_python/tests.py @@ -25,7 +25,6 @@ OLD_EVENTS = {} class TestEventHandler(BaseEvenniaTest): - """ Test cases of the event handler to add, edit or delete events. """ @@ -259,7 +258,6 @@ class TestEventHandler(BaseEvenniaTest): class TestCmdCallback(BaseEvenniaCommandTest): - """Test the @callback command.""" def setUp(self): @@ -448,7 +446,6 @@ class TestCmdCallback(BaseEvenniaCommandTest): class TestDefaultCallbacks(BaseEvenniaCommandTest): - """Test the default callbacks.""" def setUp(self): diff --git a/evennia/contrib/base_systems/ingame_python/typeclasses.py b/evennia/contrib/base_systems/ingame_python/typeclasses.py index 3922ffd11d..5f14ee8c6e 100644 --- a/evennia/contrib/base_systems/ingame_python/typeclasses.py +++ b/evennia/contrib/base_systems/ingame_python/typeclasses.py @@ -166,7 +166,6 @@ Variables you can use in this event: @register_events class EventCharacter(DefaultCharacter): - """Typeclass to represent a character and call event types.""" _events = { @@ -625,7 +624,6 @@ Variables you can use in this event: @register_events class EventExit(DefaultExit): - """Modified exit including management of events.""" _events = { @@ -721,7 +719,6 @@ Variables you can use in this event: @register_events class EventObject(DefaultObject): - """Default object with management of events.""" _events = { @@ -892,7 +889,6 @@ Variables you can use in this event: @register_events class EventRoom(DefaultRoom): - """Default room with management of events.""" _events = { diff --git a/evennia/contrib/base_systems/ingame_python/utils.py b/evennia/contrib/base_systems/ingame_python/utils.py index c99041e68c..8635792964 100644 --- a/evennia/contrib/base_systems/ingame_python/utils.py +++ b/evennia/contrib/base_systems/ingame_python/utils.py @@ -251,7 +251,6 @@ def phrase_event(callbacks, parameters): class InterruptEvent(RuntimeError): - """ Interrupt the current event. diff --git a/evennia/contrib/base_systems/menu_login/menu_login.py b/evennia/contrib/base_systems/menu_login/menu_login.py index b00dacfb67..bf9d1609d9 100644 --- a/evennia/contrib/base_systems/menu_login/menu_login.py +++ b/evennia/contrib/base_systems/menu_login/menu_login.py @@ -21,10 +21,14 @@ called automatically when a new user connects. """ from django.conf import settings + from evennia import CmdSet, Command, syscmdkeys from evennia.utils.evmenu import EvMenu -from evennia.utils.utils import (callables_from_module, class_from_module, - random_string_from_module) +from evennia.utils.utils import ( + callables_from_module, + class_from_module, + random_string_from_module, +) _CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE _GUEST_ENABLED = settings.GUEST_ENABLED diff --git a/evennia/contrib/base_systems/mux_comms_cmds/mux_comms_cmds.py b/evennia/contrib/base_systems/mux_comms_cmds/mux_comms_cmds.py index 5fadf4117b..ef1a3e0a5a 100644 --- a/evennia/contrib/base_systems/mux_comms_cmds/mux_comms_cmds.py +++ b/evennia/contrib/base_systems/mux_comms_cmds/mux_comms_cmds.py @@ -41,6 +41,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): ``` """ + from django.conf import settings from evennia.commands.cmdset import CmdSet diff --git a/evennia/contrib/base_systems/unixcommand/tests.py b/evennia/contrib/base_systems/unixcommand/tests.py index adb7421352..6a044bdeac 100644 --- a/evennia/contrib/base_systems/unixcommand/tests.py +++ b/evennia/contrib/base_systems/unixcommand/tests.py @@ -9,7 +9,6 @@ from .unixcommand import UnixCommand class CmdDummy(UnixCommand): - """A dummy UnixCommand.""" key = "dummy" diff --git a/evennia/contrib/base_systems/unixcommand/unixcommand.py b/evennia/contrib/base_systems/unixcommand/unixcommand.py index de1c73ab8f..1ad5cbaefe 100644 --- a/evennia/contrib/base_systems/unixcommand/unixcommand.py +++ b/evennia/contrib/base_systems/unixcommand/unixcommand.py @@ -72,14 +72,12 @@ from evennia.utils.ansi import raw class ParseError(Exception): - """An error occurred during parsing.""" pass class UnixCommandParser(argparse.ArgumentParser): - """A modifier command parser for unix commands. This parser is used to replace `argparse.ArgumentParser`. It @@ -183,7 +181,6 @@ class UnixCommandParser(argparse.ArgumentParser): class HelpAction(argparse.Action): - """Override the -h/--help action in the default parser. Using the default -h/--help will call the exit function in different diff --git a/evennia/contrib/full_systems/evscaperoom/menu.py b/evennia/contrib/full_systems/evscaperoom/menu.py index 8e76fb67fe..68f2d910e2 100644 --- a/evennia/contrib/full_systems/evscaperoom/menu.py +++ b/evennia/contrib/full_systems/evscaperoom/menu.py @@ -7,6 +7,7 @@ Here player user can set their own description as well as select to create a new room (to start from scratch) or join an existing room (with other players). """ + from evennia import EvMenu from evennia.utils import create, justify, list_to_string, logger from evennia.utils.evmenu import list_node diff --git a/evennia/contrib/full_systems/evscaperoom/objects.py b/evennia/contrib/full_systems/evscaperoom/objects.py index 627c931472..fceade2bf0 100644 --- a/evennia/contrib/full_systems/evscaperoom/objects.py +++ b/evennia/contrib/full_systems/evscaperoom/objects.py @@ -43,6 +43,7 @@ Available parents: - Positionable (supports sit/lie/knee/climb at once) """ + import inspect import re diff --git a/evennia/contrib/full_systems/evscaperoom/tests.py b/evennia/contrib/full_systems/evscaperoom/tests.py index 1b5cd75e0a..ed599a27d6 100644 --- a/evennia/contrib/full_systems/evscaperoom/tests.py +++ b/evennia/contrib/full_systems/evscaperoom/tests.py @@ -2,6 +2,7 @@ Unit tests for the Evscaperoom """ + import inspect import pkgutil from os import path diff --git a/evennia/contrib/game_systems/clothing/clothing.py b/evennia/contrib/game_systems/clothing/clothing.py index 2c98b17f9f..6fe957eb72 100644 --- a/evennia/contrib/game_systems/clothing/clothing.py +++ b/evennia/contrib/game_systems/clothing/clothing.py @@ -72,9 +72,11 @@ with which to test the system: wear shirt """ + from collections import defaultdict from django.conf import settings + from evennia import DefaultCharacter, DefaultObject, default_cmds from evennia.commands.default.muxcommand import MuxCommand from evennia.utils import ( diff --git a/evennia/contrib/game_systems/containers/containers.py b/evennia/contrib/game_systems/containers/containers.py index 66c31b7175..be718d526e 100644 --- a/evennia/contrib/game_systems/containers/containers.py +++ b/evennia/contrib/game_systems/containers/containers.py @@ -30,6 +30,7 @@ or implement the same locks/hooks in your own typeclasses. at_pre_get_from(getter, target, **kwargs) - called with the pre-get hooks at_pre_put_in(putter, target, **kwargs) - called with the pre-put hooks """ + from django.conf import settings from evennia import AttributeProperty, CmdSet, DefaultObject diff --git a/evennia/contrib/game_systems/crafting/crafting.py b/evennia/contrib/game_systems/crafting/crafting.py index 875e843d5f..254d8aa458 100644 --- a/evennia/contrib/game_systems/crafting/crafting.py +++ b/evennia/contrib/game_systems/crafting/crafting.py @@ -615,9 +615,11 @@ class CraftingRecipe(CraftingRecipeBase): ) else: self.output_names = [ - prot.get("key", prot.get("typeclass", "unnamed")) - if isinstance(prot, dict) - else str(prot) + ( + prot.get("key", prot.get("typeclass", "unnamed")) + if isinstance(prot, dict) + else str(prot) + ) for prot in self.output_prototypes ] diff --git a/evennia/contrib/game_systems/gendersub/tests.py b/evennia/contrib/game_systems/gendersub/tests.py index c53a65db36..842f1d1c20 100644 --- a/evennia/contrib/game_systems/gendersub/tests.py +++ b/evennia/contrib/game_systems/gendersub/tests.py @@ -3,7 +3,6 @@ Test gendersub contrib. """ - from mock import patch from evennia.commands.default.tests import BaseEvenniaCommandTest diff --git a/evennia/contrib/game_systems/multidescer/multidescer.py b/evennia/contrib/game_systems/multidescer/multidescer.py index c32e92eddc..177437206a 100644 --- a/evennia/contrib/game_systems/multidescer/multidescer.py +++ b/evennia/contrib/game_systems/multidescer/multidescer.py @@ -25,6 +25,7 @@ Reload the server and you should have the +desc command available (it will replace the default `desc` command). """ + import re from evennia import default_cmds diff --git a/evennia/contrib/grid/extended_room/extended_room.py b/evennia/contrib/grid/extended_room/extended_room.py index 97dec6056e..882b235576 100644 --- a/evennia/contrib/grid/extended_room/extended_room.py +++ b/evennia/contrib/grid/extended_room/extended_room.py @@ -47,8 +47,17 @@ from collections import deque from django.conf import settings from django.db.models import Q -from evennia import (CmdSet, DefaultRoom, EvEditor, FuncParser, - InterruptCommand, default_cmds, gametime, utils) + +from evennia import ( + CmdSet, + DefaultRoom, + EvEditor, + FuncParser, + InterruptCommand, + default_cmds, + gametime, + utils, +) from evennia.typeclasses.attributes import AttributeProperty from evennia.utils.utils import list_to_string, repeat @@ -814,7 +823,6 @@ class CmdExtendedRoomDesc(default_cmds.CmdDesc): class CmdExtendedRoomDetail(default_cmds.MuxCommand): - """ sets a detail on a room diff --git a/evennia/contrib/grid/extended_room/tests.py b/evennia/contrib/grid/extended_room/tests.py index 2a8ed62256..a5026a42a6 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/ingame_map_display/ingame_map_display.py b/evennia/contrib/grid/ingame_map_display/ingame_map_display.py index f6369c7c31..3dec9a1d26 100644 --- a/evennia/contrib/grid/ingame_map_display/ingame_map_display.py +++ b/evennia/contrib/grid/ingame_map_display/ingame_map_display.py @@ -56,6 +56,7 @@ This changes the default map width/height. 2-5 for most clients is sensible. If you don't want the player to be able to specify the size of the map, ignore any arguments passed into the Map command. """ + import time from django.conf import settings diff --git a/evennia/contrib/grid/ingame_map_display/tests.py b/evennia/contrib/grid/ingame_map_display/tests.py index 4af1cdc41c..d047957c1e 100644 --- a/evennia/contrib/grid/ingame_map_display/tests.py +++ b/evennia/contrib/grid/ingame_map_display/tests.py @@ -3,7 +3,6 @@ Tests of ingame_map_display. """ - from typeclasses import exits, rooms from evennia.commands.default.tests import BaseEvenniaCommandTest diff --git a/evennia/contrib/grid/simpledoor/tests.py b/evennia/contrib/grid/simpledoor/tests.py index 9c0d3353c1..a97d31da92 100644 --- a/evennia/contrib/grid/simpledoor/tests.py +++ b/evennia/contrib/grid/simpledoor/tests.py @@ -3,7 +3,6 @@ Tests of simpledoor. """ - from evennia.commands.default.tests import BaseEvenniaCommandTest from . import simpledoor diff --git a/evennia/contrib/grid/xyzgrid/__init__.py b/evennia/contrib/grid/xyzgrid/__init__.py index cc2ad276e1..f086fdaa2b 100644 --- a/evennia/contrib/grid/xyzgrid/__init__.py +++ b/evennia/contrib/grid/xyzgrid/__init__.py @@ -2,6 +2,7 @@ XYZGrid - Griatch 2021 """ + from . import ( example, launchcmd, diff --git a/evennia/contrib/grid/xyzgrid/prototypes.py b/evennia/contrib/grid/xyzgrid/prototypes.py index 2c0341dc24..8f7804dc6f 100644 --- a/evennia/contrib/grid/xyzgrid/prototypes.py +++ b/evennia/contrib/grid/xyzgrid/prototypes.py @@ -14,6 +14,7 @@ and/or {'prototype_parent': 'xyz_exit', ...} """ + from django.conf import settings try: diff --git a/evennia/contrib/grid/xyzgrid/tests.py b/evennia/contrib/grid/xyzgrid/tests.py index a3cd7441d1..602f1bfed0 100644 --- a/evennia/contrib/grid/xyzgrid/tests.py +++ b/evennia/contrib/grid/xyzgrid/tests.py @@ -3,14 +3,15 @@ Tests for the XYZgrid system. """ + 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 41135b52ba..9eb494dac0 100644 --- a/evennia/contrib/grid/xyzgrid/xymap.py +++ b/evennia/contrib/grid/xyzgrid/xymap.py @@ -92,6 +92,7 @@ See `./example.py` for a full grid example. ---- """ + import pickle from collections import defaultdict from os import mkdir @@ -108,6 +109,7 @@ except ImportError as err: "the SciPy package. Install with `pip install scipy'." ) from django.conf import settings + from evennia.prototypes import prototypes as protlib from evennia.prototypes.spawner import flatten_prototype from evennia.utils import logger @@ -172,6 +174,7 @@ class XYMap: but recommended for readability! """ + mapcorner_symbol = "+" max_pathfinding_length = 500 empty_symbol = " " @@ -475,10 +478,10 @@ class XYMap: max_X, max_Y = max(max_X, iX), max(max_Y, iY) node_index += 1 - xygrid[ix][iy] = XYgrid[iX][iY] = node_index_map[ - node_index - ] = mapnode_or_link_class( - x=ix, y=iy, Z=self.Z, node_index=node_index, symbol=char, xymap=self + xygrid[ix][iy] = XYgrid[iX][iY] = node_index_map[node_index] = ( + mapnode_or_link_class( + x=ix, y=iy, Z=self.Z, node_index=node_index, symbol=char, xymap=self + ) ) else: @@ -668,8 +671,7 @@ class XYMap: """ global _XYZROOMCLASS if not _XYZROOMCLASS: - from evennia.contrib.grid.xyzgrid.xyzroom import \ - XYZRoom as _XYZROOMCLASS + from evennia.contrib.grid.xyzgrid.xyzroom import XYZRoom as _XYZROOMCLASS x, y = xy wildcard = "*" spawned = [] diff --git a/evennia/contrib/grid/xyzgrid/xymap_legend.py b/evennia/contrib/grid/xyzgrid/xymap_legend.py index 1a42fc3eb4..8a205c48d2 100644 --- a/evennia/contrib/grid/xyzgrid/xymap_legend.py +++ b/evennia/contrib/grid/xyzgrid/xymap_legend.py @@ -20,11 +20,11 @@ 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 -from .utils import (BIGVAL, MAPSCAN, REVERSE_DIRECTIONS, MapError, - MapParserError) +from .utils import BIGVAL, MAPSCAN, REVERSE_DIRECTIONS, MapError, MapParserError NodeTypeclass = None ExitTypeclass = None @@ -844,6 +844,7 @@ class SmartRerouterMapLink(MapLink): /| """ + multilink = True def get_direction(self, start_direction): diff --git a/evennia/contrib/grid/xyzgrid/xyzgrid.py b/evennia/contrib/grid/xyzgrid/xyzgrid.py index 2065eeea12..56626c8cee 100644 --- a/evennia/contrib/grid/xyzgrid/xyzgrid.py +++ b/evennia/contrib/grid/xyzgrid/xyzgrid.py @@ -16,6 +16,7 @@ The grid has three main functions: """ + from evennia.scripts.scripts import DefaultScript from evennia.utils import logger from evennia.utils.utils import variable_from_module diff --git a/evennia/contrib/rpg/buffs/__init__.py b/evennia/contrib/rpg/buffs/__init__.py index d3e73893db..c08e1d8ceb 100644 --- a/evennia/contrib/rpg/buffs/__init__.py +++ b/evennia/contrib/rpg/buffs/__init__.py @@ -1,4 +1,3 @@ -from .buff import (BaseBuff, BuffableProperty, BuffHandler, CmdBuff, # noqa - Mod, cleanup_buffs, tick_buff) -from .samplebuffs import (Exploit, Exploited, Leeching, Poison, Sated, # noqa - StatBuff) +from .buff import CmdBuff # noqa +from .buff import BaseBuff, BuffableProperty, BuffHandler, Mod, cleanup_buffs, tick_buff +from .samplebuffs import Exploit, Exploited, Leeching, Poison, Sated, StatBuff # noqa diff --git a/evennia/contrib/rpg/buffs/buff.py b/evennia/contrib/rpg/buffs/buff.py index e09a070125..d77d47dc9f 100644 --- a/evennia/contrib/rpg/buffs/buff.py +++ b/evennia/contrib/rpg/buffs/buff.py @@ -98,6 +98,7 @@ You can see all the features of the `BaseBuff` class below, or browse `samplebuf many attributes and hook methods you can overload to create complex, interrelated buffs. """ + import time from random import random diff --git a/evennia/contrib/rpg/buffs/tests.py b/evennia/contrib/rpg/buffs/tests.py index 091db9acb6..50dea4da23 100644 --- a/evennia/contrib/rpg/buffs/tests.py +++ b/evennia/contrib/rpg/buffs/tests.py @@ -1,6 +1,7 @@ """ Tests for the buff system contrib """ + from unittest.mock import Mock, call, patch from evennia import DefaultObject, create_object diff --git a/evennia/contrib/rpg/character_creator/character_creator.py b/evennia/contrib/rpg/character_creator/character_creator.py index 8d1db4b6cc..994093b427 100644 --- a/evennia/contrib/rpg/character_creator/character_creator.py +++ b/evennia/contrib/rpg/character_creator/character_creator.py @@ -15,6 +15,7 @@ and examples, including how to allow players to choose and confirm character names from within the menu. """ + import string from random import choices diff --git a/evennia/contrib/rpg/dice/dice.py b/evennia/contrib/rpg/dice/dice.py index 5551ca7f64..5eec8df025 100644 --- a/evennia/contrib/rpg/dice/dice.py +++ b/evennia/contrib/rpg/dice/dice.py @@ -57,6 +57,7 @@ of the roll separately: """ + import re from ast import literal_eval from random import randint diff --git a/evennia/contrib/rpg/rpsystem/rplanguage.py b/evennia/contrib/rpg/rpsystem/rplanguage.py index 4be5782acc..a9a5cddade 100644 --- a/evennia/contrib/rpg/rpsystem/rplanguage.py +++ b/evennia/contrib/rpg/rpsystem/rplanguage.py @@ -137,6 +137,7 @@ This allows to quickly build a large corpus of translated words that never change (if this is desired). """ + import re from collections import defaultdict from random import choice, randint diff --git a/evennia/contrib/rpg/rpsystem/rpsystem.py b/evennia/contrib/rpg/rpsystem/rpsystem.py index bf808ff307..7cb9de81ab 100644 --- a/evennia/contrib/rpg/rpsystem/rpsystem.py +++ b/evennia/contrib/rpg/rpsystem/rpsystem.py @@ -148,19 +148,25 @@ Extra Installation Instructions: `type/reset/force me = typeclasses.characters.Character` """ + import re from collections import defaultdict 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 04d4ef49de..df40eb367b 100644 --- a/evennia/contrib/rpg/rpsystem/tests.py +++ b/evennia/contrib/rpg/rpsystem/tests.py @@ -2,9 +2,11 @@ Tests for RP system """ + import time from anything import Anything + from evennia import DefaultObject, create_object, default_cmds from evennia.commands.default import building from evennia.commands.default.tests import BaseEvenniaCommandTest @@ -426,11 +428,11 @@ class TestRPSystemCommands(BaseEvenniaCommandTest): self.call(default_cmds.CmdLook(), "Mushroom-2", expected_third_call) # FAILS expected_fourth_call = "Alias(es) for 'Mushroom' set to 'fungus'." - self.call(building.CmdSetObjAlias(), "Mushroom-1 = fungus", expected_fourth_call) #PASSES + self.call(building.CmdSetObjAlias(), "Mushroom-1 = fungus", expected_fourth_call) # PASSES expected_fifth_call = [ "More than one match for 'Mushroom' (please narrow target):", f" Mushroom-1 [fungus]", f" Mushroom-2", ] - self.call(default_cmds.CmdLook(), "Mushroom", "\n".join(expected_fifth_call)) # PASSES + self.call(default_cmds.CmdLook(), "Mushroom", "\n".join(expected_fifth_call)) # PASSES diff --git a/evennia/contrib/rpg/traits/traits.py b/evennia/contrib/rpg/traits/traits.py index 1a2b8b99b7..fbcbeda34a 100644 --- a/evennia/contrib/rpg/traits/traits.py +++ b/evennia/contrib/rpg/traits/traits.py @@ -452,7 +452,6 @@ class Character(DefaultCharacter): """ - from functools import total_ordering from time import time diff --git a/evennia/contrib/tutorials/bodyfunctions/bodyfunctions.py b/evennia/contrib/tutorials/bodyfunctions/bodyfunctions.py index 009928da1f..90afb46f76 100644 --- a/evennia/contrib/tutorials/bodyfunctions/bodyfunctions.py +++ b/evennia/contrib/tutorials/bodyfunctions/bodyfunctions.py @@ -13,6 +13,7 @@ The script will only send messages to the object it is stored on, so make sure to put it on yourself or you won't see any messages! """ + import random from evennia import DefaultScript diff --git a/evennia/contrib/tutorials/bodyfunctions/tests.py b/evennia/contrib/tutorials/bodyfunctions/tests.py index 2c7d6c46e6..564f7ab6e4 100644 --- a/evennia/contrib/tutorials/bodyfunctions/tests.py +++ b/evennia/contrib/tutorials/bodyfunctions/tests.py @@ -2,6 +2,7 @@ Tests for the bodyfunctions. """ + from mock import Mock, patch from evennia.utils.test_resources import BaseEvenniaTest diff --git a/evennia/contrib/tutorials/evadventure/ai.py b/evennia/contrib/tutorials/evadventure/ai.py index 90338e968c..6a65943a38 100644 --- a/evennia/contrib/tutorials/evadventure/ai.py +++ b/evennia/contrib/tutorials/evadventure/ai.py @@ -49,9 +49,9 @@ class AIHandler: def __init__(self, obj): self.obj = obj - self.ai_state = obj.attributes.get(self.attribute_name, - category=self.attribute_category, - default="idle") + self.ai_state = obj.attributes.get( + self.attribute_name, category=self.attribute_category, default="idle" + ) def set_state(self, state): self.ai_state = state @@ -122,6 +122,7 @@ class AIMixin: of multiple inheritance. In a real game, you would probably want to use a mixin like this. """ + @lazy_property def ai(self): return AIHandler(self) diff --git a/evennia/contrib/tutorials/evadventure/chargen.py b/evennia/contrib/tutorials/evadventure/chargen.py index f27012e4df..a1b429e3d1 100644 --- a/evennia/contrib/tutorials/evadventure/chargen.py +++ b/evennia/contrib/tutorials/evadventure/chargen.py @@ -2,6 +2,7 @@ EvAdventure character generation. """ + from django.conf import settings from evennia.objects.models import ObjectDB diff --git a/evennia/contrib/tutorials/evadventure/combat_turnbased.py b/evennia/contrib/tutorials/evadventure/combat_turnbased.py index fdea4a0038..b67c0db028 100644 --- a/evennia/contrib/tutorials/evadventure/combat_turnbased.py +++ b/evennia/contrib/tutorials/evadventure/combat_turnbased.py @@ -18,7 +18,6 @@ action that takes several vulnerable turns to complete. """ - import random from collections import defaultdict @@ -26,9 +25,15 @@ from evennia import AttributeProperty, CmdSet, Command, EvMenu from evennia.utils import inherits_from, list_to_string from .characters import EvAdventureCharacter -from .combat_base import (CombatAction, CombatActionAttack, CombatActionHold, - CombatActionStunt, CombatActionUseItem, - CombatActionWield, EvAdventureCombatBaseHandler) +from .combat_base import ( + CombatAction, + CombatActionAttack, + CombatActionHold, + CombatActionStunt, + CombatActionUseItem, + CombatActionWield, + EvAdventureCombatBaseHandler, +) from .enums import Ability diff --git a/evennia/contrib/tutorials/evadventure/combat_twitch.py b/evennia/contrib/tutorials/evadventure/combat_twitch.py index 9e860ffff8..d8a8d38b3f 100644 --- a/evennia/contrib/tutorials/evadventure/combat_twitch.py +++ b/evennia/contrib/tutorials/evadventure/combat_twitch.py @@ -6,15 +6,27 @@ 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 (CombatActionAttack, CombatActionHold, - CombatActionStunt, CombatActionUseItem, - CombatActionWield, EvAdventureCombatBaseHandler) +from .combat_base import ( + CombatActionAttack, + CombatActionHold, + CombatActionStunt, + CombatActionUseItem, + CombatActionWield, + EvAdventureCombatBaseHandler, +) from .enums import ABILITY_REVERSE_MAP diff --git a/evennia/contrib/tutorials/evadventure/dungeon.py b/evennia/contrib/tutorials/evadventure/dungeon.py index d03da74576..6e56bf0562 100644 --- a/evennia/contrib/tutorials/evadventure/dungeon.py +++ b/evennia/contrib/tutorials/evadventure/dungeon.py @@ -105,10 +105,10 @@ class EvAdventureDungeonRoom(EvAdventureRoom): """ self.tags.add("not_clear", category="dungeon_room") + def clear_room(self): self.tags.remove("not_clear", category="dungeon_room") - @property def is_room_clear(self): return not bool(self.tags.get("not_clear", category="dungeon_room")) @@ -146,9 +146,7 @@ class EvAdventureDungeonExit(DefaultExit): dungeon_branch = self.location.db.dungeon_branch if target_location == self.location: # destination points back to us - create a new room - self.destination = target_location = dungeon_branch.new_room( - self - ) + self.destination = target_location = dungeon_branch.new_room(self) dungeon_branch.register_exit_traversed(self) super().at_traverse(traversing_object, target_location, **kwargs) diff --git a/evennia/contrib/tutorials/evadventure/enums.py b/evennia/contrib/tutorials/evadventure/enums.py index 6ba77d82f9..cb7d4636e5 100644 --- a/evennia/contrib/tutorials/evadventure/enums.py +++ b/evennia/contrib/tutorials/evadventure/enums.py @@ -17,6 +17,7 @@ To get the `value` of an enum (must always be hashable, useful for Attribute loo ---- """ + from enum import Enum diff --git a/evennia/contrib/tutorials/evadventure/npcs.py b/evennia/contrib/tutorials/evadventure/npcs.py index 755ce70940..2afd9f73a9 100644 --- a/evennia/contrib/tutorials/evadventure/npcs.py +++ b/evennia/contrib/tutorials/evadventure/npcs.py @@ -2,6 +2,7 @@ EvAdventure NPCs. This includes both friends and enemies, only separated by their AI. """ + from random import choice from evennia import DefaultCharacter @@ -253,6 +254,7 @@ class EvAdventureMob(EvAdventureNPC): Mob (mobile) NPC; this is usually an enemy. """ + # change this to make the mob more or less likely to perform different actions combat_probabilities = { "hold": 0.0, diff --git a/evennia/contrib/tutorials/evadventure/quests.py b/evennia/contrib/tutorials/evadventure/quests.py index 38476a058e..5e862ede29 100644 --- a/evennia/contrib/tutorials/evadventure/quests.py +++ b/evennia/contrib/tutorials/evadventure/quests.py @@ -59,7 +59,6 @@ class EvAdventureQuest: desc = "This is the base quest class" start_step = "start" - # help entries for quests (could also be methods) help_start = "You need to start first" help_end = "You need to end the quest" @@ -191,8 +190,9 @@ class EvAdventureQuest: """ if self.status in ("abandoned", "completed", "failed"): - help_resource = getattr(self, f"help_{self.status}", - f"You have {self.status} this quest.") + help_resource = getattr( + self, f"help_{self.status}", f"You have {self.status} this quest." + ) else: help_resource = getattr(self, f"help_{self.current_step}", "No help available.") @@ -203,7 +203,6 @@ class EvAdventureQuest: # normally it's just a string return str(help_resource) - # step methods and hooks def step_start(self, *args, **kwargs): @@ -377,6 +376,7 @@ class CmdQuests(Command): quest """ + key = "quests" aliases = ["quest"] @@ -399,4 +399,3 @@ class CmdQuests(Command): for quest in quests: self.msg(f"Quest {quest.key}: {quest.status}") - diff --git a/evennia/contrib/tutorials/evadventure/rules.py b/evennia/contrib/tutorials/evadventure/rules.py index b0075b8e1f..9ad38f4f93 100644 --- a/evennia/contrib/tutorials/evadventure/rules.py +++ b/evennia/contrib/tutorials/evadventure/rules.py @@ -7,6 +7,7 @@ and determining what the outcome is. ---- """ + from random import randint from .enums import Ability diff --git a/evennia/contrib/tutorials/evadventure/tests/test_ai.py b/evennia/contrib/tutorials/evadventure/tests/test_ai.py index f96b4fb478..16fff27c98 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_ai.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_ai.py @@ -2,6 +2,7 @@ Test the ai module. """ + from unittest.mock import Mock, patch from evennia import create_object diff --git a/evennia/contrib/tutorials/evadventure/tests/test_equipment.py b/evennia/contrib/tutorials/evadventure/tests/test_equipment.py index 1dbe647887..58c53101e9 100644 --- a/evennia/contrib/tutorials/evadventure/tests/test_equipment.py +++ b/evennia/contrib/tutorials/evadventure/tests/test_equipment.py @@ -3,7 +3,6 @@ Test the EvAdventure equipment handler. """ - from unittest.mock import MagicMock, patch from parameterized import parameterized diff --git a/evennia/contrib/tutorials/evadventure/utils.py b/evennia/contrib/tutorials/evadventure/utils.py index 6fb12de138..25152c236f 100644 --- a/evennia/contrib/tutorials/evadventure/utils.py +++ b/evennia/contrib/tutorials/evadventure/utils.py @@ -17,7 +17,6 @@ Attacks using |w{attack_type_name}|n against |w{defense_type_name}|n Damage roll: |w{damage_roll}|n""".strip() - def get_obj_stats(obj, owner=None): """ Get a string of stats about the object. diff --git a/evennia/contrib/tutorials/red_button/red_button.py b/evennia/contrib/tutorials/red_button/red_button.py index 51ee69060f..b4c9f74f3a 100644 --- a/evennia/contrib/tutorials/red_button/red_button.py +++ b/evennia/contrib/tutorials/red_button/red_button.py @@ -31,6 +31,7 @@ Timers are handled by persistent delays on the button. These are examples of such as when closing the lid and un-blinding a character. """ + import random from evennia import CmdSet, Command, DefaultObject diff --git a/evennia/contrib/tutorials/talking_npc/tests.py b/evennia/contrib/tutorials/talking_npc/tests.py index 9a33eccad0..92bbb630b0 100644 --- a/evennia/contrib/tutorials/talking_npc/tests.py +++ b/evennia/contrib/tutorials/talking_npc/tests.py @@ -2,6 +2,7 @@ Tutorial - talking NPC tests. """ + from evennia.commands.default.tests import BaseEvenniaCommandTest from evennia.utils.create import create_object diff --git a/evennia/contrib/tutorials/tutorial_world/rooms.py b/evennia/contrib/tutorials/tutorial_world/rooms.py index 6d27118812..42c4f6fc2d 100644 --- a/evennia/contrib/tutorials/tutorial_world/rooms.py +++ b/evennia/contrib/tutorials/tutorial_world/rooms.py @@ -9,7 +9,6 @@ in a separate module (e.g. if they could have been re-used elsewhere.) """ - import random # the system error-handling module is defined in the settings. We load the diff --git a/evennia/contrib/utils/auditing/outputs.py b/evennia/contrib/utils/auditing/outputs.py index d6d4f504ef..cafae2b118 100644 --- a/evennia/contrib/utils/auditing/outputs.py +++ b/evennia/contrib/utils/auditing/outputs.py @@ -13,6 +13,7 @@ the easiest place to do it. Write a method and invoke it via Evennia contribution - Johnny 2017 """ + import json import syslog diff --git a/evennia/contrib/utils/auditing/server.py b/evennia/contrib/utils/auditing/server.py index 6646d07f32..2337b457c9 100644 --- a/evennia/contrib/utils/auditing/server.py +++ b/evennia/contrib/utils/auditing/server.py @@ -5,6 +5,7 @@ user inputs and system outputs. Evennia contribution - Johnny 2017 """ + import os import re import socket diff --git a/evennia/contrib/utils/fieldfill/fieldfill.py b/evennia/contrib/utils/fieldfill/fieldfill.py index 625002611d..b94c8e5499 100644 --- a/evennia/contrib/utils/fieldfill/fieldfill.py +++ b/evennia/contrib/utils/fieldfill/fieldfill.py @@ -138,6 +138,7 @@ Optional: object dbrefs). For boolean fields, return '0' or '1' to set the field to False or True. """ + import evennia from evennia import Command from evennia.utils import delay, evmenu, evtable, list_to_string, logger diff --git a/evennia/contrib/utils/random_string_generator/random_string_generator.py b/evennia/contrib/utils/random_string_generator/random_string_generator.py index 21fb68fe60..708064caf8 100644 --- a/evennia/contrib/utils/random_string_generator/random_string_generator.py +++ b/evennia/contrib/utils/random_string_generator/random_string_generator.py @@ -59,7 +59,6 @@ from evennia.utils.create import create_script class RejectedRegex(RuntimeError): - """The provided regular expression has been rejected. More details regarding why this error occurred will be provided in @@ -72,14 +71,12 @@ class RejectedRegex(RuntimeError): class ExhaustedGenerator(RuntimeError): - """The generator hasn't any available strings to generate anymore.""" pass class RandomStringGeneratorScript(DefaultScript): - """ The global script to hold all generators. @@ -99,7 +96,6 @@ class RandomStringGeneratorScript(DefaultScript): class RandomStringGenerator: - """ A generator class to generate pseudo-random strings with a rule. diff --git a/evennia/game_template/typeclasses/characters.py b/evennia/game_template/typeclasses/characters.py index c0cdc30f08..b022c1f293 100644 --- a/evennia/game_template/typeclasses/characters.py +++ b/evennia/game_template/typeclasses/characters.py @@ -7,6 +7,7 @@ is setup to be the "default" character type created by the default creation commands. """ + from evennia.objects.objects import DefaultCharacter from .objects import ObjectParent diff --git a/evennia/game_template/typeclasses/exits.py b/evennia/game_template/typeclasses/exits.py index 8ccd996b8b..3a53753c2e 100644 --- a/evennia/game_template/typeclasses/exits.py +++ b/evennia/game_template/typeclasses/exits.py @@ -6,6 +6,7 @@ set and has a single command defined on itself with the same name as its key, for allowing Characters to traverse the exit to its destination. """ + from evennia.objects.objects import DefaultExit from .objects import ObjectParent diff --git a/evennia/game_template/typeclasses/objects.py b/evennia/game_template/typeclasses/objects.py index b8aab3eeb6..11b7363505 100644 --- a/evennia/game_template/typeclasses/objects.py +++ b/evennia/game_template/typeclasses/objects.py @@ -10,6 +10,7 @@ the other types, you can do so by adding this as a multiple inheritance. """ + from evennia.objects.objects import DefaultObject diff --git a/evennia/game_template/web/admin/urls.py b/evennia/game_template/web/admin/urls.py index 196d574160..c42f8dc16d 100644 --- a/evennia/game_template/web/admin/urls.py +++ b/evennia/game_template/web/admin/urls.py @@ -6,7 +6,6 @@ The main web/urls.py includes these routes for all urls starting with `admin/` """ - from django.urls import path from evennia.web.admin.urls import urlpatterns as evennia_admin_urlpatterns diff --git a/evennia/game_template/web/urls.py b/evennia/game_template/web/urls.py index 673a10bf08..3f306400cd 100644 --- a/evennia/game_template/web/urls.py +++ b/evennia/game_template/web/urls.py @@ -12,6 +12,7 @@ should modify urls.py in those sub directories. Search the Django documentation for "URL dispatcher" for more help. """ + from django.urls import include, path # default evennia patterns diff --git a/evennia/help/manager.py b/evennia/help/manager.py index ff8af1e7c9..58773a5472 100644 --- a/evennia/help/manager.py +++ b/evennia/help/manager.py @@ -1,6 +1,7 @@ """ Custom manager for HelpEntry objects. """ + from django.db import IntegrityError from evennia.server import signals diff --git a/evennia/help/models.py b/evennia/help/models.py index c86cab61a8..e9bdcf9d33 100644 --- a/evennia/help/models.py +++ b/evennia/help/models.py @@ -9,6 +9,7 @@ forms of help that do not concern commands, like information about the game world, policy info, rules and similar. """ + from django.contrib.contenttypes.models import ContentType from django.db import models from django.urls import reverse diff --git a/evennia/help/utils.py b/evennia/help/utils.py index 5ef3157ca9..716122accf 100644 --- a/evennia/help/utils.py +++ b/evennia/help/utils.py @@ -5,6 +5,7 @@ sub-categories. This is used primarily by the default `help` command. """ + import re from django.conf import settings diff --git a/evennia/locks/lockfuncs.py b/evennia/locks/lockfuncs.py index d477b5a1ca..4121107b22 100644 --- a/evennia/locks/lockfuncs.py +++ b/evennia/locks/lockfuncs.py @@ -13,7 +13,6 @@ a certain object type. """ - from ast import literal_eval from django.conf import settings diff --git a/evennia/objects/manager.py b/evennia/objects/manager.py index 7b5f51cb75..f962d7e55a 100644 --- a/evennia/objects/manager.py +++ b/evennia/objects/manager.py @@ -1,11 +1,13 @@ """ Custom manager for Objects. """ + import re from django.conf import settings from django.db.models import Q from django.db.models.fields import exceptions + from evennia.server import signals from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager from evennia.utils.utils import ( diff --git a/evennia/objects/models.py b/evennia/objects/models.py index a282bafe0f..5d4bfd4acf 100644 --- a/evennia/objects/models.py +++ b/evennia/objects/models.py @@ -13,12 +13,14 @@ Attributes are separate objects that store values persistently onto the database object. Like everything else, they can be accessed transparently through the decorating TypeClass. """ + from collections import defaultdict from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.core.validators import validate_comma_separated_integer_list from django.db import models + from evennia.objects.manager import ObjectDBManager from evennia.typeclasses.models import TypedObject from evennia.utils import logger diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 57d29dd722..f11b43bc51 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -5,14 +5,16 @@ These are the (default) starting points for all in-game visible entities. """ + import time import typing 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 @@ -22,9 +24,17 @@ from evennia.server.signals import SIGNAL_EXIT_TRAVERSED from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler from evennia.typeclasses.models import TypeclassBase from evennia.utils import ansi, create, funcparser, logger, search -from evennia.utils.utils import (class_from_module, compress_whitespace, dbref, - is_iter, iter_to_str, lazy_property, - make_iter, to_str, variable_from_module) +from evennia.utils.utils import ( + class_from_module, + compress_whitespace, + dbref, + is_iter, + iter_to_str, + lazy_property, + make_iter, + to_str, + variable_from_module, +) _INFLECT = inflect.engine() _MULTISESSION_MODE = settings.MULTISESSION_MODE @@ -955,9 +965,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): # director-stance replacements outmessage = outmessage.format_map( { - key: obj.get_display_name(looker=receiver) - if hasattr(obj, "get_display_name") - else str(obj) + key: ( + obj.get_display_name(looker=receiver) + if hasattr(obj, "get_display_name") + else str(obj) + ) for key, obj in mapping.items() } ) @@ -1419,10 +1431,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): method to implement custom visibility mechanics. """ - return [obj for obj in obj_list - if (obj.access(looker, "view") - and obj.access(looker, "search", default=True)) - ] + return [ + obj + for obj in obj_list + if (obj.access(looker, "view") and obj.access(looker, "search", default=True)) + ] # name and return_appearance hooks @@ -1522,7 +1535,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): return key, key if kwargs.get("return_string"): - return singular if count==1 else plural + return singular if count == 1 else plural return singular, plural @@ -1579,8 +1592,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): str: The character display data. """ - characters = self.filter_visible(self.contents_get(content_type="character"), looker, - **kwargs) + characters = self.filter_visible( + self.contents_get(content_type="character"), looker, **kwargs + ) character_names = iter_to_str( char.get_display_name(looker, **kwargs) for char in characters ) @@ -2679,9 +2693,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): "object": self.get_display_name(self), "location": location.get_display_name(self) if location else None, "receiver": None, - "all_receivers": ", ".join(recv.get_display_name(self) for recv in receivers) - if receivers - else None, + "all_receivers": ( + ", ".join(recv.get_display_name(self) for recv in receivers) + if receivers + else None + ), "speech": message, } self_mapping.update(custom_mapping) @@ -2701,9 +2717,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): "object": self.get_display_name(receiver), "location": location.get_display_name(receiver), "receiver": receiver.get_display_name(receiver), - "all_receivers": ", ".join(recv.get_display_name(recv) for recv in receivers) - if receivers - else None, + "all_receivers": ( + ", ".join(recv.get_display_name(recv) for recv in receivers) + if receivers + else None + ), } receiver_mapping.update(individual_mapping) receiver_mapping.update(custom_mapping) diff --git a/evennia/objects/tests.py b/evennia/objects/tests.py index abc2adecdb..de23269cdf 100644 --- a/evennia/objects/tests.py +++ b/evennia/objects/tests.py @@ -191,6 +191,7 @@ class DefaultObjectTest(BaseEvenniaTest): self.obj1.get_numbered_name(1, self.char1, return_string=True, no_article=True), "Obj" ) + class TestObjectManager(BaseEvenniaTest): "Test object manager methods" diff --git a/evennia/prototypes/spawner.py b/evennia/prototypes/spawner.py index 20a39bf4ac..b77651a6db 100644 --- a/evennia/prototypes/spawner.py +++ b/evennia/prototypes/spawner.py @@ -132,7 +132,6 @@ prototype, override its name with an empty dict. """ - import copy import hashlib import time diff --git a/evennia/scripts/models.py b/evennia/scripts/models.py index 6bff24c571..e2f98dea4c 100644 --- a/evennia/scripts/models.py +++ b/evennia/scripts/models.py @@ -24,6 +24,7 @@ Common examples of uses of Scripts: - Give the account/object a time-limited bonus/effect """ + from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.db import models diff --git a/evennia/scripts/monitorhandler.py b/evennia/scripts/monitorhandler.py index 78ad71e77d..6789d3b55f 100644 --- a/evennia/scripts/monitorhandler.py +++ b/evennia/scripts/monitorhandler.py @@ -10,6 +10,7 @@ functionality: an action whenever that Attribute *changes* for whatever reason. """ + import inspect from collections import defaultdict diff --git a/evennia/scripts/scripthandler.py b/evennia/scripts/scripthandler.py index 8b8eb4bb45..720dd6e3a6 100644 --- a/evennia/scripts/scripthandler.py +++ b/evennia/scripts/scripthandler.py @@ -5,6 +5,7 @@ added to all game objects. You access it through the property `scripts` on the game object. """ + from django.utils.translation import gettext as _ from evennia.scripts.models import ScriptDB diff --git a/evennia/scripts/taskhandler.py b/evennia/scripts/taskhandler.py index b47a7f8166..a6539fb1ad 100644 --- a/evennia/scripts/taskhandler.py +++ b/evennia/scripts/taskhandler.py @@ -205,7 +205,6 @@ class TaskHandlerTask: class TaskHandler: - """A light singleton wrapper allowing to access permanent tasks. When `utils.delay` is called, the task handler is used to create diff --git a/evennia/scripts/tests.py b/evennia/scripts/tests.py index 6d251eed54..8bf6983e21 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 @@ -17,7 +19,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, EvenniaTest -from parameterized import parameterized class TestScript(BaseEvenniaTest): diff --git a/evennia/scripts/tickerhandler.py b/evennia/scripts/tickerhandler.py index 7dd702cca3..3968cee69a 100644 --- a/evennia/scripts/tickerhandler.py +++ b/evennia/scripts/tickerhandler.py @@ -65,6 +65,7 @@ a custom handler one can make a custom `AT_STARTSTOP_MODULE` entry to call the handler's `save()` and `restore()` methods when the server reboots. """ + import inspect from django.core.exceptions import ObjectDoesNotExist diff --git a/evennia/server/connection_wizard.py b/evennia/server/connection_wizard.py index 2b17c9786b..440a884153 100644 --- a/evennia/server/connection_wizard.py +++ b/evennia/server/connection_wizard.py @@ -2,6 +2,7 @@ Link Evennia to external resources (wizard plugin for evennia_launcher) """ + import pprint import sys from os import path diff --git a/evennia/server/deprecations.py b/evennia/server/deprecations.py index 643f02afdc..a93f075cd9 100644 --- a/evennia/server/deprecations.py +++ b/evennia/server/deprecations.py @@ -4,6 +4,7 @@ checks for. These all print to the terminal. """ + import os diff --git a/evennia/server/game_index_client/client.py b/evennia/server/game_index_client/client.py index 02b9241379..c39c336f70 100644 --- a/evennia/server/game_index_client/client.py +++ b/evennia/server/game_index_client/client.py @@ -2,6 +2,7 @@ The client for sending data to the Evennia Game Index """ + import platform import urllib.error import urllib.parse diff --git a/evennia/server/game_index_client/service.py b/evennia/server/game_index_client/service.py index f4a9899c28..ff5edc1bbd 100644 --- a/evennia/server/game_index_client/service.py +++ b/evennia/server/game_index_client/service.py @@ -2,6 +2,7 @@ Service for integrating the Evennia Game Index client into Evennia. """ + from twisted.application.service import Service from twisted.internet import reactor from twisted.internet.task import LoopingCall diff --git a/evennia/server/initial_setup.py b/evennia/server/initial_setup.py index e886718a5e..4785e98f12 100644 --- a/evennia/server/initial_setup.py +++ b/evennia/server/initial_setup.py @@ -6,7 +6,6 @@ Limbo room). It will also hooks, and then perform an initial restart. Everything starts at handle_setup() """ - import time from django.conf import settings diff --git a/evennia/server/manager.py b/evennia/server/manager.py index 237c40df55..7424fa71b1 100644 --- a/evennia/server/manager.py +++ b/evennia/server/manager.py @@ -1,6 +1,7 @@ """ Custom manager for ServerConfig objects. """ + from django.db import models diff --git a/evennia/server/models.py b/evennia/server/models.py index 8a1b8e58b6..f945409ada 100644 --- a/evennia/server/models.py +++ b/evennia/server/models.py @@ -8,6 +8,7 @@ Config values should usually be set through the manager's conf() method. """ + from django.db import models from evennia.server.manager import ServerConfigManager diff --git a/evennia/server/portal/amp_server.py b/evennia/server/portal/amp_server.py index c9953346a1..67fbd1d1e7 100644 --- a/evennia/server/portal/amp_server.py +++ b/evennia/server/portal/amp_server.py @@ -4,6 +4,7 @@ communication to the AMP clients connecting to it (by default these are the Evennia Server and the evennia launcher). """ + import os import sys from subprocess import STDOUT, Popen @@ -36,7 +37,6 @@ def getenv(): class AMPServerFactory(protocol.ServerFactory): - """ This factory creates AMP Server connection. This acts as the 'Portal'-side communication to the 'Server' process. diff --git a/evennia/server/portal/discord.py b/evennia/server/portal/discord.py index e38c08aea9..0e03ac6481 100644 --- a/evennia/server/portal/discord.py +++ b/evennia/server/portal/discord.py @@ -8,6 +8,7 @@ discord bot set up via https://discord.com/developers/applications with the MESSAGE CONTENT toggle switched on, and your bot token added to `server/conf/secret_settings.py` as your DISCORD_BOT_TOKEN """ + import json import os from io import BytesIO diff --git a/evennia/server/portal/mccp.py b/evennia/server/portal/mccp.py index 43390b19bc..ba748e0010 100644 --- a/evennia/server/portal/mccp.py +++ b/evennia/server/portal/mccp.py @@ -14,6 +14,7 @@ terribly slow connection. This protocol is implemented by the telnet protocol importing mccp_compress and calling it from its write methods. """ + import zlib # negotiations for v1 and v2 of the protocol diff --git a/evennia/server/portal/mssp.py b/evennia/server/portal/mssp.py index 3f57566945..03714cf9da 100644 --- a/evennia/server/portal/mssp.py +++ b/evennia/server/portal/mssp.py @@ -10,6 +10,7 @@ active players and so on. """ + from django.conf import settings from evennia.utils import utils diff --git a/evennia/server/portal/mxp.py b/evennia/server/portal/mxp.py index af3e5d1e0d..a445168c97 100644 --- a/evennia/server/portal/mxp.py +++ b/evennia/server/portal/mxp.py @@ -13,6 +13,7 @@ http://www.mushclient.com/mushclient/mxp.htm http://www.gammon.com.au/mushclient/addingservermxp.htm """ + import re from django.conf import settings diff --git a/evennia/server/portal/naws.py b/evennia/server/portal/naws.py index ab7e892712..b4498e71ea 100644 --- a/evennia/server/portal/naws.py +++ b/evennia/server/portal/naws.py @@ -9,6 +9,7 @@ NAWS allows telnet clients to report their current window size to the client and update it when the size changes """ + from codecs import encode as codecs_encode from django.conf import settings diff --git a/evennia/server/portal/portal.py b/evennia/server/portal/portal.py index b1bf532cf1..99a9e904ff 100644 --- a/evennia/server/portal/portal.py +++ b/evennia/server/portal/portal.py @@ -7,6 +7,7 @@ sets up all the networking features. (this is done automatically by game/evennia.py). """ + import os import sys diff --git a/evennia/server/portal/portalsessionhandler.py b/evennia/server/portal/portalsessionhandler.py index 8a5ed53ce2..cb118893c1 100644 --- a/evennia/server/portal/portalsessionhandler.py +++ b/evennia/server/portal/portalsessionhandler.py @@ -3,7 +3,6 @@ Sessionhandler for portal sessions. """ - import time from collections import deque, namedtuple diff --git a/evennia/server/portal/rss.py b/evennia/server/portal/rss.py index fdd5b32d2b..1499a89f17 100644 --- a/evennia/server/portal/rss.py +++ b/evennia/server/portal/rss.py @@ -5,6 +5,7 @@ This connects an RSS feed to an in-game Evennia channel, sending messages to the channel whenever the feed updates. """ + from django.conf import settings from twisted.internet import task, threads diff --git a/evennia/server/portal/ssh.py b/evennia/server/portal/ssh.py index 0a8e9637e8..294275f198 100644 --- a/evennia/server/portal/ssh.py +++ b/evennia/server/portal/ssh.py @@ -34,9 +34,6 @@ except ImportError: raise ImportError(_SSH_IMPORT_ERROR) from django.conf import settings -from evennia.accounts.models import AccountDB -from evennia.utils import ansi -from evennia.utils.utils import class_from_module, to_str from twisted.conch import interfaces as iconch from twisted.conch.insults import insults from twisted.conch.manhole import Manhole, recvline @@ -46,6 +43,10 @@ from twisted.conch.ssh.userauth import SSHUserAuthServer from twisted.internet import defer, protocol from twisted.python import components +from evennia.accounts.models import AccountDB +from evennia.utils import ansi +from evennia.utils.utils import class_from_module, to_str + _RE_N = re.compile(r"\|n$") _RE_SCREENREADER_REGEX = re.compile( r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE diff --git a/evennia/server/portal/ssl.py b/evennia/server/portal/ssl.py index 032f48d401..0fca77cb69 100644 --- a/evennia/server/portal/ssl.py +++ b/evennia/server/portal/ssl.py @@ -3,6 +3,7 @@ This is a simple context factory for auto-creating SSL keys and certificates. """ + import os import sys diff --git a/evennia/server/portal/suppress_ga.py b/evennia/server/portal/suppress_ga.py index 694f09b73a..cadf007fa9 100644 --- a/evennia/server/portal/suppress_ga.py +++ b/evennia/server/portal/suppress_ga.py @@ -39,9 +39,9 @@ class SuppressGA: self.protocol = protocol self.protocol.protocol_flags["NOGOAHEAD"] = True - self.protocol.protocol_flags[ - "NOPROMPTGOAHEAD" - ] = True # Used to send a GA after a prompt line only, set in TTYPE (per client) + self.protocol.protocol_flags["NOPROMPTGOAHEAD"] = ( + True # Used to send a GA after a prompt line only, set in TTYPE (per client) + ) # tell the client that we prefer to suppress GA ... self.protocol.will(SUPPRESS_GA).addCallbacks(self.will_suppress_ga, self.wont_suppress_ga) diff --git a/evennia/server/portal/telnet_oob.py b/evennia/server/portal/telnet_oob.py index 38012e9170..6fe68ff7a1 100644 --- a/evennia/server/portal/telnet_oob.py +++ b/evennia/server/portal/telnet_oob.py @@ -23,6 +23,7 @@ This implements the following telnet OOB communication protocols: ---- """ + import json import re diff --git a/evennia/server/portal/telnet_ssl.py b/evennia/server/portal/telnet_ssl.py index 46717c0a61..6bf6a0597d 100644 --- a/evennia/server/portal/telnet_ssl.py +++ b/evennia/server/portal/telnet_ssl.py @@ -7,6 +7,7 @@ when starting and will warn if this was not possible. These will appear as files ssl.cert in mygame/server/. """ + import os try: diff --git a/evennia/server/portal/webclient.py b/evennia/server/portal/webclient.py index b74c3eb361..1f35d473ee 100644 --- a/evennia/server/portal/webclient.py +++ b/evennia/server/portal/webclient.py @@ -14,6 +14,7 @@ The most common inputfunc is "text", which takes just the text input from the command line and interprets it as an Evennia Command: `["text", ["look"], {}]` """ + import html import json import re diff --git a/evennia/server/portal/webclient_ajax.py b/evennia/server/portal/webclient_ajax.py index b3fd54357f..2c43017c57 100644 --- a/evennia/server/portal/webclient_ajax.py +++ b/evennia/server/portal/webclient_ajax.py @@ -17,6 +17,7 @@ http://localhost:4001/webclient.) to sessions connected over the webclient. """ + import html import json import re diff --git a/evennia/server/profiling/dummyrunner.py b/evennia/server/profiling/dummyrunner.py index da7c9f43b2..00d3ea9391 100644 --- a/evennia/server/profiling/dummyrunner.py +++ b/evennia/server/profiling/dummyrunner.py @@ -31,7 +31,6 @@ for instructions on how to define this module. """ - import random import sys import time diff --git a/evennia/server/profiling/dummyrunner_settings.py b/evennia/server/profiling/dummyrunner_settings.py index 1dc63b0410..aa70874f50 100644 --- a/evennia/server/profiling/dummyrunner_settings.py +++ b/evennia/server/profiling/dummyrunner_settings.py @@ -57,6 +57,7 @@ commands (such as creating an account and logging in). ---- """ + import random import string diff --git a/evennia/server/server.py b/evennia/server/server.py index 88adad8a6d..3d22808266 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -7,6 +7,7 @@ the networking features. (this is done automatically by evennia/server/server_runner.py). """ + import os import sys diff --git a/evennia/server/serversession.py b/evennia/server/serversession.py index 5177f30f5d..e1573b37c0 100644 --- a/evennia/server/serversession.py +++ b/evennia/server/serversession.py @@ -6,6 +6,7 @@ connection actually happens (so it's the same for telnet, web, ssh etc). It is stored on the Server side (as opposed to protocol-specific sessions which are stored on the Portal side) """ + import time from django.conf import settings diff --git a/evennia/server/service.py b/evennia/server/service.py index bf4a14d598..c1c57e5d56 100644 --- a/evennia/server/service.py +++ b/evennia/server/service.py @@ -2,6 +2,7 @@ This module contains the main EvenniaService class, which is the very core of the Evennia server. It is instantiated by the evennia/server/server.py module. """ + import importlib import time import traceback @@ -330,12 +331,13 @@ class EvenniaServerService(MultiService): (i, tup[0], tup[1]) for i, tup in enumerate(settings_compare) if i in mismatches ): # update the database - self.info_dict[ - "info" - ] = " %s:\n '%s' changed to '%s'. Updating unchanged entries in database ..." % ( - settings_names[i], - prev, - curr, + self.info_dict["info"] = ( + " %s:\n '%s' changed to '%s'. Updating unchanged entries in database ..." + % ( + settings_names[i], + prev, + curr, + ) ) if i == 0: evennia.ObjectDB.objects.filter(db_cmdset_storage__exact=prev).update( diff --git a/evennia/server/session.py b/evennia/server/session.py index c70c75234d..8c1a518796 100644 --- a/evennia/server/session.py +++ b/evennia/server/session.py @@ -3,6 +3,7 @@ This module defines a generic session class. All connection instances (both on Portal and Server side) should inherit from this class. """ + import time from django.conf import settings diff --git a/evennia/server/sessionhandler.py b/evennia/server/sessionhandler.py index 697e1aeb56..3d3f1c6e6f 100644 --- a/evennia/server/sessionhandler.py +++ b/evennia/server/sessionhandler.py @@ -12,6 +12,7 @@ There are two similar but separate stores of sessions: handle network communication but holds no game info. """ + import time from codecs import decode as codecs_decode diff --git a/evennia/server/signals.py b/evennia/server/signals.py index 7c3f89221c..170d93b9a1 100644 --- a/evennia/server/signals.py +++ b/evennia/server/signals.py @@ -20,6 +20,7 @@ This is used on top of hooks to make certain features easier to add to contribs without necessitating a full takeover of hooks that may be in high demand. """ + from collections import defaultdict from django.dispatch import Signal diff --git a/evennia/server/tests/test_server.py b/evennia/server/tests/test_server.py index f1625f7d9e..c6518dd438 100644 --- a/evennia/server/tests/test_server.py +++ b/evennia/server/tests/test_server.py @@ -2,6 +2,7 @@ Test the main server component """ + from unittest import TestCase from django.test import override_settings @@ -25,13 +26,15 @@ class TestServer(TestCase): @override_settings(IDMAPPER_CACHE_MAXSIZE=1000) def test__server_maintenance_reset(self): - with patch.object(self.server, "_flush_cache", new=MagicMock()) as mockflush, patch.object( - evennia, "ServerConfig", new=MagicMock() - ) as mockconf, patch.multiple( - "evennia.server.service", - LoopingCall=DEFAULT, - connection=DEFAULT, - ) as mocks: + with ( + patch.object(self.server, "_flush_cache", new=MagicMock()) as mockflush, + patch.object(evennia, "ServerConfig", new=MagicMock()) as mockconf, + patch.multiple( + "evennia.server.service", + LoopingCall=DEFAULT, + connection=DEFAULT, + ) as mocks, + ): self.server.maintenance_count = 0 mocks["connection"].close = MagicMock() @@ -43,15 +46,15 @@ class TestServer(TestCase): @override_settings(IDMAPPER_CACHE_MAXSIZE=1000) def test__server_maintenance_flush(self): - with patch.multiple( - "evennia.server.service", - LoopingCall=DEFAULT, - connection=DEFAULT, - ) as mocks, patch.object( - evennia, "ServerConfig", new=MagicMock() - ) as mockconf, patch.object( - self.server, "_flush_cache", new=MagicMock() - ) as mockflush: + with ( + patch.multiple( + "evennia.server.service", + LoopingCall=DEFAULT, + connection=DEFAULT, + ) as mocks, + patch.object(evennia, "ServerConfig", new=MagicMock()) as mockconf, + patch.object(self.server, "_flush_cache", new=MagicMock()) as mockflush, + ): mocks["connection"].close = MagicMock() mockconf.objects.conf = MagicMock(return_value=100) self.server.maintenance_count = 5 - 1 @@ -61,11 +64,14 @@ class TestServer(TestCase): @override_settings(IDMAPPER_CACHE_MAXSIZE=1000) def test__server_maintenance_close_connection(self): - with patch.multiple( - "evennia.server.service", - LoopingCall=DEFAULT, - connection=DEFAULT, - ) as mocks, patch.object(evennia, "ServerConfig", new=MagicMock()) as mockconf: + with ( + patch.multiple( + "evennia.server.service", + LoopingCall=DEFAULT, + connection=DEFAULT, + ) as mocks, + patch.object(evennia, "ServerConfig", new=MagicMock()) as mockconf, + ): self.server._flush_cache = MagicMock() self.server.maintenance_count = (60 * 7) - 1 self.server._last_server_time_snapshot = 0 @@ -76,16 +82,16 @@ class TestServer(TestCase): @override_settings(IDLE_TIMEOUT=10) def test__server_maintenance_idle_time(self): - with patch.multiple( - "evennia.server.service", - LoopingCall=DEFAULT, - connection=DEFAULT, - time=DEFAULT, - ) as mocks, patch.object( - evennia, "ServerConfig", new=MagicMock() - ) as mockconf, patch.object( - evennia, "SESSION_HANDLER", new=MagicMock() - ) as mocksess: + with ( + patch.multiple( + "evennia.server.service", + LoopingCall=DEFAULT, + connection=DEFAULT, + time=DEFAULT, + ) as mocks, + patch.object(evennia, "ServerConfig", new=MagicMock()) as mockconf, + patch.object(evennia, "SESSION_HANDLER", new=MagicMock()) as mocksess, + ): self.server.maintenance_count = (3600 * 7) - 1 self.server._last_server_time_snapshot = 0 sess1 = MagicMock() @@ -114,13 +120,13 @@ class TestServer(TestCase): mocksess.disconnect.assert_has_calls(calls, any_order=True) def test_update_defaults(self): - with patch.object(evennia, "ObjectDB", new=MagicMock()) as mockobj, patch.object( - evennia, "AccountDB", new=MagicMock() - ) as mockacc, patch.object(evennia, "ScriptDB", new=MagicMock()) as mockscr, patch.object( - evennia, "ChannelDB", new=MagicMock() - ) as mockchan, patch.object( - evennia, "ServerConfig", new=MagicMock() - ) as mockconf: + with ( + patch.object(evennia, "ObjectDB", new=MagicMock()) as mockobj, + patch.object(evennia, "AccountDB", new=MagicMock()) as mockacc, + patch.object(evennia, "ScriptDB", new=MagicMock()) as mockscr, + patch.object(evennia, "ChannelDB", new=MagicMock()) as mockchan, + patch.object(evennia, "ServerConfig", new=MagicMock()) as mockconf, + ): for m in (mockscr, mockobj, mockacc, mockchan): m.objects.filter = MagicMock() @@ -220,9 +226,10 @@ class TestInitHooks(TestCase): @override_settings(TEST_ENVIRONMENT=True) def test_run_init_hooks(self): - with patch.object( - self.server, "at_server_reload_start", new=MagicMock() - ) as reload, patch.object(self.server, "at_server_cold_start", new=MagicMock()) as cold: + with ( + patch.object(self.server, "at_server_reload_start", new=MagicMock()) as reload, + patch.object(self.server, "at_server_cold_start", new=MagicMock()) as cold, + ): self.server.run_init_hooks("reload") self.server.run_init_hooks("reset") self.server.run_init_hooks("shutdown") diff --git a/evennia/server/tests/testrunner.py b/evennia/server/tests/testrunner.py index 9652c5a9d0..31aefb7666 100644 --- a/evennia/server/tests/testrunner.py +++ b/evennia/server/tests/testrunner.py @@ -5,6 +5,7 @@ all over the code base and runs them. Runs as part of the Evennia's test suite with 'evennia test evennia" """ + from django.test.runner import DiscoverRunner diff --git a/evennia/server/webserver.py b/evennia/server/webserver.py index 31e05bd0a9..db48e459d4 100644 --- a/evennia/server/webserver.py +++ b/evennia/server/webserver.py @@ -12,6 +12,7 @@ a great example/aid on how to do this.) """ + import urllib.parse from urllib.parse import quote as urlquote diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 2d53d524cc..50a27ce1b5 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -12,6 +12,7 @@ value - which may change as Evennia is developed. This way you can always be sure of what you have changed and what is default behaviour. """ + import os import sys diff --git a/evennia/typeclasses/attributes.py b/evennia/typeclasses/attributes.py index ac274614b0..5aedc03262 100644 --- a/evennia/typeclasses/attributes.py +++ b/evennia/typeclasses/attributes.py @@ -8,6 +8,7 @@ which is a non-db version of Attributes. """ + import fnmatch import re from collections import defaultdict diff --git a/evennia/typeclasses/managers.py b/evennia/typeclasses/managers.py index fee012eaed..7a48e94866 100644 --- a/evennia/typeclasses/managers.py +++ b/evennia/typeclasses/managers.py @@ -4,6 +4,7 @@ abstract models in dbobjects.py (and which are thus shared by all Attributes and TypedObjects). """ + import shlex from django.db.models import Count, ExpressionWrapper, F, FloatField, Q diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index 9758b1f8ce..8f39c66227 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -25,6 +25,7 @@ This module also contains the Managers for the respective models; inherit from these to create custom managers. """ + from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist diff --git a/evennia/typeclasses/tags.py b/evennia/typeclasses/tags.py index a44ed99332..b396419a4b 100644 --- a/evennia/typeclasses/tags.py +++ b/evennia/typeclasses/tags.py @@ -9,6 +9,7 @@ used for storing Aliases and Permissions. This module contains the respective handlers. """ + from collections import defaultdict from django.conf import settings diff --git a/evennia/utils/ansi.py b/evennia/utils/ansi.py index 2cc03f4aec..60c88c4be8 100644 --- a/evennia/utils/ansi.py +++ b/evennia/utils/ansi.py @@ -61,6 +61,7 @@ Xterm256 greyscale: ---- """ + import functools import re from collections import OrderedDict diff --git a/evennia/utils/batchprocessors.py b/evennia/utils/batchprocessors.py index b8c0289bdb..d59ce339a3 100644 --- a/evennia/utils/batchprocessors.py +++ b/evennia/utils/batchprocessors.py @@ -167,6 +167,7 @@ made available in the script namespace. script = create.create_script() """ + import codecs import re import sys diff --git a/evennia/utils/containers.py b/evennia/utils/containers.py index 70b7b43f7d..26e4f0ca69 100644 --- a/evennia/utils/containers.py +++ b/evennia/utils/containers.py @@ -10,7 +10,6 @@ evennia.OPTION_CLASSES """ - from pickle import dumps from django.conf import settings diff --git a/evennia/utils/dbserialize.py b/evennia/utils/dbserialize.py index 2d59f9b803..cc79eed89e 100644 --- a/evennia/utils/dbserialize.py +++ b/evennia/utils/dbserialize.py @@ -18,6 +18,7 @@ in-situ, e.g `obj.db.mynestedlist[3][5] = 3` would never be saved and be out of sync with the database. """ + from collections import OrderedDict, defaultdict, deque from collections.abc import MutableMapping, MutableSequence, MutableSet from functools import update_wrapper diff --git a/evennia/utils/eveditor.py b/evennia/utils/eveditor.py index f0f2168fca..04578c8be8 100644 --- a/evennia/utils/eveditor.py +++ b/evennia/utils/eveditor.py @@ -39,10 +39,12 @@ The editor can also be used to format Python code and be made to survive a reload. See the `EvEditor` class for more details. """ + import re from django.conf import settings from django.utils.translation import gettext as _ + from evennia import CmdSet from evennia.commands import cmdhandler from evennia.utils import dedent, fill, is_iter, justify, logger, to_str, utils @@ -305,7 +307,11 @@ class CmdEditorBase(_COMMAND_DEFAULT_CLASS): if arglist and arglist[0].count(":") == 1: part1, part2 = arglist[0].split(":") lstart = min(max(1, int(part1)), nlines) - 1 if utils.value_is_integer(part1) else 0 - lend = min(max(lstart + 1, int(part2)), nlines) if utils.value_is_integer(part2) else nlines + lend = ( + min(max(lstart + 1, int(part2)), nlines) + if utils.value_is_integer(part2) + else nlines + ) linerange = True elif arglist and arglist[0].isdigit(): lstart = min(max(0, int(arglist[0]) - 1), nlines) @@ -468,7 +474,7 @@ class CmdEditorGroup(CmdEditorBase): linebuffer = self.linebuffer lstart, lend = self.lstart, self.lend # preserve the cmdname including case (otherwise uu and UU would be the same) - cmd = self.raw_string[:len(self.cmdstring)] + cmd = self.raw_string[: len(self.cmdstring)] echo_mode = self.editor._echo_mode if cmd == ":": diff --git a/evennia/utils/funcparser.py b/evennia/utils/funcparser.py index 9417767467..2c434badcf 100644 --- a/evennia/utils/funcparser.py +++ b/evennia/utils/funcparser.py @@ -43,6 +43,7 @@ The `FuncParser` also accepts a direct dict mapping of `{'name': callable, ...}` --- """ + import dataclasses import inspect import random diff --git a/evennia/utils/idmapper/manager.py b/evennia/utils/idmapper/manager.py index c60c6d89a7..7e6f0fa31c 100644 --- a/evennia/utils/idmapper/manager.py +++ b/evennia/utils/idmapper/manager.py @@ -1,6 +1,7 @@ """ IDmapper extension to the default manager. """ + from django.db.models.manager import Manager diff --git a/evennia/utils/logger.py b/evennia/utils/logger.py index 19b5e1214d..b0b4ab9604 100644 --- a/evennia/utils/logger.py +++ b/evennia/utils/logger.py @@ -13,7 +13,6 @@ log_typemsg(). This is for historical, back-compatible reasons. """ - import os import time from datetime import datetime diff --git a/evennia/utils/test_resources.py b/evennia/utils/test_resources.py index 44802a8325..9aee64842a 100644 --- a/evennia/utils/test_resources.py +++ b/evennia/utils/test_resources.py @@ -22,25 +22,32 @@ Other: helper. Used by the command-test classes, but can be used for making a customt test class. """ + import re import sys import types -import evennia from django.conf import settings from django.test import TestCase, override_settings +from mock import MagicMock, Mock, patch +from twisted.internet.defer import Deferred + +import evennia from evennia import settings_default from evennia.accounts.accounts import DefaultAccount from evennia.commands.command import InterruptCommand from evennia.commands.default.muxcommand import MuxCommand -from evennia.objects.objects import DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom +from evennia.objects.objects import ( + DefaultCharacter, + DefaultExit, + DefaultObject, + DefaultRoom, +) from evennia.scripts.scripts import DefaultScript from evennia.server.serversession import ServerSession from evennia.utils import ansi, create from evennia.utils.idmapper.models import flush_cache from evennia.utils.utils import all_from_module, to_str -from mock import MagicMock, Mock, patch -from twisted.internet.defer import Deferred _RE_STRIP_EVMENU = re.compile(r"^\+|-+\+|\+-+|--+|\|(?:\s|$)", re.MULTILINE) diff --git a/evennia/utils/tests/test_eveditor.py b/evennia/utils/tests/test_eveditor.py index 97bda62630..7fc50861c5 100644 --- a/evennia/utils/tests/test_eveditor.py +++ b/evennia/utils/tests/test_eveditor.py @@ -23,7 +23,7 @@ class TestEvEditor(BaseEvenniaCommandTest): self.call(eveditor.CmdLineInput(), "line 5", raw_string="line 5", msg="05line 5") self.call( eveditor.CmdEditorGroup(), - "", # list whole buffer + "", # list whole buffer raw_string=":", msg="Line Editor []\n01line 1\n02line 2\n" "03line 3\n04line 4\n05line 5\n" @@ -31,7 +31,7 @@ class TestEvEditor(BaseEvenniaCommandTest): ) self.call( eveditor.CmdEditorGroup(), - ":", # list empty range + ":", # list empty range raw_string=":", msg="Line Editor []\n01line 1\n02line 2\n" "03line 3\n04line 4\n05line 5\n" @@ -39,7 +39,7 @@ class TestEvEditor(BaseEvenniaCommandTest): ) self.call( eveditor.CmdEditorGroup(), - ":4", # list from start to line 4 + ":4", # list from start to line 4 raw_string=":", msg="Line Editor []\n01line 1\n02line 2\n" "03line 3\n04line 4\n" @@ -47,7 +47,7 @@ class TestEvEditor(BaseEvenniaCommandTest): ) self.call( eveditor.CmdEditorGroup(), - "2:", # list from line 2 to end + "2:", # list from line 2 to end raw_string=":", msg="Line Editor []\n02line 2\n03line 3\n" "04line 4\n05line 5\n" @@ -55,7 +55,7 @@ class TestEvEditor(BaseEvenniaCommandTest): ) self.call( eveditor.CmdEditorGroup(), - "-10:10", # try to list invalid range (too large) + "-10:10", # try to list invalid range (too large) raw_string=":", msg="Line Editor []\n01line 1\n02line 2\n" "03line 3\n04line 4\n05line 5\n" @@ -63,10 +63,9 @@ class TestEvEditor(BaseEvenniaCommandTest): ) self.call( eveditor.CmdEditorGroup(), - "3:1", # try to list invalid range (reversed) + "3:1", # try to list invalid range (reversed) raw_string=":", - msg="Line Editor []\n03line 3\n" - "[l:01 w:002 c:0006](:h for help)", + msg="Line Editor []\n03line 3\n" "[l:01 w:002 c:0006](:h for help)", ) def test_eveditor_view_cmd(self): @@ -184,7 +183,10 @@ class TestEvEditor(BaseEvenniaCommandTest): ) self.call( - eveditor.CmdEditorGroup(), "3", raw_string=":x", msg="Line 3, [' test line'] cut." # cut + eveditor.CmdEditorGroup(), + "3", + raw_string=":x", + msg="Line 3, [' test line'] cut.", # cut ) self.call( diff --git a/evennia/utils/tests/test_evform.py b/evennia/utils/tests/test_evform.py index 4d879cfafb..1d60508eb6 100644 --- a/evennia/utils/tests/test_evform.py +++ b/evennia/utils/tests/test_evform.py @@ -2,6 +2,7 @@ Unit tests for the EvForm text form generator """ + from unittest import skip from django.test import TestCase diff --git a/evennia/utils/tests/test_tagparsing.py b/evennia/utils/tests/test_tagparsing.py index ac1fa3069a..fc062b1c43 100644 --- a/evennia/utils/tests/test_tagparsing.py +++ b/evennia/utils/tests/test_tagparsing.py @@ -2,6 +2,7 @@ Unit tests for all sorts of inline text-tag parsing, like ANSI, html conversion, inlinefuncs etc """ + import re from django.test import TestCase, override_settings diff --git a/evennia/utils/tests/test_utils.py b/evennia/utils/tests/test_utils.py index 17f6c4144a..9852802e72 100644 --- a/evennia/utils/tests/test_utils.py +++ b/evennia/utils/tests/test_utils.py @@ -11,11 +11,12 @@ from datetime import datetime, timedelta import mock from django.test import TestCase +from parameterized import parameterized +from twisted.internet import task + from evennia.utils import utils from evennia.utils.ansi import ANSIString from evennia.utils.test_resources import BaseEvenniaTest -from parameterized import parameterized -from twisted.internet import task class TestIsIter(TestCase): @@ -58,15 +59,26 @@ class TestCompressWhitespace(TestCase): # No text, return no text self.assertEqual("", utils.compress_whitespace("")) # If no whitespace is exceeded, should return the same - self.assertEqual("One line\nTwo spaces", utils.compress_whitespace("One line\nTwo spaces")) + self.assertEqual( + "One line\nTwo spaces", utils.compress_whitespace("One line\nTwo spaces") + ) # Extra newlines are removed - self.assertEqual("First line\nSecond line", utils.compress_whitespace("First line\n\nSecond line")) + self.assertEqual( + "First line\nSecond line", utils.compress_whitespace("First line\n\nSecond line") + ) # Extra spaces are removed self.assertEqual("Too many spaces", utils.compress_whitespace("Too many spaces")) # "Invisible" extra lines with whitespace are removed - self.assertEqual("First line\nSecond line", utils.compress_whitespace("First line\n \n \nSecond line")) + self.assertEqual( + "First line\nSecond line", utils.compress_whitespace("First line\n \n \nSecond line") + ) # Max kwargs are respected - self.assertEqual("First line\n\nSecond line", utils.compress_whitespace("First line\n\nSecond line", max_spacing=1, max_linebreaks=2)) + self.assertEqual( + "First line\n\nSecond line", + utils.compress_whitespace( + "First line\n\nSecond line", max_spacing=1, max_linebreaks=2 + ), + ) def test_preserve_indents(self): """Ensure that indentation spacing is preserved.""" @@ -78,6 +90,7 @@ Hanging Indents # since there is no doubled-up spacing besides indents, input should equal output self.assertEqual(indented, utils.compress_whitespace(indented)) + class TestListToString(TestCase): """ Default function header from time.py: diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 99e5170651..377d31958d 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -28,7 +28,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 @@ -36,12 +35,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 @@ -474,6 +475,7 @@ iter_to_string = iter_to_str re_empty = re.compile("\n\s*\n") + def compress_whitespace(text, max_linebreaks=1, max_spacing=2): """ Removes extra sequential whitespace in a block of text. This will also remove any trailing @@ -492,9 +494,9 @@ def compress_whitespace(text, max_linebreaks=1, max_spacing=2): # this allows the blank-line compression to eliminate them if needed text = re_empty.sub("\n\n", text) # replace groups of extra spaces with the maximum number of spaces - text = re.sub(f"(?<=\S) {{{max_spacing},}}", " "*max_spacing, text) + text = re.sub(f"(?<=\S) {{{max_spacing},}}", " " * max_spacing, text) # replace groups of extra newlines with the maximum number of newlines - text = re.sub(f"\n{{{max_linebreaks},}}", "\n"*max_linebreaks, text) + text = re.sub(f"\n{{{max_linebreaks},}}", "\n" * max_linebreaks, text) return text @@ -2402,20 +2404,18 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs): # result is a typeclassed entity where `.aliases` is an AliasHandler. aliases = result.aliases.all(return_objs=True) # remove pluralization aliases - aliases = [ - alias.db_key - for alias in aliases - if alias.db_category != "plural_key" - ] + aliases = [alias.db_key for alias in aliases if alias.db_category != "plural_key"] else: # result is likely a Command, where `.aliases` is a list of strings. aliases = result.aliases error += _MULTIMATCH_TEMPLATE.format( number=num + 1, - name=result.get_display_name(caller) - if hasattr(result, "get_display_name") - else query, + name=( + result.get_display_name(caller) + if hasattr(result, "get_display_name") + else query + ), aliases=" [{alias}]".format(alias=";".join(aliases)) if aliases else "", info=result.get_extra_info(caller), ) diff --git a/evennia/utils/verb_conjugation/pronouns.py b/evennia/utils/verb_conjugation/pronouns.py index f7a293fda1..c3316e15a9 100644 --- a/evennia/utils/verb_conjugation/pronouns.py +++ b/evennia/utils/verb_conjugation/pronouns.py @@ -25,6 +25,7 @@ viewpoint/pronouns Subject Object Possessive Possessive Reflexive 3rd person plural they them their theirs themselves ==================== ======= ======== ========== ========== =========== """ + from evennia.utils.utils import copy_word_case, is_iter DEFAULT_PRONOUN_TYPE = "subject pronoun" diff --git a/evennia/web/admin/help.py b/evennia/web/admin/help.py index 4417142107..9c64630fca 100644 --- a/evennia/web/admin/help.py +++ b/evennia/web/admin/help.py @@ -1,6 +1,7 @@ """ This defines how to edit help entries in Admin. """ + from django import forms from django.contrib import admin diff --git a/evennia/web/admin/tags.py b/evennia/web/admin/tags.py index ebfe2cff56..fd7395f686 100644 --- a/evennia/web/admin/tags.py +++ b/evennia/web/admin/tags.py @@ -3,7 +3,6 @@ Tag admin """ - import traceback from datetime import datetime diff --git a/evennia/web/admin/urls.py b/evennia/web/admin/urls.py index 0a59fcf752..a6dfcf64f6 100644 --- a/evennia/web/admin/urls.py +++ b/evennia/web/admin/urls.py @@ -4,6 +4,7 @@ Rerouting admin frontpage to evennia version. These patterns are all under the admin/* namespace. """ + from django.conf import settings from django.contrib import admin from django.urls import include, path diff --git a/evennia/web/api/filters.py b/evennia/web/api/filters.py index 29ce027dc0..dedb874ad1 100644 --- a/evennia/web/api/filters.py +++ b/evennia/web/api/filters.py @@ -7,6 +7,7 @@ documentation specifically regarding DRF integration. https://django-filter.readthedocs.io/en/latest/guide/rest_framework.html """ + from typing import Union from django.db.models import Q @@ -138,7 +139,6 @@ class ScriptDBFilterSet(BaseTypeclassFilterSet): class HelpFilterSet(FilterSet): - """ Filter for help entries diff --git a/evennia/web/api/permissions.py b/evennia/web/api/permissions.py index 536cb9a552..901f485c55 100644 --- a/evennia/web/api/permissions.py +++ b/evennia/web/api/permissions.py @@ -3,7 +3,6 @@ Sets up an api-access permission check using the in-game permission hierarchy. """ - from django.conf import settings from rest_framework import permissions diff --git a/evennia/web/api/tests.py b/evennia/web/api/tests.py index 4af37b2603..94006dd641 100644 --- a/evennia/web/api/tests.py +++ b/evennia/web/api/tests.py @@ -2,6 +2,7 @@ Tests for the REST API. """ + from collections import namedtuple from django.core.exceptions import ObjectDoesNotExist diff --git a/evennia/web/api/views.py b/evennia/web/api/views.py index eb28073d97..51de2f0321 100644 --- a/evennia/web/api/views.py +++ b/evennia/web/api/views.py @@ -4,6 +4,7 @@ Rest Framework provides collections called 'ViewSets', which can generate a number of views for the common CRUD operations. """ + from django_filters.rest_framework import DjangoFilterBackend from rest_framework import status from rest_framework.decorators import action diff --git a/evennia/web/utils/general_context.py b/evennia/web/utils/general_context.py index f8731a633d..57abb1843f 100644 --- a/evennia/web/utils/general_context.py +++ b/evennia/web/utils/general_context.py @@ -7,10 +7,10 @@ TEMPLATES["OPTIONS"]["context_processors"] list. """ - import os from django.conf import settings + from evennia.utils.utils import get_evennia_version # Setup lists of the most relevant apps so diff --git a/evennia/web/webclient/urls.py b/evennia/web/webclient/urls.py index 364a72feb5..39a7edfdbf 100644 --- a/evennia/web/webclient/urls.py +++ b/evennia/web/webclient/urls.py @@ -2,6 +2,7 @@ This structures the (simple) structure of the webpage 'application'. """ + from django.urls import path from . import views diff --git a/evennia/web/website/urls.py b/evennia/web/website/urls.py index 2777424eeb..92c01e2474 100644 --- a/evennia/web/website/urls.py +++ b/evennia/web/website/urls.py @@ -2,6 +2,7 @@ This redirects to website sub-pages. """ + from django.conf import settings from django.contrib import admin from django.urls import include, path diff --git a/evennia/web/website/views/accounts.py b/evennia/web/website/views/accounts.py index 5ecb5128ee..8cfd33a550 100644 --- a/evennia/web/website/views/accounts.py +++ b/evennia/web/website/views/accounts.py @@ -3,7 +3,6 @@ Views for managing accounts. """ - from django.conf import settings from django.contrib import messages from django.http import HttpResponseRedirect diff --git a/evennia/web/website/views/characters.py b/evennia/web/website/views/characters.py index f9e4142b1d..113710f2a5 100644 --- a/evennia/web/website/views/characters.py +++ b/evennia/web/website/views/characters.py @@ -14,12 +14,17 @@ from django.utils.encoding import iri_to_uri from django.utils.http import url_has_allowed_host_and_scheme from django.views.generic import ListView from django.views.generic.base import RedirectView + from evennia.utils import class_from_module from evennia.web.website import forms from .mixins import TypeclassMixin -from .objects import (ObjectCreateView, ObjectDeleteView, ObjectDetailView, - ObjectUpdateView) +from .objects import ( + ObjectCreateView, + ObjectDeleteView, + ObjectDetailView, + ObjectUpdateView, +) class CharacterMixin(TypeclassMixin): @@ -124,9 +129,11 @@ class CharacterPuppetView(LoginRequiredMixin, CharacterMixin, RedirectView, Obje # since next_page is untrusted input from the user, we need to check it's safe to next_page = iri_to_uri(next_page) - if not url_has_allowed_host_and_scheme(url=next_page, - allowed_hosts={self.request.get_host()}, - require_https=self.request.is_secure()): + if not url_has_allowed_host_and_scheme( + url=next_page, + allowed_hosts={self.request.get_host()}, + require_https=self.request.is_secure(), + ): next_page = self.success_url if char: @@ -140,7 +147,6 @@ class CharacterPuppetView(LoginRequiredMixin, CharacterMixin, RedirectView, Obje self.request.session["puppet"] = None messages.error(self.request, "You cannot become '%s'." % char) - return next_page diff --git a/evennia/web/website/views/help.py b/evennia/web/website/views/help.py index 98ef5cbcb3..c84feb20b1 100644 --- a/evennia/web/website/views/help.py +++ b/evennia/web/website/views/help.py @@ -4,6 +4,7 @@ Views to manipulate help entries. Multi entry object type supported added by DaveWithTheNiceHat 2021 Pull Request #2429 """ + from django.conf import settings from django.http import HttpResponseBadRequest from django.utils.text import slugify diff --git a/evennia/web/website/views/mixins.py b/evennia/web/website/views/mixins.py index 8cecd5b241..496ebab64e 100644 --- a/evennia/web/website/views/mixins.py +++ b/evennia/web/website/views/mixins.py @@ -2,6 +2,7 @@ These are mixins for class-based views, granting functionality. """ + from django.views.generic import DetailView from django.views.generic.edit import CreateView, DeleteView, UpdateView