From: Armin Ronacher Date: Sun, 21 Oct 2007 19:51:51 +0000 (+0200) Subject: improved pprint X-Git-Tag: 2.0rc1~254 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f2ce126df7e3a3675d36ae6a68b819cf61d9a16c;p=jinja2.git improved pprint --HG-- branch : trunk --- diff --git a/jinja/filters.py b/jinja/filters.py index 9540f6d..a431e3d 100644 --- a/jinja/filters.py +++ b/jinja/filters.py @@ -423,12 +423,15 @@ def do_filesizeformat(): return wrapped -def do_pprint(): +def do_pprint(verbose=False): """ Pretty print a variable. Useful for debugging. + + With Jinja 1.2 onwards you can pass it a parameter. If this parameter + is truthy the output will be more verbose (this requires `pp`) """ def wrapped(env, context, value): - return pformat(value) + return pformat(value, verbose=verbose) return wrapped diff --git a/jinja/utils.py b/jinja/utils.py index fe8c0ba..096afbc 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -350,16 +350,17 @@ except TypeError, e: del _test_singleton, _test_gen_bug -def pformat(obj): +def pformat(obj, verbose=False): """ Prettyprint an object. Either use the `pp` library or the builtin `pprint`. """ try: - from pp import pp as format + from pp import pp + return pp(obj, verbose=verbose) except ImportError: - from pprint import pformat as format - return format(obj) + from pprint import pformat + return pformat(obj) def buffereater(f): @@ -419,7 +420,7 @@ class DebugHelper(object): def __call__(self, env, context): """Print a nice representation of the context.""" - return pformat(context.to_dict()) + return pformat(context.to_dict(), verbose=True) def filters(self, env, context, builtins=True): """List the filters."""