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:
parent
a749f0c5ca
commit
c4c662b33e
3 changed files with 13 additions and 9 deletions
|
|
@ -13,7 +13,7 @@ from django.conf import settings
|
||||||
#from src.scripts.models import ScriptDB
|
#from src.scripts.models import ScriptDB
|
||||||
from src.comms.models import ChannelDB
|
from src.comms.models import ChannelDB
|
||||||
from src.utils import logger, utils
|
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.cmdhandler import cmdhandler
|
||||||
from src.commands.cmdsethandler import CmdSetHandler
|
from src.commands.cmdsethandler import CmdSetHandler
|
||||||
from src.server.session import Session
|
from src.server.session import Session
|
||||||
|
|
@ -198,7 +198,7 @@ class ServerSession(Session):
|
||||||
"""
|
"""
|
||||||
if text:
|
if text:
|
||||||
# this is treated as a command input
|
# 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
|
# handle the 'idle' command
|
||||||
if text.strip() == IDLE_COMMAND:
|
if text.strip() == IDLE_COMMAND:
|
||||||
self.update_session_counters(idle=True)
|
self.update_session_counters(idle=True)
|
||||||
|
|
@ -231,11 +231,12 @@ class ServerSession(Session):
|
||||||
"""
|
"""
|
||||||
Send Evennia -> User
|
Send Evennia -> User
|
||||||
"""
|
"""
|
||||||
if text is None:
|
text = text if text else ""
|
||||||
text = ""
|
#if text is None:
|
||||||
else:
|
# text = ""
|
||||||
text = to_unicode(text)
|
#else:
|
||||||
text = to_str(text, self.encoding)
|
# text = to_unicode(text)
|
||||||
|
# text = to_str(text, self.encoding)
|
||||||
|
|
||||||
self.sessionhandler.data_out(self, text=text, **kwargs)
|
self.sessionhandler.data_out(self, text=text, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ There are two similar but separate stores of sessions:
|
||||||
import time
|
import time
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.commands.cmdhandler import CMD_LOGINSTART
|
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:
|
try:
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -469,6 +470,7 @@ class ServerSessionHandler(SessionHandler):
|
||||||
"""
|
"""
|
||||||
Sending data Server -> Portal
|
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,
|
self.server.amp_protocol.call_remote_MsgServer2Portal(sessid=session.sessid,
|
||||||
msg=text,
|
msg=text,
|
||||||
data=kwargs)
|
data=kwargs)
|
||||||
|
|
@ -479,6 +481,7 @@ class ServerSessionHandler(SessionHandler):
|
||||||
"""
|
"""
|
||||||
session = self.sessions.get(sessid, None)
|
session = self.sessions.get(sessid, None)
|
||||||
if session:
|
if session:
|
||||||
|
text = text and to_unicode(strip_control_sequences(text), encoding=session.encoding)
|
||||||
session.data_in(text=text, **kwargs)
|
session.data_in(text=text, **kwargs)
|
||||||
|
|
||||||
SESSIONS = ServerSessionHandler()
|
SESSIONS = ServerSessionHandler()
|
||||||
|
|
|
||||||
|
|
@ -1105,7 +1105,7 @@ class lazy_property(object):
|
||||||
|
|
||||||
_STRIP_ANSI = None
|
_STRIP_ANSI = None
|
||||||
_RE_CONTROL_CHAR = re.compile('[%s]' % re.escape(''.join([unichr(c) for c in range(0,32)])))# + range(127,160)])))
|
_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.
|
remove non-print text sequences from string.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue