From dce76c3ee7153e8340cb3d64e8ee4df23a545bc4 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 3 Jun 2014 01:41:44 +0300 Subject: [PATCH] Sync py2_unicode decorator with Django. --- mediagoblin/_compat.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mediagoblin/_compat.py b/mediagoblin/_compat.py index c38e0727..ab5dbcf6 100644 --- a/mediagoblin/_compat.py +++ b/mediagoblin/_compat.py @@ -1,5 +1,3 @@ -import sys - from six import PY3, iteritems from mediagoblin import mg_globals @@ -17,8 +15,13 @@ else: ungettext = mg_globals.thread_scope.translations.ungettext +# taken from https://github.com/django/django/blob/master/django/utils/encoding.py def py2_unicode(klass): if not PY3: + if '__str__' not in klass.__dict__: + raise ValueError("@py2_unicode cannot be applied " + "to %s because it doesn't define __str__()." % + klass.__name__) klass.__unicode__ = klass.__str__ klass.__str__ = lambda self: self.__unicode__().encode('utf-8') return klass -- 2.25.1