summaryrefslogtreecommitdiff
path: root/django/newforms/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/newforms/util.py')
-rw-r--r--django/newforms/util.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/django/newforms/util.py b/django/newforms/util.py
index a78623a17b..891585cba2 100644
--- a/django/newforms/util.py
+++ b/django/newforms/util.py
@@ -1,21 +1,14 @@
-from django.conf import settings
+from django.utils.html import escape
+from django.utils.encoding import smart_unicode
-def smart_unicode(s):
- if not isinstance(s, basestring):
- s = unicode(str(s))
- elif not isinstance(s, unicode):
- s = unicode(s, settings.DEFAULT_CHARSET)
- return s
-
-class StrAndUnicode(object):
+def flatatt(attrs):
"""
- A class whose __str__ returns its __unicode__ as a bytestring
- according to settings.DEFAULT_CHARSET.
-
- Useful as a mix-in.
+ 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.
"""
- def __str__(self):
- return self.__unicode__().encode(settings.DEFAULT_CHARSET)
+ return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
class ErrorDict(dict):
"""