diff options
Diffstat (limited to 'django/newforms/util.py')
-rw-r--r-- | django/newforms/util.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/django/newforms/util.py b/django/newforms/util.py index cc17ff4f7f..891585cba2 100644 --- a/django/newforms/util.py +++ b/django/newforms/util.py @@ -1,9 +1,14 @@ from django.utils.html import escape from django.utils.encoding import smart_unicode -# Converts a dictionary to a single string with key="value", XML-style with -# a leading space. Assumes keys do not need to be XML-escaped. -flatatt = lambda attrs: u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) +def flatatt(attrs): + """ + Convert a dictionary of attributes to a single string. + The returned string will contain a leading space followed by key="value", + XML-style pairs. It is assumed that the keys do not need to be XML-escaped. + If the passed dictionary is empty, then return an empty string. + """ + return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) class ErrorDict(dict): """ |