From 20a9e9af348ea0d3030af4e406425daa2b158671 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 21 Oct 2007 21:37:54 +0200 Subject: [PATCH] added pp support to jinja --HG-- branch : trunk --- jinja/filters.py | 3 +-- jinja/utils.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jinja/filters.py b/jinja/filters.py index 675f310..9540f6d 100644 --- a/jinja/filters.py +++ b/jinja/filters.py @@ -13,7 +13,7 @@ from random import choice from operator import itemgetter from urllib import urlencode, quote from jinja.utils import urlize, escape, reversed, sorted, groupby, \ - get_attribute + get_attribute, pformat from jinja.datastructure import TemplateData from jinja.exceptions import FilterArgumentError, SecurityException @@ -428,7 +428,6 @@ def do_pprint(): Pretty print a variable. Useful for debugging. """ def wrapped(env, context, value): - from pprint import pformat return pformat(value) return wrapped diff --git a/jinja/utils.py b/jinja/utils.py index 9e8190c..fe8c0ba 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -350,6 +350,18 @@ except TypeError, e: del _test_singleton, _test_gen_bug +def pformat(obj): + """ + Prettyprint an object. Either use the `pp` library or the + builtin `pprint`. + """ + try: + from pp import pp as format + except ImportError: + from pprint import pformat as format + return format(obj) + + def buffereater(f): """ Used by the python translator to capture output of substreams. @@ -407,7 +419,6 @@ class DebugHelper(object): def __call__(self, env, context): """Print a nice representation of the context.""" - from pprint import pformat return pformat(context.to_dict()) def filters(self, env, context, builtins=True): -- 2.26.2