Run black on sources

This commit is contained in:
Griatch 2020-04-20 23:39:09 +02:00
parent dc81d275e6
commit 8b2b23873f
17 changed files with 102 additions and 59 deletions

View file

@ -508,8 +508,10 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
if banned: if banned:
# this is a banned IP or name! # this is a banned IP or name!
errors.append( errors.append(
_("|rYou have been banned and cannot continue from here." _(
"\nIf you feel this ban is in error, please email an admin.|x") "|rYou have been banned and cannot continue from here."
"\nIf you feel this ban is in error, please email an admin.|x"
)
) )
logger.log_sec(f"Authentication Denied (Banned): {username} (IP: {ip}).") logger.log_sec(f"Authentication Denied (Banned): {username} (IP: {ip}).")
LOGIN_THROTTLE.update(ip, "Too many sightings of banned artifact.") LOGIN_THROTTLE.update(ip, "Too many sightings of banned artifact.")
@ -716,9 +718,9 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
banned = cls.is_banned(username=username, ip=ip) banned = cls.is_banned(username=username, ip=ip)
if banned: if banned:
# this is a banned IP or name! # this is a banned IP or name!
string = ( string = _(
_("|rYou have been banned and cannot continue from here." "|rYou have been banned and cannot continue from here."
"\nIf you feel this ban is in error, please email an admin.|x") "\nIf you feel this ban is in error, please email an admin.|x"
) )
errors.append(string) errors.append(string)
return None, errors return None, errors
@ -733,7 +735,9 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
except Exception as e: except Exception as e:
errors.append( errors.append(
_("There was an error creating the Account. If this problem persists, contact an admin.") _(
"There was an error creating the Account. If this problem persists, contact an admin."
)
) )
logger.log_trace() logger.log_trace()
return None, errors return None, errors
@ -1305,7 +1309,9 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
""" """
reason = f" ({reason if reason else ''})" reason = f" ({reason if reason else ''})"
self._send_to_connect_channel(_("|R{key} disconnected{reason}|n").format(key=self.key, reason=reason)) self._send_to_connect_channel(
_("|R{key} disconnected{reason}|n").format(key=self.key, reason=reason)
)
def at_post_disconnect(self, **kwargs): def at_post_disconnect(self, **kwargs):
""" """
@ -1454,7 +1460,9 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
if is_su or len(characters) < charmax: if is_su or len(characters) < charmax:
if not characters: if not characters:
result.append( result.append(
_("\n\n You don't have any characters yet. See |whelp @charcreate|n for creating one.") _(
"\n\n You don't have any characters yet. See |whelp @charcreate|n for creating one."
)
) )
else: else:
result.append("\n |w@charcreate <name> [=description]|n - create new character") result.append("\n |w@charcreate <name> [=description]|n - create new character")

View file

@ -329,7 +329,9 @@ class IRCBot(Bot):
chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})"
nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower())) nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower()))
for obj in self._nicklist_callers: for obj in self._nicklist_callers:
obj.msg(_("Nicks at {chstr}:\n {nicklist}").format(chstr=chstr, nicklist=nicklist)) obj.msg(
_("Nicks at {chstr}:\n {nicklist}").format(chstr=chstr, nicklist=nicklist)
)
self._nicklist_callers = [] self._nicklist_callers = []
return return
@ -338,7 +340,11 @@ class IRCBot(Bot):
if hasattr(self, "_ping_callers") and self._ping_callers: if hasattr(self, "_ping_callers") and self._ping_callers:
chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})" chstr = f"{self.db.irc_channel} ({self.db.irc_network}:{self.db.irc_port})"
for obj in self._ping_callers: for obj in self._ping_callers:
obj.msg(_("IRC ping return from {chstr} took {time}s.").format(chstr=chstr, time=kwargs['timing'])) obj.msg(
_("IRC ping return from {chstr} took {time}s.").format(
chstr=chstr, time=kwargs["timing"]
)
)
self._ping_callers = [] self._ping_callers = []
return return

View file

@ -743,7 +743,9 @@ def cmdhandler(
sysarg = raw_string sysarg = raw_string
else: else:
# fallback to default error text # fallback to default error text
sysarg = _("Command '{command}' is not available.").format(command=raw_string) sysarg = _("Command '{command}' is not available.").format(
command=raw_string
)
suggestions = string_suggestions( suggestions = string_suggestions(
raw_string, raw_string,
cmdset.get_all_cmd_keys_and_aliases(caller), cmdset.get_all_cmd_keys_and_aliases(caller),
@ -751,7 +753,9 @@ def cmdhandler(
maxnum=3, maxnum=3,
) )
if suggestions: if suggestions:
sysarg += _(" Maybe you meant {command}?").format(command=utils.list_to_string(suggestions, _("or"), addquote=True)) sysarg += _(" Maybe you meant {command}?").format(
command=utils.list_to_string(suggestions, _("or"), addquote=True)
)
else: else:
sysarg += _(' Type "help" for help.') sysarg += _(' Type "help" for help.')
raise ExecSystemCommand(syscmd, sysarg) raise ExecSystemCommand(syscmd, sysarg)

View file

@ -184,7 +184,9 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
raise exc.with_traceback(tb) raise exc.with_traceback(tb)
else: else:
# try next suggested path # try next suggested path
errstring += _("\n(Unsuccessfully tried '{path}').").format(path=python_path) errstring += _("\n(Unsuccessfully tried '{path}').").format(
path=python_path
)
continue continue
try: try:
cmdsetclass = getattr(module, classname) cmdsetclass = getattr(module, classname)
@ -194,7 +196,9 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
dum, dum, tb = sys.exc_info() dum, dum, tb = sys.exc_info()
raise exc.with_traceback(tb) raise exc.with_traceback(tb)
else: else:
errstring += _("\n(Unsuccessfully tried '{path}').").format(path=python_path) errstring += _("\n(Unsuccessfully tried '{path}').").format(
path=python_path
)
continue continue
_CACHED_CMDSETS[python_path] = cmdsetclass _CACHED_CMDSETS[python_path] = cmdsetclass

View file

@ -131,7 +131,9 @@ class HelpEntryManager(TypedObjectManager):
for topic in topics: for topic in topics:
topic.help_category = default_category topic.help_category = default_category
topic.save() topic.save()
string = _("Help database moved to category {default_category}").format(default_category=default_category) string = _("Help database moved to category {default_category}").format(
default_category=default_category
)
logger.log_info(string) logger.log_info(string)
def search_help(self, ostring, help_category=None): def search_help(self, ostring, help_category=None):

View file

@ -246,7 +246,11 @@ class LockHandler(object):
evalstring = " ".join(_RE_OK.findall(evalstring)) evalstring = " ".join(_RE_OK.findall(evalstring))
eval(evalstring % tuple(True for func in funclist), {}, {}) eval(evalstring % tuple(True for func in funclist), {}, {})
except Exception: except Exception:
elist.append(_("Lock: definition '{lock_string}' has syntax errors.").format(lock_string=raw_lockstring)) elist.append(
_("Lock: definition '{lock_string}' has syntax errors.").format(
lock_string=raw_lockstring
)
)
continue continue
if access_type in locks: if access_type in locks:
duplicates += 1 duplicates += 1

View file

@ -10,6 +10,7 @@ from evennia.objects.models import ObjectDB
from django.contrib.admin.utils import flatten_fieldsets from django.contrib.admin.utils import flatten_fieldsets
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
class ObjectAttributeInline(AttributeInline): class ObjectAttributeInline(AttributeInline):
""" """
Defines inline descriptions of Attributes (experimental) Defines inline descriptions of Attributes (experimental)
@ -61,7 +62,7 @@ class ObjectCreateForm(forms.ModelForm):
required=False, required=False,
widget=forms.TextInput(attrs={"size": "78"}), widget=forms.TextInput(attrs={"size": "78"}),
help_text="Most non-character objects don't need a cmdset" help_text="Most non-character objects don't need a cmdset"
" and can leave this field blank." " and can leave this field blank.",
) )
raw_id_fields = ("db_destination", "db_location", "db_home") raw_id_fields = ("db_destination", "db_location", "db_home")

View file

@ -261,6 +261,7 @@ if TELNET_ENABLED:
# Start telnet game connections # Start telnet game connections
from evennia.server.portal import telnet from evennia.server.portal import telnet
_telnet_protocol = class_from_module(settings.TELNET_PROTOCOL_CLASS) _telnet_protocol = class_from_module(settings.TELNET_PROTOCOL_CLASS)
for interface in TELNET_INTERFACES: for interface in TELNET_INTERFACES:
@ -285,6 +286,7 @@ if SSL_ENABLED:
# 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
_ssl_protocol = class_from_module(settings.SSL_PROTOCOL_CLASS) _ssl_protocol = class_from_module(settings.SSL_PROTOCOL_CLASS)
for interface in SSL_INTERFACES: for interface in SSL_INTERFACES:
@ -319,6 +321,7 @@ if SSH_ENABLED:
# evennia/game if necessary. # evennia/game if necessary.
from evennia.server.portal import ssh from evennia.server.portal import ssh
_ssh_protocol = class_from_module(settings.SSH_PROTOCOL_CLASS) _ssh_protocol = class_from_module(settings.SSH_PROTOCOL_CLASS)
for interface in SSH_INTERFACES: for interface in SSH_INTERFACES:
@ -328,11 +331,7 @@ if SSH_ENABLED:
for port in SSH_PORTS: for port in SSH_PORTS:
pstring = "%s:%s" % (ifacestr, port) pstring = "%s:%s" % (ifacestr, port)
factory = ssh.makeFactory( factory = ssh.makeFactory(
{ {"protocolFactory": _ssh_protocol, "protocolArgs": (), "sessions": PORTAL_SESSIONS,}
"protocolFactory": _ssh_protocol,
"protocolArgs": (),
"sessions": PORTAL_SESSIONS,
}
) )
factory.noisy = False factory.noisy = False
ssh_service = internet.TCPServer(port, factory, interface=interface) ssh_service = internet.TCPServer(port, factory, interface=interface)

View file

@ -468,7 +468,11 @@ def getKeyPair(pubkeyfile, privkeyfile):
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric import rsa
rsa_key = Key(rsa.generate_private_key(public_exponent=65537, key_size=_KEY_LENGTH, backend=default_backend())) rsa_key = Key(
rsa.generate_private_key(
public_exponent=65537, key_size=_KEY_LENGTH, backend=default_backend()
)
)
public_key_string = rsa_key.public().toString(type="OPENSSH").decode() public_key_string = rsa_key.public().toString(type="OPENSSH").decode()
private_key_string = rsa_key.toString(type="OPENSSH").decode() private_key_string = rsa_key.toString(type="OPENSSH").decode()

View file

@ -58,7 +58,6 @@ _HTTP_WARNING = bytes(
_BASE_SESSION_CLASS = class_from_module(settings.BASE_SESSION_CLASS) _BASE_SESSION_CLASS = class_from_module(settings.BASE_SESSION_CLASS)
class TelnetServerFactory(protocol.ServerFactory): class TelnetServerFactory(protocol.ServerFactory):
"This is only to name this better in logs" "This is only to name this better in logs"
noisy = False noisy = False

View file

@ -101,7 +101,9 @@ class Session(object):
the keys given by self._attrs_to_sync. the keys given by self._attrs_to_sync.
""" """
return {attr: getattr(self, attr) for attr in settings.SESSION_SYNC_ATTRS if hasattr(self, attr)} return {
attr: getattr(self, attr) for attr in settings.SESSION_SYNC_ATTRS if hasattr(self, attr)
}
def load_sync_data(self, sessdata): def load_sync_data(self, sessdata):
""" """

View file

@ -23,7 +23,7 @@ from evennia.utils.utils import (
make_iter, make_iter,
delay, delay,
callables_from_module, callables_from_module,
class_from_module class_from_module,
) )
from evennia.server.portal import amp from evennia.server.portal import amp
from evennia.server.signals import SIGNAL_ACCOUNT_POST_LOGIN, SIGNAL_ACCOUNT_POST_LOGOUT from evennia.server.signals import SIGNAL_ACCOUNT_POST_LOGIN, SIGNAL_ACCOUNT_POST_LOGOUT

View file

@ -1055,13 +1055,13 @@ SESSION_SYNC_ATTRS = (
"cmd_total", "cmd_total",
"protocol_flags", "protocol_flags",
"server_data", "server_data",
"cmdset_storage_string" "cmdset_storage_string",
) )
# The following are used for the communications between the Portal and Server. # The following are used for the communications between the Portal and Server.
# Very dragons territory. # Very dragons territory.
AMP_SERVER_PROTOCOL_CLASS = 'evennia.server.portal.amp_server.AMPServerProtocol' AMP_SERVER_PROTOCOL_CLASS = "evennia.server.portal.amp_server.AMPServerProtocol"
AMP_CLIENT_PROTOCOL_CLASS = 'evennia.server.amp_client.AMPServerClientProtocol' AMP_CLIENT_PROTOCOL_CLASS = "evennia.server.amp_client.AMPServerClientProtocol"
###################################################################### ######################################################################

View file

@ -32,7 +32,6 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
# Attribute manager methods # Attribute manager methods
def get_attribute( def get_attribute(
self, key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None, **kwargs self, key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None, **kwargs
): ):
""" """
Return Attribute objects by key, by category, by value, by Return Attribute objects by key, by category, by value, by
@ -104,8 +103,9 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
key=key, category=category, value=value, strvalue=strvalue, obj=obj key=key, category=category, value=value, strvalue=strvalue, obj=obj
) )
def get_by_attribute(self, key=None, category=None, value=None, def get_by_attribute(
strvalue=None, attrtype=None, **kwargs): self, key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
):
""" """
Return objects having attributes with the given key, category, Return objects having attributes with the given key, category,
value, strvalue or combination of those criteria. value, strvalue or combination of those criteria.

View file

@ -205,29 +205,33 @@ help_entries = search_help
# not the attribute object itself (this is usually what you want) # not the attribute object itself (this is usually what you want)
def search_object_attribute(key=None, category=None, value=None, def search_object_attribute(
strvalue=None, attrtype=None, **kwargs): key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
):
return ObjectDB.objects.get_by_attribute( return ObjectDB.objects.get_by_attribute(
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
) )
def search_account_attribute(key=None, category=None, value=None, def search_account_attribute(
strvalue=None, attrtype=None, **kwargs): key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
):
return AccountDB.objects.get_by_attribute( return AccountDB.objects.get_by_attribute(
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
) )
def search_script_attribute(key=None, category=None, value=None, def search_script_attribute(
strvalue=None, attrtype=None, **kwargs): key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
):
return ScriptDB.objects.get_by_attribute( return ScriptDB.objects.get_by_attribute(
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
) )
def search_channel_attribute(key=None, category=None, value=None, def search_channel_attribute(
strvalue=None, attrtype=None, **kwargs): key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs
):
return Channel.objects.get_by_attribute( return Channel.objects.get_by_attribute(
key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs key=key, category=category, value=value, strvalue=strvalue, attrtype=attrtype, **kwargs
) )

View file

@ -2041,7 +2041,9 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs):
if multimatch_string: if multimatch_string:
error = "%s\n" % multimatch_string error = "%s\n" % multimatch_string
else: else:
error = _("More than one match for '{query}' (please narrow target):\n").format(query=query) error = _("More than one match for '{query}' (please narrow target):\n").format(
query=query
)
for num, result in enumerate(matches): for num, result in enumerate(matches):
# we need to consider Commands, where .aliases is a list # we need to consider Commands, where .aliases is a list

View file

@ -67,7 +67,11 @@ def datetime(entry, option_key="Datetime", account=None, from_tz=None, **kwargs)
try: try:
from_tz = _pytz.timezone(acct_tz) from_tz = _pytz.timezone(acct_tz)
except Exception as err: except Exception as err:
raise ValueError(_("Timezone string '{acct_tz}' is not a valid timezone ({err})").format(acct_tz=acct_tz, err=err)) raise ValueError(
_("Timezone string '{acct_tz}' is not a valid timezone ({err})").format(
acct_tz=acct_tz, err=err
)
)
else: else:
from_tz = _pytz.UTC from_tz = _pytz.UTC