From: Armin Ronacher Date: Sun, 21 Oct 2007 19:37:54 +0000 (+0200) Subject: added pp support to jinja X-Git-Tag: 2.0rc1~256 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=20a9e9af348ea0d3030af4e406425daa2b158671;p=jinja2.git added pp support to jinja --HG-- branch : trunk --- 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):