Add py2_unicode helper to mediagoblin._compat.
authorBerker Peksag <berker.peksag@gmail.com>
Mon, 2 Jun 2014 18:01:48 +0000 (21:01 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Mon, 2 Jun 2014 18:01:48 +0000 (21:01 +0300)
mediagoblin/_compat.py
mediagoblin/tools/workbench.py

index a6b775fc4e4f2eeae930de0b6009780a2d15bc40..fd6172fdd78cf9473bcc4a6744cdc3a7207eb5ae 100644 (file)
@@ -14,3 +14,10 @@ else:
     import urlparse
     ugettext = mg_globals.thread_scope.translations.ugettext
     ungettext = mg_globals.thread_scope.translations.ungettext
+
+
+def py2_unicode(klass):
+    if not PY3:
+        klass.__unicode__ = klass.__str__
+        klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
+    return klass
index 0bd4096b47ab47e4fa7340934e8a93c2be358a3b..f1ad6414511a20eabf416958c97149d3293fca00 100644 (file)
@@ -18,10 +18,15 @@ import os
 import shutil
 import tempfile
 
+import six
+
+from mediagoblin._compat import py2_unicode
 
 # Actual workbench stuff
 # ----------------------
 
+
+@py2_unicode
 class Workbench(object):
     """
     Represent the directory for the workbench
@@ -36,11 +41,8 @@ class Workbench(object):
         """
         self.dir = dir
 
-    def __unicode__(self):
-        return unicode(self.dir)
-
     def __str__(self):
-        return str(self.dir)
+        return six.text_type(self.dir)
 
     def __repr__(self):
         try: