mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Merge pull request #1915 from kovitikus/myfixes
Updated various modules with f-strings.
This commit is contained in:
commit
73ba06d5f8
5 changed files with 56 additions and 58 deletions
|
|
@ -269,7 +269,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
return
|
||||
if not obj.access(self, 'puppet'):
|
||||
# no access
|
||||
self.msg("You don't have permission to puppet '%s'." % obj.key)
|
||||
self.msg(f"You don't have permission to puppet '{obj.key}'.")
|
||||
return
|
||||
if obj.account:
|
||||
# object already puppeted
|
||||
|
|
@ -278,19 +278,19 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
# we may take over another of our sessions
|
||||
# output messages to the affected sessions
|
||||
if _MULTISESSION_MODE in (1, 3):
|
||||
txt1 = "Sharing |c%s|n with another of your sessions."
|
||||
txt2 = "|c%s|n|G is now shared from another of your sessions.|n"
|
||||
self.msg(txt1 % obj.name, session=session)
|
||||
self.msg(txt2 % obj.name, session=obj.sessions.all())
|
||||
txt1 = f"Sharing |c{obj.name}|n with another of your sessions."
|
||||
txt2 = f"|c{obj.name}|n|G is now shared from another of your sessions.|n"
|
||||
self.msg(txt1, session=session)
|
||||
self.msg(txt2, session=obj.sessions.all())
|
||||
else:
|
||||
txt1 = "Taking over |c%s|n from another of your sessions."
|
||||
txt2 = "|c%s|n|R is now acted from another of your sessions.|n"
|
||||
self.msg(txt1 % obj.name, session=session)
|
||||
self.msg(txt2 % obj.name, session=obj.sessions.all())
|
||||
txt1 = f"Taking over |c{obj.name}|n from another of your sessions."
|
||||
txt2 = f"|c{obj.name}|n|R is now acted from another of your sessions.|n"
|
||||
self.msg(txt1, session=session)
|
||||
self.msg(txt2, session=obj.sessions.all())
|
||||
self.unpuppet_object(obj.sessions.get())
|
||||
elif obj.account.is_connected:
|
||||
# controlled by another account
|
||||
self.msg("|c%s|R is already puppeted by another Account." % obj.key)
|
||||
self.msg(f"|c{obj.key}|R is already puppeted by another Account.")
|
||||
return
|
||||
|
||||
# do the puppeting
|
||||
|
|
@ -439,9 +439,9 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
try:
|
||||
klass = import_string(validator['NAME'])
|
||||
except ImportError:
|
||||
msg = ("The module in NAME could not be imported: %s. "
|
||||
msg = (f"The module in NAME could not be imported: {validator['NAME']}. "
|
||||
"Check your AUTH_USERNAME_VALIDATORS setting.")
|
||||
raise ImproperlyConfigured(msg % validator['NAME'])
|
||||
raise ImproperlyConfigured(msg)
|
||||
objs.append(klass(**validator.get('OPTIONS', {})))
|
||||
return objs
|
||||
|
||||
|
|
@ -494,7 +494,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
# this is a banned IP or name!
|
||||
errors.append("|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('Authentication Denied (Banned): %s (IP: %s).' % (username, ip))
|
||||
logger.log_sec(f'Authentication Denied (Banned): {username} (IP: {ip}).')
|
||||
LOGIN_THROTTLE.update(ip, 'Too many sightings of banned artifact.')
|
||||
return None, errors
|
||||
|
||||
|
|
@ -505,7 +505,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
errors.append('Username and/or password is incorrect.')
|
||||
|
||||
# Log auth failures while throttle is inactive
|
||||
logger.log_sec('Authentication Failure: %s (IP: %s).' % (username, ip))
|
||||
logger.log_sec(f'Authentication Failure: {username} (IP: {ip}).')
|
||||
|
||||
# Update throttle
|
||||
if ip:
|
||||
|
|
@ -521,7 +521,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
return None, errors
|
||||
|
||||
# Account successfully authenticated
|
||||
logger.log_sec('Authentication Success: %s (IP: %s).' % (account, ip))
|
||||
logger.log_sec(f'Authentication Success: {account} (IP: {ip}).')
|
||||
return account, errors
|
||||
|
||||
@classmethod
|
||||
|
|
@ -629,7 +629,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
|
||||
"""
|
||||
super(DefaultAccount, self).set_password(password)
|
||||
logger.log_sec("Password successfully changed for %s." % self)
|
||||
logger.log_sec(f"Password successfully changed for {self}.")
|
||||
self.at_password_change()
|
||||
|
||||
@classmethod
|
||||
|
|
@ -706,7 +706,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
try:
|
||||
try:
|
||||
account = create.create_account(username, email, password, permissions=permissions, typeclass=typeclass)
|
||||
logger.log_sec('Account Created: %s (IP: %s).' % (account, ip))
|
||||
logger.log_sec(f'Account Created: {account} (IP: {ip}).')
|
||||
|
||||
except Exception as e:
|
||||
errors.append("There was an error creating the Account. If this problem persists, contact an admin.")
|
||||
|
|
@ -725,7 +725,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
# join the new account to the public channel
|
||||
pchannel = ChannelDB.objects.get_channel(settings.DEFAULT_CHANNELS[0]["key"])
|
||||
if not pchannel or not pchannel.connect(account):
|
||||
string = "New account '%s' could not connect to public channel!" % account.key
|
||||
string = f"New account '{account.key}' could not connect to public channel!"
|
||||
errors.append(string)
|
||||
logger.log_err(string)
|
||||
|
||||
|
|
@ -1034,7 +1034,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
updates = []
|
||||
if not cdict.get("key"):
|
||||
if not self.db_key:
|
||||
self.db_key = "#%i" % self.dbid
|
||||
self.db_key = f"#{self.dbid}"
|
||||
updates.append("db_key")
|
||||
elif self.key != cdict.get("key"):
|
||||
updates.append("db_key")
|
||||
|
|
@ -1156,9 +1156,9 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month,
|
||||
now.day, now.hour, now.minute)
|
||||
if _MUDINFO_CHANNEL:
|
||||
_MUDINFO_CHANNEL.tempmsg("[%s, %s]: %s" % (_MUDINFO_CHANNEL.key, now, message))
|
||||
_MUDINFO_CHANNEL.tempmsg(f"[{_MUDINFO_CHANNEL.key}, {now}]: {message}")
|
||||
else:
|
||||
logger.log_info("[%s]: %s" % (now, message))
|
||||
logger.log_info(f"[{now}]: {message}")
|
||||
|
||||
def at_post_login(self, session=None, **kwargs):
|
||||
"""
|
||||
|
|
@ -1185,7 +1185,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
if session:
|
||||
session.msg(logged_in={})
|
||||
|
||||
self._send_to_connect_channel("|G%s connected|n" % self.key)
|
||||
self._send_to_connect_channel(f"|G{self.key} connected|n")
|
||||
if _MULTISESSION_MODE == 0:
|
||||
# in this mode we should have only one character available. We
|
||||
# try to auto-connect to our last conneted object, if any
|
||||
|
|
@ -1235,8 +1235,8 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
|
||||
|
||||
"""
|
||||
reason = " (%s)" % reason if reason else ""
|
||||
self._send_to_connect_channel("|R%s disconnected%s|n" % (self.key, reason))
|
||||
reason = f" ({reason if reason else ''})"
|
||||
self._send_to_connect_channel(f"|R{self.key} disconnected{reason}|n")
|
||||
|
||||
def at_post_disconnect(self, **kwargs):
|
||||
"""
|
||||
|
|
@ -1353,12 +1353,12 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
is_su = self.is_superuser
|
||||
|
||||
# text shown when looking in the ooc area
|
||||
result = ["Account |g%s|n (you are Out-of-Character)" % self.key]
|
||||
result = [f"Account |g{self.key}|n (you are Out-of-Character)"]
|
||||
|
||||
nsess = len(sessions)
|
||||
result.append(nsess == 1 and
|
||||
"\n\n|wConnected session:|n" or
|
||||
"\n\n|wConnected sessions (%i):|n" % nsess)
|
||||
f"\n\n|wConnected sessions ({nsess}):|n")
|
||||
for isess, sess in enumerate(sessions):
|
||||
csessid = sess.sessid
|
||||
addr = "%s (%s)" % (sess.protocol_key, isinstance(sess.address, tuple) and
|
||||
|
|
@ -1385,7 +1385,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
string_s_ending = len(characters) > 1 and "s" or ""
|
||||
result.append("\n |w@ic <character>|n - enter the game (|w@ooc|n to get back here)")
|
||||
if is_su:
|
||||
result.append("\n\nAvailable character%s (%i/unlimited):" % (string_s_ending, len(characters)))
|
||||
result.append(f"\n\nAvailable character{string_s_ending} ({len(characters)}/unlimited):")
|
||||
else:
|
||||
result.append("\n\nAvailable character%s%s:"
|
||||
% (string_s_ending, charmax > 1 and " (%i/%i)" % (len(characters), charmax) or ""))
|
||||
|
|
@ -1397,14 +1397,12 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
|||
# character is already puppeted
|
||||
sid = sess in sessions and sessions.index(sess) + 1
|
||||
if sess and sid:
|
||||
result.append("\n - |G%s|n [%s] (played by you in session %i)"
|
||||
% (char.key, ", ".join(char.permissions.all()), sid))
|
||||
result.append(f"\n - |G{char.key}|n [{', '.join(char.permissions.all())}] (played by you in session {sid})")
|
||||
else:
|
||||
result.append("\n - |R%s|n [%s] (played by someone else)"
|
||||
% (char.key, ", ".join(char.permissions.all())))
|
||||
result.append(f"\n - |R{char.key}|n [{', '.join(char.permissions.all())}] (played by someone else)")
|
||||
else:
|
||||
# character is "free to puppet"
|
||||
result.append("\n - %s [%s]" % (char.key, ", ".join(char.permissions.all())))
|
||||
result.append(f"\n - {char.key} [{', '.join(char.permissions.all())}]")
|
||||
look_string = ("-" * 68) + "\n" + "".join(result) + "\n" + ("-" * 68)
|
||||
return look_string
|
||||
|
||||
|
|
@ -1499,7 +1497,7 @@ class DefaultGuest(DefaultAccount):
|
|||
overriding the call (unused by default).
|
||||
|
||||
"""
|
||||
self._send_to_connect_channel("|G%s connected|n" % self.key)
|
||||
self._send_to_connect_channel(f"|G{self.key} connected|n")
|
||||
self.puppet_object(session, self.db._last_puppet)
|
||||
|
||||
def at_server_shutdown(self):
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class Bot(DefaultAccount):
|
|||
"boot:perm(Admin);msg:false();noidletimeout:true()"
|
||||
self.locks.add(lockstring)
|
||||
# set the basics of being a bot
|
||||
script_key = "%s" % self.key
|
||||
script_key = str(self.key)
|
||||
self.scripts.add(BotStarter, key=script_key)
|
||||
self.is_bot = True
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ class IRCBot(Bot):
|
|||
# connect to Evennia channel
|
||||
channel = search.channel_search(ev_channel)
|
||||
if not channel:
|
||||
raise RuntimeError("Evennia Channel '%s' not found." % ev_channel)
|
||||
raise RuntimeError(f"Evennia Channel '{ev_channel}' not found.")
|
||||
channel = channel[0]
|
||||
channel.connect(self)
|
||||
self.db.ev_channel = channel
|
||||
|
|
@ -307,19 +307,19 @@ class IRCBot(Bot):
|
|||
if kwargs["type"] == "nicklist":
|
||||
# the return of a nicklist request
|
||||
if hasattr(self, "_nicklist_callers") and self._nicklist_callers:
|
||||
chstr = "%s (%s:%s)" % (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()))
|
||||
for obj in self._nicklist_callers:
|
||||
obj.msg("Nicks at %s:\n %s" % (chstr, nicklist))
|
||||
obj.msg(f"Nicks at {chstr}:\n {nicklist}")
|
||||
self._nicklist_callers = []
|
||||
return
|
||||
|
||||
elif kwargs["type"] == "ping":
|
||||
# the return of a ping
|
||||
if hasattr(self, "_ping_callers") and self._ping_callers:
|
||||
chstr = "%s (%s:%s)" % (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:
|
||||
obj.msg("IRC ping return from %s took %ss." % (chstr, kwargs["timing"]))
|
||||
obj.msg(f"IRC ping return from {chstr} took {kwargs['timing']}s.")
|
||||
self._ping_callers = []
|
||||
return
|
||||
|
||||
|
|
@ -341,10 +341,10 @@ class IRCBot(Bot):
|
|||
whos.append("%s (%s/%s)" % (utils.crop("|w%s|n" % account.name, width=25),
|
||||
utils.time_format(delta_conn, 0),
|
||||
utils.time_format(delta_cmd, 1)))
|
||||
text = "Who list (online/idle): %s" % ", ".join(sorted(whos, key=lambda w: w.lower()))
|
||||
text = f"Who list (online/idle): {', '.join(sorted(whos, key=lambda w: w.lower()))}"
|
||||
elif txt.lower().startswith("about"):
|
||||
# some bot info
|
||||
text = "This is an Evennia IRC bot connecting from '%s'." % settings.SERVERNAME
|
||||
text = f"This is an Evennia IRC bot connecting from '{settings.SERVERNAME}'."
|
||||
else:
|
||||
text = "I understand 'who' and 'about'."
|
||||
super().msg(privmsg=((text,), {"user": user}))
|
||||
|
|
@ -352,10 +352,10 @@ class IRCBot(Bot):
|
|||
# something to send to the main channel
|
||||
if kwargs["type"] == "action":
|
||||
# An action (irc pose)
|
||||
text = "%s@%s %s" % (kwargs["user"], kwargs["channel"], txt)
|
||||
text = f"{kwargs['user']}@{kwargs['channel']} {txt}"
|
||||
else:
|
||||
# msg - A normal channel message
|
||||
text = "%s@%s: %s" % (kwargs["user"], kwargs["channel"], txt)
|
||||
text = f"{kwargs['user']}@{kwargs['channel']}: {txt}"
|
||||
|
||||
if not self.ndb.ev_channel and self.db.ev_channel:
|
||||
# cache channel lookup
|
||||
|
|
@ -401,7 +401,7 @@ class RSSBot(Bot):
|
|||
# connect to Evennia channel
|
||||
channel = search.channel_search(ev_channel)
|
||||
if not channel:
|
||||
raise RuntimeError("Evennia Channel '%s' not found." % ev_channel)
|
||||
raise RuntimeError(f"Evennia Channel '{ev_channel}' not found.")
|
||||
channel = channel[0]
|
||||
self.db.ev_channel = channel
|
||||
if rss_url:
|
||||
|
|
@ -463,7 +463,7 @@ class GrapevineBot(Bot):
|
|||
# connect to Evennia channel
|
||||
channel = search.channel_search(ev_channel)
|
||||
if not channel:
|
||||
raise RuntimeError("Evennia Channel '%s' not found." % ev_channel)
|
||||
raise RuntimeError(f"Evennia Channel '{ev_channel}' not found.")
|
||||
channel = channel[0]
|
||||
channel.connect(self)
|
||||
self.db.ev_channel = channel
|
||||
|
|
|
|||
|
|
@ -164,9 +164,9 @@ class AccountDBManager(TypedObjectManager, UserManager):
|
|||
if typeclass:
|
||||
# we accept both strings and actual typeclasses
|
||||
if callable(typeclass):
|
||||
typeclass = "%s.%s" % (typeclass.__module__, typeclass.__name__)
|
||||
typeclass = f"{typeclass.__module__}.{typeclass.__name__}"
|
||||
else:
|
||||
typeclass = "%s" % typeclass
|
||||
typeclass = str(typeclass)
|
||||
query["db_typeclass_path"] = typeclass
|
||||
if exact:
|
||||
matches = self.filter(**query)
|
||||
|
|
|
|||
|
|
@ -137,10 +137,10 @@ class AccountDB(TypedObject, AbstractUser):
|
|||
#
|
||||
|
||||
def __str__(self):
|
||||
return smart_str("%s(account %s)" % (self.name, self.dbid))
|
||||
return smart_str(f"{self.name}(account {self.dbid})")
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(account#%s)" % (self.name, self.dbid)
|
||||
return f"{self.name}(account#{self.dbid})"
|
||||
|
||||
#@property
|
||||
def __username_get(self):
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TestAccountSessionHandler(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.account = create.create_account(
|
||||
"TestAccount%s" % randint(0, 999999), email="test@test.com",
|
||||
f"TestAccount{randint(0, 999999)}", email="test@test.com",
|
||||
password="testpassword", typeclass=DefaultAccount)
|
||||
self.handler = AccountSessionHandler(self.account)
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ class TestDefaultAccountAuth(EvenniaTest):
|
|||
|
||||
self.password = "testpassword"
|
||||
self.account.delete()
|
||||
self.account = create.create_account("TestAccount%s" % randint(100000, 999999), email="test@test.com", password=self.password, typeclass=DefaultAccount)
|
||||
self.account = create.create_account(f"TestAccount{randint(100000, 999999)}", email="test@test.com", password=self.password, typeclass=DefaultAccount)
|
||||
|
||||
def test_authentication(self):
|
||||
"Confirm Account authentication method is authenticating/denying users."
|
||||
|
|
@ -170,7 +170,7 @@ class TestDefaultAccountAuth(EvenniaTest):
|
|||
def test_password_validation(self):
|
||||
"Check password validators deny bad passwords"
|
||||
|
||||
account = create.create_account("TestAccount%s" % randint(100000, 999999),
|
||||
account = create.create_account(f"TestAccount{randint(100000, 999999)}",
|
||||
email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
for bad in ('', '123', 'password', 'TestAccount', '#', 'xyzzy'):
|
||||
self.assertFalse(account.validate_password(bad, account=self.account)[0])
|
||||
|
|
@ -182,7 +182,7 @@ class TestDefaultAccountAuth(EvenniaTest):
|
|||
|
||||
def test_password_change(self):
|
||||
"Check password setting and validation is working as expected"
|
||||
account = create.create_account("TestAccount%s" % randint(100000, 999999),
|
||||
account = create.create_account(f"TestAccount{randint(100000, 999999)}",
|
||||
email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
|
@ -228,7 +228,7 @@ class TestDefaultAccount(TestCase):
|
|||
import evennia.server.sessionhandler
|
||||
|
||||
account = create.create_account(
|
||||
"TestAccount%s" % randint(0, 999999), email="test@test.com",
|
||||
f"TestAccount{randint(0, 999999)}", email="test@test.com",
|
||||
password="testpassword", typeclass=DefaultAccount)
|
||||
self.s1.uid = account.uid
|
||||
evennia.server.sessionhandler.SESSIONS[self.s1.uid] = self.s1
|
||||
|
|
@ -247,7 +247,7 @@ class TestDefaultAccount(TestCase):
|
|||
|
||||
import evennia.server.sessionhandler
|
||||
|
||||
account = create.create_account("TestAccount%s" % randint(0, 999999), email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
account = create.create_account(f"TestAccount{randint(0, 999999)}", email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
self.s1.uid = account.uid
|
||||
evennia.server.sessionhandler.SESSIONS[self.s1.uid] = self.s1
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ class TestDefaultAccount(TestCase):
|
|||
|
||||
import evennia.server.sessionhandler
|
||||
|
||||
account = create.create_account("TestAccount%s" % randint(0, 999999), email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
account = create.create_account(f"TestAccount{randint(0, 999999)}", email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
self.s1.uid = account.uid
|
||||
evennia.server.sessionhandler.SESSIONS[self.s1.uid] = self.s1
|
||||
|
||||
|
|
@ -289,7 +289,7 @@ class TestDefaultAccount(TestCase):
|
|||
|
||||
import evennia.server.sessionhandler
|
||||
|
||||
account = create.create_account("TestAccount%s" % randint(0, 999999), email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
account = create.create_account(f"TestAccount{randint(0, 999999)}", email="test@test.com", password="testpassword", typeclass=DefaultAccount)
|
||||
self.account = account
|
||||
self.s1.uid = account.uid
|
||||
evennia.server.sessionhandler.SESSIONS[self.s1.uid] = self.s1
|
||||
|
|
@ -325,7 +325,7 @@ class TestAccountPuppetDeletion(EvenniaTest):
|
|||
self.char1.delete()
|
||||
# Playable char list should be empty.
|
||||
self.assertFalse(self.account.db._playable_characters,
|
||||
'Playable character list is not empty! %s' % self.account.db._playable_characters)
|
||||
f'Playable character list is not empty! {self.account.db._playable_characters}')
|
||||
|
||||
|
||||
class TestDefaultAccountEv(EvenniaTest):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue