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
# utilities
from django.conf import settings
import os
from django.conf import settings
from . import contrib
from .accounts.accounts import DefaultAccount, DefaultGuest
from .accounts.models import AccountDB
@ -211,7 +212,7 @@ def _init(portal_mode=False):
from .server.models import ServerConfig
from .typeclasses.attributes import AttributeProperty
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
if not PORTAL_MODE:

View file

@ -15,13 +15,14 @@ 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
@ -31,9 +32,9 @@ 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,
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
)
from evennia.server.throttle import Throttle
from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler
@ -855,7 +856,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
"""
# check character slot usage.
if (slot_check := self.check_available_slots()):
if slot_check := self.check_available_slots():
return None, [slot_check]
# parse inputs

View file

@ -148,7 +148,9 @@ class CmdCharCreate(COMMAND_DEFAULT_CLASS):
key = self.lhs
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:
self.msg(errors)
@ -161,7 +163,6 @@ class CmdCharCreate(COMMAND_DEFAULT_CLASS):
)
class CmdCharDelete(COMMAND_DEFAULT_CLASS):
"""
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 typing
from collections import defaultdict
import typing
import inflect
from django.conf import settings
@ -2540,7 +2539,7 @@ class DefaultCharacter(DefaultObject):
# Normalize to latin characters and validate, if necessary, the supplied 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)
return obj, errors

View file

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

View file

@ -2,12 +2,14 @@ import os
import sys
import time
from os.path import abspath, dirname
from twisted.application.service import MultiService
from django.conf import settings
from django.db import connection
from twisted.application import internet, service
from twisted.application.service import MultiService
from twisted.internet import protocol, reactor
from twisted.internet.task import LoopingCall
import evennia
from evennia.utils.utils import (
class_from_module,
@ -18,7 +20,6 @@ from evennia.utils.utils import (
class EvenniaPortalService(MultiService):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.amp_protocol = None
@ -80,10 +81,10 @@ class EvenniaPortalService(MultiService):
if settings.SSL_ENABLED and settings.SSL_PORTS and settings.SSL_INTERFACES:
self.register_ssl()
if settings.SSH_ENABLED and settings.SSH_PORTS and settings.SSH_INTERFACES:
self.register_ssh()
if settings.WEBSERVER_ENABLED:
self.register_webserver()
@ -105,17 +106,16 @@ class EvenniaPortalService(MultiService):
if settings.LOCKDOWN_MODE:
return ["127.0.0.1"]
return interfaces
def register_ssl(self):
def register_ssl(self):
# Start Telnet+SSL game connection (requires PyOpenSSL).
from evennia.server.portal import telnet_ssl
_ssl_protocol = class_from_module(settings.SSL_PROTOCOL_CLASS)
interfaces = self.check_lockdown(settings.SSL_INTERFACES)
for interface in interfaces:
ifacestr = ""
if interface not in ("0.0.0.0", "::") or len(interfaces) > 1:
@ -148,9 +148,9 @@ class EvenniaPortalService(MultiService):
from evennia.server.portal import ssh
_ssh_protocol = class_from_module(settings.SSH_PROTOCOL_CLASS)
interfaces = self.check_lockdown(settings.SSH_INTERFACES)
for interface in interfaces:
ifacestr = ""
if interface not in ("0.0.0.0", "::") or len(interfaces) > 1:
@ -158,7 +158,11 @@ class EvenniaPortalService(MultiService):
for port in settings.SSH_PORTS:
pstring = "%s:%s" % (ifacestr, port)
factory = ssh.makeFactory(
{"protocolFactory": _ssh_protocol, "protocolArgs": (), "sessions": evennia.PORTAL_SESSION_HANDLER}
{
"protocolFactory": _ssh_protocol,
"protocolArgs": (),
"sessions": evennia.PORTAL_SESSION_HANDLER,
}
)
factory.noisy = False
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))
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
interfaces = self.check_lockdown(settings.WEBSERVER_INTERFACES)
@ -178,7 +182,7 @@ class EvenniaPortalService(MultiService):
ifacestr = ""
if interface not in ("0.0.0.0", "::") or len(interfaces) > 1:
ifacestr = "-%s" % interface
for proxyport, serverport in settings.WEBSERVER_PORTS:
web_root = EvenniaReverseProxyResource("127.0.0.1", serverport, "")
webclientstr = ""
@ -191,17 +195,27 @@ class EvenniaPortalService(MultiService):
web_root.putChild(b"webclientdata", ajax_webclient)
webclientstr = "webclient (ajax only)"
if (settings.WEBSOCKET_CLIENT_ENABLED and settings.WEBSOCKET_CLIENT_PORT and
settings.WEBSOCKET_CLIENT_INTERFACE) and not websocket_started:
if (
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
# we only support one websocket client
from autobahn.twisted.websocket import WebSocketServerFactory
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 = ""
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
port = settings.WEBSOCKET_CLIENT_PORT
@ -246,7 +260,9 @@ class EvenniaPortalService(MultiService):
proxy_service = internet.TCPServer(proxyport, web_root, interface=interface)
proxy_service.setName("EvenniaWebProxy%s:%s" % (ifacestr, proxyport))
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)
def register_telnet(self):
@ -284,7 +300,9 @@ class EvenniaPortalService(MultiService):
self.info_dict["amp"] = "amp: %s" % settings.AMP_PORT
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.setServiceParent(self)

View file

@ -23,9 +23,9 @@ from twisted.trial.unittest import TestCase as TwistedTestCase
import evennia
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.service import EvenniaPortalService
from evennia.utils.test_resources import BaseEvenniaTest
from .amp import (
AMP_MAXLEN,

View file

@ -10,15 +10,17 @@ evennia/server/server_runner.py).
import os
import sys
import django
from twisted.logger import globalLogPublisher
import django
django.setup()
import evennia
evennia._init()
from django.conf import settings
from evennia.utils import logger
# 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,
)
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
Evennia server. It is instantiated by the evennia/server/server.py module.
"""
import importlib
import time
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.service import MultiService
from twisted.internet import defer, reactor
from twisted.internet.defer import Deferred
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
from evennia.utils.utils import get_evennia_version, make_iter, mod_import
from evennia.utils import logger
from evennia.utils.utils import get_evennia_version, make_iter, mod_import
_SA = object.__setattr__
@ -417,8 +416,7 @@ class EvenniaServerService(MultiService):
"""
from evennia import AccountDB
from evennia import ChannelDB
from evennia import AccountDB, ChannelDB
from evennia.utils.create import create_channel
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.
"""
from django.dispatch import Signal
from collections import defaultdict
from django.dispatch import Signal
# 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
# 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
from evennia.server import amp_client, server, serversession, session
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.service import EvenniaPortalService
from evennia.server.service import EvenniaServerService
from evennia.server.sessionhandler import ServerSessionHandler
from evennia.utils import create
DelayedCall.debug = True

View file

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

View file

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