Exemple #1
0
def show_(*args, **kwargs):
    """show_('x', 'y', z='z') # print names & values of arguments
    values of args and kwargs are expressions to be evaluated in context of the caller
    values of args become names to be displayed
    names of kwargs become names to be displayed
    """

    import miscutils.insp as insp
    from peepshow.core import show as core
    from peepshow.utils import python as utils

    env = utils.caller_gloloc()

    if args or kwargs:
        # show specified variables
        names = [*args] + [*kwargs.keys()]
        exprs = [*args] + [*kwargs.values()]

        for expr in exprs:
            if not isinstance(expr, str):
                raise TypeError("Each expression must be a string.")

        values = [eval(expr, env.glo, env.loc) for expr in exprs]
    else:
        # show all the user variables in scope of the caller
        is_user_var = lambda item: not insp.isaccess(item[0]).special
        user_vars = filter(is_user_var, env.initial.items())
        names, values = zip(*user_vars)

    core.show(names, values)
Exemple #2
0
def show(*args, **kwargs):
    """show(x, y, z=z) # print names & values of arguments
    names of args will be determined only if possible
    names of kwargs will be known as it is explicitely given
    """

    import miscutils.insp as insp
    from peepshow.core import show as core
    from peepshow.utils import python as utils

    if args or kwargs:
        # show specified variables
        if args:
            names = utils.arg_names()
        else:
            names = []
        names += [*kwargs.keys()]
        values = [*args] + [*kwargs.values()]
    else:
        # show all the user variables in scope of the caller
        env = utils.caller_gloloc()
        is_user_var = lambda item: not insp.isaccess(item[0]).special
        user_vars = filter(is_user_var, env.initial.items())
        names, values = zip(*user_vars)

    core.show(names, values)
Exemple #3
0
def peep_(*args):
    """Examine local data.
    peep_()     # examine all variables in the scope (locals cover globals)
    peep_('x')  # examine x (name will be known as it is explicitely given)
    """

    from peepshow.core import peep as core
    from peepshow.utils import python as utils
    from peepshow.core.trans import GloLoc, Given

    if len(args) > 1:
        raise TypeError("Too many arguments.")

    expr = args[0]
    env = utils.caller_gloloc()

    if args:
        if not isinstance(expr, str):
            raise TypeError("Expression must be a string or None.")

        try:
            target = eval(expr, {}, env.initial)
        except:
            raise SyntaxError('Invalid expression.')

        target = Given(target, expr)
    else:
        target = GloLoc(env.initial)

    last_target = core.peep(target, env)
Exemple #4
0
def peep(*args):
    """Examine local data.
    peep()   # examine all variables in the scope (locals cover globals)
    peep(x)  # examine x (name will be determined only if possible)
    """

    from peepshow.core import peep as core
    from peepshow.utils import python as utils
    from peepshow.core.trans import GloLoc, Given

    if len(args) > 1:
        raise TypeError("Too many arguments.")

    env = utils.caller_gloloc()

    if args:
        expr = utils.arg_names()[0]
        target = Given(args[0], expr)
    else:
        target = GloLoc(env.initial)

    last_target = core.peep(target, env)
Exemple #5
0
 def foo():
     gloloc = caller_gloloc()
     glo = gloloc.glo
     assert glo['caller_gloloc'] == caller_gloloc
     assert glo['TestCallerGloloc'] == TestCallerGloloc
Exemple #6
0
 def foo():
     gloloc = caller_gloloc()
     loc = gloloc.loc
     assert loc['x'] == 123
     assert loc['y'] == 234
     assert loc['foo'] == foo