Skip to content
Back to top
View this page
Edit this page

# xonsh.contexts

Context management tools for xonsh.

class xonsh.contexts.Block

  This is a context manager for obtaining a block of lines without actually executing the block. The lines are accessible as the ‘lines’ attribute. This must be used as a macro.

  Attributes:
    lines list of str or None

      Block lines as if split by str.splitlines(), if available.

    glbs Mapping or None

      Global execution context, ie globals().

    locs Mapping or None

      Local execution context, ie locals().

class xonsh.contexts.Functor(args=(), kwargs=None, rtn='')

  This is a context manager that turns the block into a callable object, bound to the execution context it was created in.

  Parameters:
    args Sequence of str, optional

      A tuple of argument names for the functor.

    kwargs Mapping of str to values or list of item tuples, optional

      Keyword argument names and values, if available.

    rtn str, optional

      Name of object to return, if available.

  Attributes:
    func function

      The underlying function object. This defaults to none and is set after the the block is exited.