-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This shift brings us closer to a Python3-first code base.
- Loading branch information
Showing
2 changed files
with
25 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" Backports of code left behind by new versions of Django. """ | ||
|
||
import six | ||
|
||
# Django 1.7 removed StrAndUnicode, so it has been purged from this project as well. To bridge the | ||
# gap, we will rely on this utility directly, instead of trying to generate our own replacement | ||
# StrAndUnicode class. | ||
def python_2_unicode_compatible(klass): | ||
""" | ||
A decorator that defines __unicode__ and __str__ methods under Python 2. | ||
Under Python 3 it does nothing. | ||
To support Python 2 and 3 with a single code base, define a __str__ method | ||
returning text and apply this decorator to the class. | ||
""" | ||
if not six.PY3: | ||
klass.__unicode__ = klass.__str__ | ||
klass.__str__ = lambda self: self.__unicode__().encode('utf-8') | ||
return klass |
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