Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Python 2/3 Compatibility Helper 

2 

3Inspired by: 

4 

5* https://docs.djangoproject.com/en/dev/topics/python3/ 

6* http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/ 

7* http://python-future.org/index.html 

8* http://docs.python.org/3.3/howto/pyporting.html 

9 

10""" 

11import six 

12 

13 

14def python_2_unicode_compatible(cls): 

15 """ 

16 Class decorator that provides appropriate Python 2 __unicode__ and __str__ 

17 based upon Python 3' __str__. 

18 """ 

19 if six.PY2: 

20 cls.__unicode__ = cls.__str__ 

21 cls.__str__ = lambda self: self.__unicode__().encode('utf-8') 

22 return cls