summaryrefslogtreecommitdiff
path: root/django/newforms/util.py
diff options
context:
space:
mode:
authorRobin Munn <robin.munn@gmail.com>2006-12-08 15:10:09 +0000
committerRobin Munn <robin.munn@gmail.com>2006-12-08 15:10:09 +0000
commit122426e7453ed638a0c5be7e8b925adcddea3889 (patch)
treea095a661aca53e0ceee021d93a2a503783b71c14 /django/newforms/util.py
parentdadfca08c0db567ce33284aaa8eb388cf667a836 (diff)
sqlalchemy: Merged revisions 4054 to 4185 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/sqlalchemy@4186 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/util.py')
-rw-r--r--django/newforms/util.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/django/newforms/util.py b/django/newforms/util.py
index 3887010c85..a78623a17b 100644
--- a/django/newforms/util.py
+++ b/django/newforms/util.py
@@ -1,11 +1,22 @@
-# Default encoding for input byte strings.
-DEFAULT_ENCODING = 'utf-8' # TODO: First look at django.conf.settings, then fall back to this.
+from django.conf import settings
def smart_unicode(s):
- if not isinstance(s, unicode):
- s = unicode(s, DEFAULT_ENCODING)
+ 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):
+ """
+ A class whose __str__ returns its __unicode__ as a bytestring
+ according to settings.DEFAULT_CHARSET.
+
+ Useful as a mix-in.
+ """
+ def __str__(self):
+ return self.__unicode__().encode(settings.DEFAULT_CHARSET)
+
class ErrorDict(dict):
"""
A collection of errors that knows how to display itself in various formats.