Converted encoding setting to use protocol_flags rather than being stored on-session. Also renamed the 256 COLORS TTYPE setting to XTERM256 which is more accurate (and doesn't have a space)

This commit is contained in:
Griatch 2016-03-25 13:01:21 +01:00
parent 1ddfbca7ea
commit 11ecdef7c8
8 changed files with 39 additions and 29 deletions

View file

@ -54,7 +54,6 @@ def text(session, *args, **kwargs):
if text is None:
return
# this is treated as a command input
#text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
# handle the 'idle' command
if text.strip() == _IDLE_COMMAND:
session.update_session_counters(idle=True)
@ -122,7 +121,7 @@ def client_settings(session, *args, **kwargs):
elif key == "ansi":
flags["ANSI"] = bool(value)
elif key == "xterm256":
flags["256 COLORS"] = bool(value)
flags["XTERM256"] = bool(value)
elif key == "mxp":
flags["MXP"] = bool(value)
elif key == "utf-8":

View file

@ -254,7 +254,7 @@ class SshProtocol(Manhole, session.Session):
# handle arguments
options = kwargs.get("options", {})
flags = self.protocol_flags
xterm256 = options.get("xterm256", flags.get('256 COLORS', False) if flags["TTYPE"] else True)
xterm256 = options.get("xterm256", flags.get('XTERM256', False) if flags["TTYPE"] else True)
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
raw = options.get("raw", False)
nomarkup = options.get("nomarkup", not (xterm256 or useansi))

View file

@ -304,7 +304,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
# handle arguments
options = kwargs.get("options", {})
flags = self.protocol_flags
xterm256 = options.get("xterm256", flags.get('256 COLORS', False) if flags["TTYPE"] else True)
xterm256 = options.get("xterm256", flags.get('XTERM256', False) if flags["TTYPE"] else True)
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
raw = options.get("raw", False)
nomarkup = options.get("nomarkup", not (xterm256 or useansi))

View file

@ -19,10 +19,10 @@ SEND = chr(1)
# terminal capabilities and their codes
MTTS = [(128, 'PROXY'),
(64, 'SCREEN READER'),
(32, 'OSC COLOR PALETTE'),
(16, 'MOUSE TRACKING'),
(8, '256 COLORS'),
(64, 'SCREENREADER'),
(32, 'OSC_COLOR_PALETTE'),
(16, 'MOUSE_TRACKING'),
(8, 'XTERM256'),
(4, 'UTF-8'),
(2, 'VT100'),
(1, 'ANSI')]
@ -120,7 +120,7 @@ class Ttype(object):
# all clients supporting TTYPE at all seem to support ANSI
self.protocol.protocol_flags['ANSI'] = True
self.protocol.protocol_flags['256 COLORS'] = xterm256
self.protocol.protocol_flags['XTERM256'] = xterm256
self.protocol.protocol_flags['CLIENTNAME'] = clientname
self.protocol.requestNegotiation(TTYPE, SEND)
@ -133,7 +133,7 @@ class Ttype(object):
not term.endswith("-color"))
if xterm256:
self.protocol.protocol_flags['ANSI'] = True
self.protocol.protocol_flags['256 COLORS'] = xterm256
self.protocol.protocol_flags['XTERM256'] = xterm256
self.protocol.protocol_flags['TERM'] = term
# request next information
self.protocol.requestNegotiation(TTYPE, SEND)

View file

@ -37,7 +37,7 @@ class Session(object):
# names of attributes that should be affected by syncing.
_attrs_to_sync = ('protocol_key', 'address', 'suid', 'sessid', 'uid',
'uname', 'logged_in', 'puid', 'encoding',
'uname', 'logged_in', 'puid',
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
'protocol_flags', 'server_data', "cmdset_storage_string")
@ -79,9 +79,8 @@ class Session(object):
self.cmd_last_visible = self.conn_time
self.cmd_last = self.conn_time
self.cmd_total = 0
self.encoding = "utf-8"
self.protocol_flags = {}
self.protocol_flags = {"ENCODING": "utf-8", "SCREENREADER":False}
self.server_data = {}
# map of input data to session methods

View file

@ -168,11 +168,11 @@ class SessionHandler(dict):
elif isinstance(data, basestring):
# make sure strings are in a valid encoding
try:
data = data and to_str(to_unicode(data), encoding=session.encoding)
data = data and to_str(to_unicode(data), encoding=session.protocol_flags["ENCODING"])
except LookupError:
# wrong encoding set on the session. Set it to a safe one
session.encoding = "utf-8"
data = to_str(to_unicode(data), encoding=session.encoding)
session.protocol_flags["ENCODING"] = "utf-8"
data = to_str(to_unicode(data), encoding=session.protocol_flags["ENCODING"])
if _INLINEFUNC_ENABLED and not raw:
data = parse_inlinefunc(data, strip=strip_inlinefunc, session=session) # deprecated!
data = parse_nested_inlinefunc(data, strip=strip_inlinefunc, session=session)