7 from email
.mime
.text
import MIMEText
9 from email
.MIMEText
import MIMEText
12 def encode_to_utf8(method
):
14 if six
.PY2
and isinstance(method(self
), six
.text_type
):
15 return method(self
).encode('utf-8')
17 functools
.update_wrapper(wrapper
, method
, ['__name__', '__doc__'])
21 # based on django.utils.encoding.python_2_unicode_compatible
22 def py2_unicode(klass
):
24 if '__str__' not in klass
.__dict
__:
25 warnings
.warn("@py2_unicode cannot be applied "
26 "to %s because it doesn't define __str__()." %
28 klass
.__unicode
__ = klass
.__str
__
29 klass
.__str
__ = encode_to_utf8(klass
.__unicode
__)
30 if '__repr__' in klass
.__dict
__:
31 klass
.__repr
__ = encode_to_utf8(klass
.__repr
__)