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:
parent
1ddfbca7ea
commit
11ecdef7c8
8 changed files with 39 additions and 29 deletions
|
|
@ -401,12 +401,19 @@ class CmdOption(MuxPlayerCommand):
|
||||||
|
|
||||||
if not self.args:
|
if not self.args:
|
||||||
# list the option settings
|
# list the option settings
|
||||||
string = "{wEncoding{n:\n"
|
flags = self.session.protocol_flags
|
||||||
pencoding = self.session.encoding or "None"
|
keys = sorted(flags)
|
||||||
sencodings = settings.ENCODINGS
|
options = "\n".join(" {w%s{n: %s" % (key, flags[key]) for key in keys)
|
||||||
string += " Custom: %s\n Server: %s" % (pencoding, ", ".join(sencodings))
|
self.msg("{wClient settings:\n%s" % options)
|
||||||
string += "\n{wScreen Reader mode:{n %s" % self.session.protocol_flags.get("SCREENREADER", False)
|
#string = "{wEncoding{n:\n"
|
||||||
self.msg(string)
|
#pencoding = flags.get("ENCODING", "None")
|
||||||
|
#sencodings = settings.ENCODINGS
|
||||||
|
#string += " Custom: %s\n Server: %s" % (pencoding, ", ".join(sencodings))
|
||||||
|
#string += "\n{wScreen Reader mode:{n %s" % flags.get("SCREENREADER", False)
|
||||||
|
## display all
|
||||||
|
#keys =
|
||||||
|
#string += "\n{wClient settings (read-only):\n%s" % options
|
||||||
|
#self.msg(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.rhs:
|
if not self.rhs:
|
||||||
|
|
@ -417,14 +424,14 @@ class CmdOption(MuxPlayerCommand):
|
||||||
|
|
||||||
if self.lhs == "encoding":
|
if self.lhs == "encoding":
|
||||||
# change encoding
|
# change encoding
|
||||||
old_encoding = self.session.encoding
|
old_encoding = self.session.protocol_flags["ENCODING"]
|
||||||
new_encoding = self.rhs.strip() or "utf-8"
|
new_encoding = self.rhs.strip() or "utf-8"
|
||||||
try:
|
try:
|
||||||
utils.to_str(utils.to_unicode("test-string"), encoding=new_encoding)
|
utils.to_str(utils.to_unicode("test-string"), encoding=new_encoding)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (new_encoding, old_encoding)
|
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (new_encoding, old_encoding)
|
||||||
else:
|
else:
|
||||||
self.session.encoding = new_encoding
|
self.session.protocol_flags["ENCODING"] = new_encoding
|
||||||
string = "Encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, new_encoding)
|
string = "Encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, new_encoding)
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -459,17 +459,19 @@ class CmdUnconnectedEncoding(MuxCommand):
|
||||||
if self.session is None:
|
if self.session is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
sync = False
|
||||||
if 'clear' in self.switches:
|
if 'clear' in self.switches:
|
||||||
# remove customization
|
# remove customization
|
||||||
old_encoding = self.session.encoding
|
old_encoding = self.session.protocol_flags.get("ENCODING", None)
|
||||||
if old_encoding:
|
if old_encoding:
|
||||||
string = "Your custom text encoding ('%s') was cleared." % old_encoding
|
string = "Your custom text encoding ('%s') was cleared." % old_encoding
|
||||||
else:
|
else:
|
||||||
string = "No custom encoding was set."
|
string = "No custom encoding was set."
|
||||||
self.session.encoding = "utf-8"
|
self.session.protocol_flags["ENCODING"] = "utf-8"
|
||||||
|
sync = True
|
||||||
elif not self.args:
|
elif not self.args:
|
||||||
# just list the encodings supported
|
# just list the encodings supported
|
||||||
pencoding = self.session.encoding
|
pencoding = self.session.protocol_flags.get("ENCODING", None)
|
||||||
string = ""
|
string = ""
|
||||||
if pencoding:
|
if pencoding:
|
||||||
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
|
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
|
||||||
|
|
@ -480,15 +482,18 @@ class CmdUnconnectedEncoding(MuxCommand):
|
||||||
string = "No encodings found."
|
string = "No encodings found."
|
||||||
else:
|
else:
|
||||||
# change encoding
|
# change encoding
|
||||||
old_encoding = self.session.encoding
|
old_encoding = self.session.protocol_flags.get("ENCODING", None)
|
||||||
encoding = self.args
|
encoding = self.args
|
||||||
try:
|
try:
|
||||||
utils.to_str(utils.to_unicode("test-string"), encoding=encoding)
|
utils.to_str(utils.to_unicode("test-string"), encoding=encoding)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (encoding, old_encoding)
|
string = "|rThe encoding '|w%s|r' is invalid. Keeping the previous encoding '|w%s|r'.|n" % (encoding, old_encoding)
|
||||||
else:
|
else:
|
||||||
self.session.encoding = encoding
|
self.session.protocol_flags["ENCODING"] = encoding
|
||||||
string = "Your custom text encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, encoding)
|
string = "Your custom text encoding was changed from '|w%s|n' to '|w%s|n'." % (old_encoding, encoding)
|
||||||
|
sync = True
|
||||||
|
if sync:
|
||||||
|
self.session.sessionhandler.session_portal_sync(self.session)
|
||||||
self.caller.msg(string.strip())
|
self.caller.msg(string.strip())
|
||||||
|
|
||||||
class CmdUnconnectedScreenreader(MuxCommand):
|
class CmdUnconnectedScreenreader(MuxCommand):
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ def text(session, *args, **kwargs):
|
||||||
if text is None:
|
if text is None:
|
||||||
return
|
return
|
||||||
# this is treated as a command input
|
# this is treated as a command input
|
||||||
#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:
|
||||||
session.update_session_counters(idle=True)
|
session.update_session_counters(idle=True)
|
||||||
|
|
@ -122,7 +121,7 @@ def client_settings(session, *args, **kwargs):
|
||||||
elif key == "ansi":
|
elif key == "ansi":
|
||||||
flags["ANSI"] = bool(value)
|
flags["ANSI"] = bool(value)
|
||||||
elif key == "xterm256":
|
elif key == "xterm256":
|
||||||
flags["256 COLORS"] = bool(value)
|
flags["XTERM256"] = bool(value)
|
||||||
elif key == "mxp":
|
elif key == "mxp":
|
||||||
flags["MXP"] = bool(value)
|
flags["MXP"] = bool(value)
|
||||||
elif key == "utf-8":
|
elif key == "utf-8":
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,7 @@ class SshProtocol(Manhole, session.Session):
|
||||||
# handle arguments
|
# handle arguments
|
||||||
options = kwargs.get("options", {})
|
options = kwargs.get("options", {})
|
||||||
flags = self.protocol_flags
|
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)
|
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
|
||||||
raw = options.get("raw", False)
|
raw = options.get("raw", False)
|
||||||
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
||||||
# handle arguments
|
# handle arguments
|
||||||
options = kwargs.get("options", {})
|
options = kwargs.get("options", {})
|
||||||
flags = self.protocol_flags
|
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)
|
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
|
||||||
raw = options.get("raw", False)
|
raw = options.get("raw", False)
|
||||||
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ SEND = chr(1)
|
||||||
|
|
||||||
# terminal capabilities and their codes
|
# terminal capabilities and their codes
|
||||||
MTTS = [(128, 'PROXY'),
|
MTTS = [(128, 'PROXY'),
|
||||||
(64, 'SCREEN READER'),
|
(64, 'SCREENREADER'),
|
||||||
(32, 'OSC COLOR PALETTE'),
|
(32, 'OSC_COLOR_PALETTE'),
|
||||||
(16, 'MOUSE TRACKING'),
|
(16, 'MOUSE_TRACKING'),
|
||||||
(8, '256 COLORS'),
|
(8, 'XTERM256'),
|
||||||
(4, 'UTF-8'),
|
(4, 'UTF-8'),
|
||||||
(2, 'VT100'),
|
(2, 'VT100'),
|
||||||
(1, 'ANSI')]
|
(1, 'ANSI')]
|
||||||
|
|
@ -120,7 +120,7 @@ class Ttype(object):
|
||||||
|
|
||||||
# all clients supporting TTYPE at all seem to support ANSI
|
# all clients supporting TTYPE at all seem to support ANSI
|
||||||
self.protocol.protocol_flags['ANSI'] = True
|
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.protocol_flags['CLIENTNAME'] = clientname
|
||||||
self.protocol.requestNegotiation(TTYPE, SEND)
|
self.protocol.requestNegotiation(TTYPE, SEND)
|
||||||
|
|
||||||
|
|
@ -133,7 +133,7 @@ class Ttype(object):
|
||||||
not term.endswith("-color"))
|
not term.endswith("-color"))
|
||||||
if xterm256:
|
if xterm256:
|
||||||
self.protocol.protocol_flags['ANSI'] = True
|
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
|
self.protocol.protocol_flags['TERM'] = term
|
||||||
# request next information
|
# request next information
|
||||||
self.protocol.requestNegotiation(TTYPE, SEND)
|
self.protocol.requestNegotiation(TTYPE, SEND)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Session(object):
|
||||||
|
|
||||||
# names of attributes that should be affected by syncing.
|
# names of attributes that should be affected by syncing.
|
||||||
_attrs_to_sync = ('protocol_key', 'address', 'suid', 'sessid', 'uid',
|
_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',
|
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
|
||||||
'protocol_flags', 'server_data', "cmdset_storage_string")
|
'protocol_flags', 'server_data', "cmdset_storage_string")
|
||||||
|
|
||||||
|
|
@ -79,9 +79,8 @@ class Session(object):
|
||||||
self.cmd_last_visible = self.conn_time
|
self.cmd_last_visible = self.conn_time
|
||||||
self.cmd_last = self.conn_time
|
self.cmd_last = self.conn_time
|
||||||
self.cmd_total = 0
|
self.cmd_total = 0
|
||||||
self.encoding = "utf-8"
|
|
||||||
|
|
||||||
self.protocol_flags = {}
|
self.protocol_flags = {"ENCODING": "utf-8", "SCREENREADER":False}
|
||||||
self.server_data = {}
|
self.server_data = {}
|
||||||
|
|
||||||
# map of input data to session methods
|
# map of input data to session methods
|
||||||
|
|
|
||||||
|
|
@ -168,11 +168,11 @@ class SessionHandler(dict):
|
||||||
elif isinstance(data, basestring):
|
elif isinstance(data, basestring):
|
||||||
# make sure strings are in a valid encoding
|
# make sure strings are in a valid encoding
|
||||||
try:
|
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:
|
except LookupError:
|
||||||
# wrong encoding set on the session. Set it to a safe one
|
# wrong encoding set on the session. Set it to a safe one
|
||||||
session.encoding = "utf-8"
|
session.protocol_flags["ENCODING"] = "utf-8"
|
||||||
data = to_str(to_unicode(data), encoding=session.encoding)
|
data = to_str(to_unicode(data), encoding=session.protocol_flags["ENCODING"])
|
||||||
if _INLINEFUNC_ENABLED and not raw:
|
if _INLINEFUNC_ENABLED and not raw:
|
||||||
data = parse_inlinefunc(data, strip=strip_inlinefunc, session=session) # deprecated!
|
data = parse_inlinefunc(data, strip=strip_inlinefunc, session=session) # deprecated!
|
||||||
data = parse_nested_inlinefunc(data, strip=strip_inlinefunc, session=session)
|
data = parse_nested_inlinefunc(data, strip=strip_inlinefunc, session=session)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue