Cleaned up worst instability. Test suite does validate yet.

This commit is contained in:
Griatch 2013-09-21 17:33:48 +02:00
parent fa93c70e7f
commit e36c7d5cc1
24 changed files with 134 additions and 300 deletions

View file

@ -121,7 +121,7 @@ class PortalSessionHandler(SessionHandler):
return [sess for sess in self.get_sessions(include_unloggedin=True)
if hasattr(sess, 'suid') and sess.suid == suid]
def data_in(self, session, string="", data=""):
def data_in(self, session, string="", **kwargs):
"""
Called by portal sessions for relaying data coming
in from the protocol to the server. data is
@ -130,7 +130,7 @@ class PortalSessionHandler(SessionHandler):
#print "portal_data_in:", string
self.portal.amp_protocol.call_remote_MsgPortal2Server(session.sessid,
msg=string,
data=data)
data=kwargs)
def announce_all(self, message):
"""
Send message to all connection sessions
@ -138,30 +138,13 @@ class PortalSessionHandler(SessionHandler):
for session in self.sessions.values():
session.data_out(message)
def data_out(self, sessid, string="", data=""):
def data_out(self, sessid, text=None, **kwargs):
"""
Called by server for having the portal relay messages and data
to the correct session protocol.
"""
session = self.sessions.get(sessid, None)
if session:
session.data_out(string, data=data)
def oob_data_in(self, session, data):
"""
OOB (Out-of-band) data Portal -> Server
"""
print "portal_oob_data_in:", data
self.portal.amp_protocol.call_remote_OOBPortal2Server(session.sessid,
data=data)
def oob_data_out(self, sessid, data):
"""
OOB (Out-of-band) data Server -> Portal
"""
print "portal_oob_data_out:", data
session = self.sessions.get(sessid, None)
if session:
session.oob_data_out(data)
session.data_out(text=text, **kwargs)
PORTAL_SESSIONS = PortalSessionHandler()

View file

@ -173,22 +173,22 @@ class SshProtocol(Manhole, session.Session):
self.data_out(reason)
self.connectionLost(reason)
def data_out(self, string, data=None):
def data_out(self, text=None, **kwargs):
"""
Data Evennia -> Player access hook. 'data' argument is a dict parsed for string settings.
ssh flags:
raw=True - leave all ansi markup and tokens unparsed
nomarkup=True - remove all ansi markup
"""
try:
string = utils.to_str(string, encoding=self.encoding)
text = utils.to_str(text if text else "", encoding=self.encoding)
except Exception, e:
self.lineSend(str(e))
return
nomarkup = False
raw = False
if type(data) == dict:
# check if we want escape codes to go through unparsed.
raw = data.get("raw", False)
# check if we want to remove all markup
nomarkup = data.get("nomarkup", False)
raw = kwargs.get("raw", False)
nomarkup = kwargs.get("nomarkup", False)
if raw:
self.lineSend(string)
else:

View file

@ -141,28 +141,31 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
self.data_out(reason)
self.connectionLost(reason)
def data_out(self, string, data=None):
def data_out(self, text=None, **kwargs):
"""
generic hook method for engine to call in order to send data
through the telnet connection.
Data Evennia -> Player.
data argument may contain a dict with output flags.
valid telnet kwargs:
raw=True - pass string through without any ansi processing (i.e. include Evennia
ansi markers but do not convert them into ansi tokens)
nomarkup=True - strip all ansi markup
The telnet ttype negotiation flags, if any, are used if no kwargs are given.
"""
try:
string = utils.to_str(string, encoding=self.encoding)
text = utils.to_str(text if text else "", encoding=self.encoding)
except Exception, e:
self.sendLine(str(e))
return
ttype = self.protocol_flags.get('TTYPE', {})
raw = kwargs.get("raw", False)
nomarkup = not (ttype or ttype.get('256 COLORS') or ttype.get('ANSI') or not ttype.get("init_done"))
raw = False
if type(data) == dict:
# check if we want escape codes to go through unparsed.
raw = data.get("raw", False)
# check if we want to remove all markup (TTYPE override)
nomarkup = data.get("nomarkup", False)
nomarkup = kwargs.get("nomarkup", nomarkup)
if raw:
self.sendLine(string)
# no processing whatsoever
self.sendLine(text)
else:
# we need to make sure to kill the color at the end in order to match the webclient output.
self.sendLine(ansi.parse_ansi(_RE_N.sub("", string) + "{n", strip_ansi=nomarkup, xterm256=ttype.get('256 COLORS')))
self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=ttype.get('256 COLORS')))

View file

@ -224,33 +224,24 @@ class WebClientSession(session.Session):
self.client.lineSend(self.suid, reason)
self.client.client_disconnect(self.suid)
def data_out(self, string='', data=None):
def data_out(self, text=None, **kwargs):
"""
Data Evennia -> Player access hook.
data argument may be used depending on
the client-server implementation.
webclient flags checked are
raw=True - no parsing at all (leave ansi-to-html markers unparsed)
nomarkup=True - clean out all ansi/html markers and tokens
"""
if data:
# treat data?
pass
# string handling is similar to telnet
try:
string = utils.to_str(string, encoding=self.encoding)
nomarkup = False
raw = False
if type(data) == dict:
# check if we want escape codes to go through unparsed.
raw = data.get("raw", False)
# check if we want to remove all markup
nomarkup = data.get("nomarkup", False)
text = utils.to_str(text if text else "", encoding=self.encoding)
raw = kwargs.get("raw", False)
nomarkup = kwargs.get("nomarkup", False)
if raw:
self.client.lineSend(self.suid, string)
self.client.lineSend(self.suid, text)
else:
self.client.lineSend(self.suid, parse_html(string, strip_ansi=nomarkup))
self.client.lineSend(self.suid, parse_html(text, strip_ansi=nomarkup))
return
except Exception, e:
except Exception:
logger.log_trace()