Be more lenient with iterables sent to msg(text=..)
This will enforce that the text argument must either be a string or a tuple.
This commit is contained in:
parent
70dbaf8bf4
commit
2e1ca526c6
2 changed files with 17 additions and 2 deletions
|
|
@ -21,7 +21,7 @@ from evennia.objects.models import ObjectDB
|
||||||
from evennia.comms.models import ChannelDB
|
from evennia.comms.models import ChannelDB
|
||||||
from evennia.commands import cmdhandler
|
from evennia.commands import cmdhandler
|
||||||
from evennia.utils import logger
|
from evennia.utils import logger
|
||||||
from evennia.utils.utils import (lazy_property,
|
from evennia.utils.utils import (lazy_property, to_str,
|
||||||
make_iter, to_unicode, is_iter,
|
make_iter, to_unicode, is_iter,
|
||||||
variable_from_module)
|
variable_from_module)
|
||||||
from evennia.typeclasses.attributes import NickHandler
|
from evennia.typeclasses.attributes import NickHandler
|
||||||
|
|
@ -421,6 +421,13 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
||||||
|
|
||||||
kwargs["options"] = options
|
kwargs["options"] = options
|
||||||
|
|
||||||
|
if text and not (isinstance(text, basestring) or isinstance(text, tuple)):
|
||||||
|
# sanitize text before sending across the wire
|
||||||
|
try:
|
||||||
|
text = to_str(text, force_string=True)
|
||||||
|
except Exception:
|
||||||
|
text = repr(text)
|
||||||
|
|
||||||
# session relay
|
# session relay
|
||||||
sessions = make_iter(session) if session else self.sessions.all()
|
sessions = make_iter(session) if session else self.sessions.all()
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ from evennia.commands import cmdhandler
|
||||||
from evennia.utils import search
|
from evennia.utils import search
|
||||||
from evennia.utils import logger
|
from evennia.utils import logger
|
||||||
from evennia.utils.utils import (variable_from_module, lazy_property,
|
from evennia.utils.utils import (variable_from_module, lazy_property,
|
||||||
make_iter, to_unicode, is_iter)
|
make_iter, to_unicode, is_iter, to_str)
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
_MULTISESSION_MODE = settings.MULTISESSION_MODE
|
_MULTISESSION_MODE = settings.MULTISESSION_MODE
|
||||||
|
|
@ -528,11 +528,19 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
|
|
||||||
kwargs["options"] = options
|
kwargs["options"] = options
|
||||||
|
|
||||||
|
if text and not (isinstance(text, basestring) or isinstance(text, tuple)):
|
||||||
|
# sanitize text before sending across the wire
|
||||||
|
try:
|
||||||
|
text = to_str(text, force_string=True)
|
||||||
|
except Exception:
|
||||||
|
text = repr(text)
|
||||||
|
|
||||||
# relay to session(s)
|
# relay to session(s)
|
||||||
sessions = make_iter(session) if session else self.sessions.all()
|
sessions = make_iter(session) if session else self.sessions.all()
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
session.data_out(text=text, **kwargs)
|
session.data_out(text=text, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def for_contents(self, func, exclude=None, **kwargs):
|
def for_contents(self, func, exclude=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Runs a function on every object contained within this one.
|
Runs a function on every object contained within this one.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue