On Thu, Jun 28, 2012 at 11:18 AM, Alex Ogier <alex.og...@gmail.com> wrote:
>
> Also, to be compatible with python 3 and more idiomatic python, I
> would implement the function as:
>
>    def html_mark_safe(format_string, *args):
>        return mark_safe(format_string.format(*map(conditional_escape, args)))
>

Actually, on second thought, this is even better:

    def html_mark_safe(format_string, *args, **kwargs):
        args_safe = map(conditional_escape, args)
        kwargs_safe = dict([(k, conditional_escape(v)) for (k, v) in
kwargs.iteritems()])
        return mark_safe(format_string.format(*args_safe, **kwargs_safe))

That's an HTML-safe replacement of the str.format() method, so far as
I can tell (except that all parameters must be [safe-]strings). That
allows more idiomatic python, and won't require awkward shims in
python 3, but it would mean that you can't directly translate %
interpolations. I think thats a good tradeoff.

Best,
Alex Ogier

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to