Moved unicode/str conversions to sessionhandler level in order to still allow message_all session messages without triggering unicode tracebacks (such as when server restarts).

This commit is contained in:
Griatch 2014-09-10 09:33:44 +02:00
parent a749f0c5ca
commit c4c662b33e
3 changed files with 13 additions and 9 deletions

View file

@ -13,7 +13,7 @@ from django.conf import settings
#from src.scripts.models import ScriptDB
from src.comms.models import ChannelDB
from src.utils import logger, utils
from src.utils.utils import make_iter, to_unicode, to_str, escape_control_sequences
from src.utils.utils import make_iter
from src.commands.cmdhandler import cmdhandler
from src.commands.cmdsethandler import CmdSetHandler
from src.server.session import Session
@ -198,7 +198,7 @@ class ServerSession(Session):
"""
if text:
# this is treated as a command input
text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
#text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
# handle the 'idle' command
if text.strip() == IDLE_COMMAND:
self.update_session_counters(idle=True)
@ -231,11 +231,12 @@ class ServerSession(Session):
"""
Send Evennia -> User
"""
if text is None:
text = ""
else:
text = to_unicode(text)
text = to_str(text, self.encoding)
text = text if text else ""
#if text is None:
# text = ""
#else:
# text = to_unicode(text)
# text = to_str(text, self.encoding)
self.sessionhandler.data_out(self, text=text, **kwargs)

View file

@ -15,7 +15,8 @@ There are two similar but separate stores of sessions:
import time
from django.conf import settings
from src.commands.cmdhandler import CMD_LOGINSTART
from src.utils.utils import variable_from_module, is_iter
from src.utils.utils import variable_from_module, is_iter, \
to_str, to_unicode, strip_control_sequences
try:
import cPickle as pickle
except ImportError:
@ -469,6 +470,7 @@ class ServerSessionHandler(SessionHandler):
"""
Sending data Server -> Portal
"""
text = text and to_str(to_unicode(text), encoding=session.encoding)
self.server.amp_protocol.call_remote_MsgServer2Portal(sessid=session.sessid,
msg=text,
data=kwargs)
@ -479,6 +481,7 @@ class ServerSessionHandler(SessionHandler):
"""
session = self.sessions.get(sessid, None)
if session:
text = text and to_unicode(strip_control_sequences(text), encoding=session.encoding)
session.data_in(text=text, **kwargs)
SESSIONS = ServerSessionHandler()

View file

@ -1105,7 +1105,7 @@ class lazy_property(object):
_STRIP_ANSI = None
_RE_CONTROL_CHAR = re.compile('[%s]' % re.escape(''.join([unichr(c) for c in range(0,32)])))# + range(127,160)])))
def escape_control_sequences(string):
def strip_control_sequences(string):
"""
remove non-print text sequences from string.
"""