Ran black on sources

This commit is contained in:
Griatch 2023-11-23 19:09:12 +01:00
parent 84e8ca129f
commit b4a3bae6a9
13 changed files with 73 additions and 50 deletions

View file

@ -183,9 +183,10 @@ def _init(portal_mode=False):
# Parent typeclasses # Parent typeclasses
# utilities # utilities
from django.conf import settings
import os import os
from django.conf import settings
from . import contrib from . import contrib
from .accounts.accounts import DefaultAccount, DefaultGuest from .accounts.accounts import DefaultAccount, DefaultGuest
from .accounts.models import AccountDB from .accounts.models import AccountDB
@ -211,7 +212,7 @@ def _init(portal_mode=False):
from .server.models import ServerConfig from .server.models import ServerConfig
from .typeclasses.attributes import AttributeProperty from .typeclasses.attributes import AttributeProperty
from .typeclasses.tags import TagCategoryProperty, TagProperty from .typeclasses.tags import TagCategoryProperty, TagProperty
from .utils import ansi, gametime, logger, class_from_module from .utils import ansi, class_from_module, gametime, logger
from .utils.ansi import ANSIString from .utils.ansi import ANSIString
if not PORTAL_MODE: if not PORTAL_MODE:

View file

@ -15,13 +15,14 @@ import time
import typing import typing
from random import getrandbits from random import getrandbits
import evennia
from django.conf import settings from django.conf import settings
from django.contrib.auth import authenticate, password_validation from django.contrib.auth import authenticate, password_validation
from django.core.exceptions import ImproperlyConfigured, ValidationError from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.utils import timezone from django.utils import timezone
from django.utils.module_loading import import_string from django.utils.module_loading import import_string
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
import evennia
from evennia.accounts.manager import AccountManager from evennia.accounts.manager import AccountManager
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
from evennia.commands.cmdsethandler import CmdSetHandler from evennia.commands.cmdsethandler import CmdSetHandler
@ -31,9 +32,9 @@ from evennia.scripts.scripthandler import ScriptHandler
from evennia.server.models import ServerConfig from evennia.server.models import ServerConfig
from evennia.server.signals import ( from evennia.server.signals import (
SIGNAL_ACCOUNT_POST_CREATE, SIGNAL_ACCOUNT_POST_CREATE,
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
SIGNAL_OBJECT_POST_PUPPET, SIGNAL_OBJECT_POST_PUPPET,
SIGNAL_OBJECT_POST_UNPUPPET, SIGNAL_OBJECT_POST_UNPUPPET,
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
) )
from evennia.server.throttle import Throttle from evennia.server.throttle import Throttle
from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler
@ -855,7 +856,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
""" """
# check character slot usage. # check character slot usage.
if (slot_check := self.check_available_slots()): if slot_check := self.check_available_slots():
return None, [slot_check] return None, [slot_check]
# parse inputs # parse inputs

View file

@ -148,7 +148,9 @@ class CmdCharCreate(COMMAND_DEFAULT_CLASS):
key = self.lhs key = self.lhs
description = self.rhs or "This is a character." description = self.rhs or "This is a character."
new_character, errors = self.account.create_character(key=key, description=description, ip=self.session.address) new_character, errors = self.account.create_character(
key=key, description=description, ip=self.session.address
)
if errors: if errors:
self.msg(errors) self.msg(errors)
@ -161,7 +163,6 @@ class CmdCharCreate(COMMAND_DEFAULT_CLASS):
) )
class CmdCharDelete(COMMAND_DEFAULT_CLASS): class CmdCharDelete(COMMAND_DEFAULT_CLASS):
""" """
delete a character - this cannot be undone! delete a character - this cannot be undone!

View file

@ -10,7 +10,6 @@ This is the v1.0 develop version (for ref in doc building).
import time import time
import typing import typing
from collections import defaultdict from collections import defaultdict
import typing
import inflect import inflect
from django.conf import settings from django.conf import settings
@ -2540,7 +2539,7 @@ class DefaultCharacter(DefaultObject):
# Normalize to latin characters and validate, if necessary, the supplied key # Normalize to latin characters and validate, if necessary, the supplied key
key = cls.normalize_name(key) key = cls.normalize_name(key)
if (val_err := cls.validate_name(key, account=account)): if val_err := cls.validate_name(key, account=account):
errors.append(val_err) errors.append(val_err)
return obj, errors return obj, errors

View file

@ -10,15 +10,17 @@ by game/evennia.py).
import os import os
import sys import sys
import django
from twisted.logger import globalLogPublisher from twisted.logger import globalLogPublisher
import django
django.setup() django.setup()
import evennia import evennia
evennia._init(portal_mode=True) evennia._init(portal_mode=True)
from django.conf import settings from django.conf import settings
from evennia.utils import logger from evennia.utils import logger
# twistd requires us to define the variable 'application' so it knows # twistd requires us to define the variable 'application' so it knows

View file

@ -2,12 +2,14 @@ import os
import sys import sys
import time import time
from os.path import abspath, dirname from os.path import abspath, dirname
from twisted.application.service import MultiService
from django.conf import settings from django.conf import settings
from django.db import connection from django.db import connection
from twisted.application import internet, service from twisted.application import internet, service
from twisted.application.service import MultiService
from twisted.internet import protocol, reactor from twisted.internet import protocol, reactor
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
import evennia import evennia
from evennia.utils.utils import ( from evennia.utils.utils import (
class_from_module, class_from_module,
@ -18,7 +20,6 @@ from evennia.utils.utils import (
class EvenniaPortalService(MultiService): class EvenniaPortalService(MultiService):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.amp_protocol = None self.amp_protocol = None
@ -107,7 +108,6 @@ class EvenniaPortalService(MultiService):
return interfaces return interfaces
def register_ssl(self): def register_ssl(self):
# Start Telnet+SSL game connection (requires PyOpenSSL). # Start Telnet+SSL game connection (requires PyOpenSSL).
from evennia.server.portal import telnet_ssl from evennia.server.portal import telnet_ssl
@ -158,7 +158,11 @@ class EvenniaPortalService(MultiService):
for port in settings.SSH_PORTS: for port in settings.SSH_PORTS:
pstring = "%s:%s" % (ifacestr, port) pstring = "%s:%s" % (ifacestr, port)
factory = ssh.makeFactory( factory = ssh.makeFactory(
{"protocolFactory": _ssh_protocol, "protocolArgs": (), "sessions": evennia.PORTAL_SESSION_HANDLER} {
"protocolFactory": _ssh_protocol,
"protocolArgs": (),
"sessions": evennia.PORTAL_SESSION_HANDLER,
}
) )
factory.noisy = False factory.noisy = False
ssh_service = internet.TCPServer(port, factory, interface=interface) ssh_service = internet.TCPServer(port, factory, interface=interface)
@ -168,7 +172,7 @@ class EvenniaPortalService(MultiService):
self.info_dict["ssh"].append("ssh%s: %s" % (ifacestr, port)) self.info_dict["ssh"].append("ssh%s: %s" % (ifacestr, port))
def register_webserver(self): def register_webserver(self):
from evennia.server.webserver import Website, EvenniaReverseProxyResource from evennia.server.webserver import EvenniaReverseProxyResource, Website
# Start a reverse proxy to relay data to the Server-side webserver # Start a reverse proxy to relay data to the Server-side webserver
interfaces = self.check_lockdown(settings.WEBSERVER_INTERFACES) interfaces = self.check_lockdown(settings.WEBSERVER_INTERFACES)
@ -191,17 +195,27 @@ class EvenniaPortalService(MultiService):
web_root.putChild(b"webclientdata", ajax_webclient) web_root.putChild(b"webclientdata", ajax_webclient)
webclientstr = "webclient (ajax only)" webclientstr = "webclient (ajax only)"
if (settings.WEBSOCKET_CLIENT_ENABLED and settings.WEBSOCKET_CLIENT_PORT and if (
settings.WEBSOCKET_CLIENT_INTERFACE) and not websocket_started: settings.WEBSOCKET_CLIENT_ENABLED
and settings.WEBSOCKET_CLIENT_PORT
and settings.WEBSOCKET_CLIENT_INTERFACE
) and not websocket_started:
# start websocket client port for the webclient # start websocket client port for the webclient
# we only support one websocket client # we only support one websocket client
from autobahn.twisted.websocket import WebSocketServerFactory from autobahn.twisted.websocket import WebSocketServerFactory
from evennia.server.portal import webclient # noqa from evennia.server.portal import webclient # noqa
w_interface = "127.0.0.1" if settings.LOCKDOWN_MODE else settings.WEBSOCKET_CLIENT_INTERFACE w_interface = (
"127.0.0.1"
if settings.LOCKDOWN_MODE
else settings.WEBSOCKET_CLIENT_INTERFACE
)
w_ifacestr = "" w_ifacestr = ""
if w_interface not in ("0.0.0.0", "::") or len(settings.WEBSERVER_INTERFACES) > 1: if (
w_interface not in ("0.0.0.0", "::")
or len(settings.WEBSERVER_INTERFACES) > 1
):
w_ifacestr = "-%s" % w_interface w_ifacestr = "-%s" % w_interface
port = settings.WEBSOCKET_CLIENT_PORT port = settings.WEBSOCKET_CLIENT_PORT
@ -246,7 +260,9 @@ class EvenniaPortalService(MultiService):
proxy_service = internet.TCPServer(proxyport, web_root, interface=interface) proxy_service = internet.TCPServer(proxyport, web_root, interface=interface)
proxy_service.setName("EvenniaWebProxy%s:%s" % (ifacestr, proxyport)) proxy_service.setName("EvenniaWebProxy%s:%s" % (ifacestr, proxyport))
proxy_service.setServiceParent(self) proxy_service.setServiceParent(self)
self.info_dict["webserver_proxy"].append("webserver-proxy%s: %s" % (ifacestr, proxyport)) self.info_dict["webserver_proxy"].append(
"webserver-proxy%s: %s" % (ifacestr, proxyport)
)
self.info_dict["webserver_internal"].append("webserver: %s" % serverport) self.info_dict["webserver_internal"].append("webserver: %s" % serverport)
def register_telnet(self): def register_telnet(self):
@ -284,7 +300,9 @@ class EvenniaPortalService(MultiService):
self.info_dict["amp"] = "amp: %s" % settings.AMP_PORT self.info_dict["amp"] = "amp: %s" % settings.AMP_PORT
factory = amp_server.AMPServerFactory(self) factory = amp_server.AMPServerFactory(self)
amp_service = internet.TCPServer(settings.AMP_PORT, factory, interface=settings.AMP_INTERFACE) amp_service = internet.TCPServer(
settings.AMP_PORT, factory, interface=settings.AMP_INTERFACE
)
amp_service.setName("PortalAMPServer") amp_service.setName("PortalAMPServer")
amp_service.setServiceParent(self) amp_service.setServiceParent(self)

View file

@ -23,9 +23,9 @@ from twisted.trial.unittest import TestCase as TwistedTestCase
import evennia import evennia
from evennia.server.portal import irc from evennia.server.portal import irc
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.server.portal.service import EvenniaPortalService
from evennia.server.portal.portalsessionhandler import PortalSessionHandler from evennia.server.portal.portalsessionhandler import PortalSessionHandler
from evennia.server.portal.service import EvenniaPortalService
from evennia.utils.test_resources import BaseEvenniaTest
from .amp import ( from .amp import (
AMP_MAXLEN, AMP_MAXLEN,

View file

@ -10,15 +10,17 @@ evennia/server/server_runner.py).
import os import os
import sys import sys
import django
from twisted.logger import globalLogPublisher from twisted.logger import globalLogPublisher
import django
django.setup() django.setup()
import evennia import evennia
evennia._init() evennia._init()
from django.conf import settings from django.conf import settings
from evennia.utils import logger from evennia.utils import logger
# twistd requires us to define the variable 'application' so it knows # twistd requires us to define the variable 'application' so it knows
@ -36,5 +38,3 @@ if "--nodaemon" not in sys.argv and "test" not in sys.argv:
max_size=settings.SERVER_LOG_MAX_SIZE, max_size=settings.SERVER_LOG_MAX_SIZE,
) )
globalLogPublisher.addObserver(logger.GetServerLogObserver()(logfile)) globalLogPublisher.addObserver(logger.GetServerLogObserver()(logfile))

View file

@ -2,25 +2,24 @@
This module contains the main EvenniaService class, which is the very core of the 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. Evennia server. It is instantiated by the evennia/server/server.py module.
""" """
import importlib
import time import time
import traceback import traceback
import importlib
import django
from django.conf import settings
from django.db import connection
from django.db.utils import OperationalError
from django.utils.translation import gettext as _
from twisted.application import internet from twisted.application import internet
from twisted.application.service import MultiService from twisted.application.service import MultiService
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
import django
from django.db import connection
from django.db.utils import OperationalError
from django.conf import settings
from django.utils.translation import gettext as _
import evennia import evennia
from evennia.utils.utils import get_evennia_version, make_iter, mod_import
from evennia.utils import logger from evennia.utils import logger
from evennia.utils.utils import get_evennia_version, make_iter, mod_import
_SA = object.__setattr__ _SA = object.__setattr__
@ -417,8 +416,7 @@ class EvenniaServerService(MultiService):
""" """
from evennia import AccountDB from evennia import AccountDB, ChannelDB
from evennia import ChannelDB
from evennia.utils.create import create_channel from evennia.utils.create import create_channel
superuser = AccountDB.objects.get(id=1) superuser = AccountDB.objects.get(id=1)

View file

@ -20,9 +20,10 @@ 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. without necessitating a full takeover of hooks that may be in high demand.
""" """
from django.dispatch import Signal
from collections import defaultdict from collections import defaultdict
from django.dispatch import Signal
# The sender is the created Account. This is triggered at the very end of # The sender is the created Account. This is triggered at the very end of
# Account.create() after the Account is created. Note that this will *not* fire # Account.create() after the Account is created. Note that this will *not* fire
# if calling create.create_account alone, since going through the Account.create() # if calling create.create_account alone, since going through the Account.create()

View file

@ -14,11 +14,11 @@ from twisted.trial.unittest import TestCase as TwistedTestCase
import evennia import evennia
from evennia.server import amp_client, server, serversession, session from evennia.server import amp_client, server, serversession, session
from evennia.server.portal import amp, amp_server, portal from evennia.server.portal import amp, amp_server, portal
from evennia.utils import create
from evennia.server.service import EvenniaServerService
from evennia.server.portal.service import EvenniaPortalService
from evennia.server.sessionhandler import ServerSessionHandler
from evennia.server.portal.portalsessionhandler import PortalSessionHandler from evennia.server.portal.portalsessionhandler import PortalSessionHandler
from evennia.server.portal.service import EvenniaPortalService
from evennia.server.service import EvenniaServerService
from evennia.server.sessionhandler import ServerSessionHandler
from evennia.utils import create
DelayedCall.debug = True DelayedCall.debug = True

View file

@ -2,12 +2,13 @@
Test the main server component Test the main server component
""" """
import evennia
from unittest import TestCase from unittest import TestCase
from django.test import override_settings from django.test import override_settings
from mock import DEFAULT, MagicMock, call, patch from mock import DEFAULT, MagicMock, call, patch
import evennia
@patch("evennia.server.service.LoopingCall", new=MagicMock()) @patch("evennia.server.service.LoopingCall", new=MagicMock())
class TestServer(TestCase): class TestServer(TestCase):

View file

@ -18,6 +18,7 @@ class EvenniaTestSuiteRunner(DiscoverRunner):
def setup_test_environment(self, **kwargs): def setup_test_environment(self, **kwargs):
import evennia import evennia
evennia._init() evennia._init()
from django.conf import settings from django.conf import settings