Skip to content

Commit

Permalink
bugfix traceback exception line
Browse files Browse the repository at this point in the history
  • Loading branch information
jquast committed Oct 19, 2015
1 parent 4fece35 commit 17f9f15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* bugfix: linemode MODE is now acknowledged.
* bugfix: default stream handler sends 80 x 24 in cols x rows, not 24 x 80.
* bugfix: waiter_closed future on client defaulted to wrong type.
* bugfix: telnet shell (TelSh) no longer paints over final exception line.

0.4.0
* bugfix: cannot connect to IPv6 address as client.
Expand Down
28 changes: 20 additions & 8 deletions telnetlib3/telsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,11 @@ def autocomplete(self, input, table=None):
or @property ``autocomplete_cmdset`` is used.
"""
self.log.debug('tab_received: {!r}'.format(input))

# dynamic injection of variables for set command,
cmd, args = input.rstrip(), []
table = self.autocomplete_cmdset if table is None else table

# inject session variables for set command,
if 'set' in table:
table['set'] = collections.OrderedDict([
Expand Down Expand Up @@ -753,19 +755,25 @@ def prompt(self):
return ('{}'.format(prompt_eval(self, ps)))

def display_exception(self, *exc_info):
""" Dispaly exception to client when ``show_traceback`` is True,
forward copy server log at debug and info levels.
"""
Display exception to client when ``show_traceback`` is True.
Forward-copy to server log at DEBUG and INFO levels.
"""
tbl_exception = (
traceback.format_tb(exc_info[2]) +
traceback.format_exception_only(exc_info[0], exc_info[1]))
for num, tb in enumerate(tbl_exception):
tb_msg = tb.splitlines()
if self.show_traceback:
self.stream.write('\r\n' + '\r\n'.join(
self.standout(row.rstrip())
if num == len(tbl_exception) - 1
else row.rstrip() for row in tb_msg))
self.stream.write(u'\r\n'.join(
(u'',
'\r\n'.join(
self.standout(row.rstrip())
if num == len(tbl_exception) - 1
else row.rstrip()
for row in tb_msg),
u'\r\n')))
tbl_srv = [row.rstrip() for row in tb_msg]
for line in tbl_srv:
self.log.log(logging.ERROR, line)
Expand Down Expand Up @@ -1125,7 +1133,7 @@ def autocomplete(table, cycle, buf, cmd, *args):
table : collections.OrderedDict, cycle : bool,
buf : string, cmd : string, *args) -> (buf, bool)
Recursive autocompete function. This provides no "found last match"
Recursive auto-complete function. This provides no "found last match"
state tracking, but rather simply cycles 'next match' when cycle
is True, meaning 's'<tab> -> 'set', then, subsequent <tab> -> 'status'.
"""
Expand Down Expand Up @@ -1154,26 +1162,30 @@ def postfix(buf, using=' '):
postfix(auto_cmd),
escape_quote(args))
return (buf, False)

# first-time exact match,
if not cycle:
return (buf, True)

# cycle next match
ptr = 0 if ptr + 1 == len(auto_cmds) - 1 else ptr + 1
buf = ''.join((postfix(buf), auto_cmds[ptr]))
return (buf, True)
else:
# match at this step, have/will args, recruse;
# match at this step, have/will args, recurse;
buf = ''.join((postfix(buf), auto_cmd,))
_cmd = args[0] if args else ''
return autocomplete(
table[auto_cmd], cycle, buf, _cmd, *args[1:])

elif auto_cmd.lower().startswith(cmd.lower()):
# partial match, error if arguments not valid,
args_ok = bool(not args or args and has_args)
buf = ''.join((postfix(buf), auto_cmd))
if args or has_args:
buf = ''.join((postfix(buf), escape_quote(args)))
return (buf, args_ok)

# no matches
buf = '{}{}{}'.format(
postfix(buf), cmd, escape_quote(args))
Expand Down

0 comments on commit 17f9f15

Please sign in to comment.