From f2ce126df7e3a3675d36ae6a68b819cf61d9a16c Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 21 Oct 2007 21:51:51 +0200 Subject: [PATCH] improved pprint --HG-- branch : trunk --- jinja/filters.py | 7 +++++-- jinja/utils.py | 11 ++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) 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.""" -- 2.26.2