Tools (xonsh.tools)

Misc. xonsh tools.

The following implementations were forked from the IPython project:

Implementations:

  • decode()
  • encode()
  • cast_unicode()
  • safe_hasattr()
class xonsh.tools.redirect_stderr(new_target)[source]

Context manager for temporarily redirecting stderr to another file.

class xonsh.tools.redirect_stdout(new_target)[source]

Context manager for temporarily redirecting stdout to another file.

# How to send help() to stderr with redirect_stdout(sys.stderr):

help(dir)

# How to write help() to a file with open(‘help.txt’, ‘w’) as f:

with redirect_stdout(f):
help(pow)
xonsh.tools.cast_unicode(s, encoding=None)[source]
xonsh.tools.decode(s, encoding=None)[source]
xonsh.tools.encode(u, encoding=None)[source]
xonsh.tools.levenshtein(a, b, max_dist=inf)[source]

Calculates the Levenshtein distance between a and b.

xonsh.tools.safe_hasattr(obj, attr)[source]

In recent versions of Python, hasattr() only catches AttributeError. This catches all errors.

xonsh.tools.subproc_line(line)[source]

Excapsulates a source code line in a uncaptured subprocess $[].

xonsh.tools.subproc_toks(line, mincol=-1, maxcol=None, lexer=None, returnline=False)[source]

Excapsulates tokens in a source code line in a uncaptured subprocess $[] starting at a minimum column.

xonsh.tools.suggest_commands(cmd, env, aliases)[source]
xonsh.tools.suggestion_sort_helper(x, y)[source]

This Page