Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved smart_unicode and StrAndUnicode to django.utils.encoding. They …
…are useful outside of newforms. This is backwards compatible as far as smart_unicode goes (since newforms.util still imports it). All imports of smart_unicode and StrAndUnicode have also been updated. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
10 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.conf import settings | ||
from django.utils.functional import Promise | ||
|
||
def smart_unicode(s): | ||
if isinstance(s, Promise): | ||
# The input is the result of a gettext_lazy() call, or similar. It will | ||
# already be encoded in DEFAULT_CHARSET on evaluation and we don't want | ||
# to evaluate it until render time. | ||
return s | ||
if not isinstance(s, basestring,): | ||
if hasattr(s, '__unicode__'): | ||
s = unicode(s) | ||
else: | ||
s = unicode(str(s), settings.DEFAULT_CHARSET) | ||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters