From 0b2572b9a8f8d1e22e724283cd99152c767208e8 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 2 Jun 2014 21:01:48 +0300 Subject: [PATCH] Add py2_unicode helper to mediagoblin._compat. --- mediagoblin/_compat.py | 7 +++++++ mediagoblin/tools/workbench.py | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mediagoblin/_compat.py b/mediagoblin/_compat.py index a6b775fc..fd6172fd 100644 --- a/mediagoblin/_compat.py +++ b/mediagoblin/_compat.py @@ -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 diff --git a/mediagoblin/tools/workbench.py b/mediagoblin/tools/workbench.py index 0bd4096b..f1ad6414 100644 --- a/mediagoblin/tools/workbench.py +++ b/mediagoblin/tools/workbench.py @@ -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: -- 2.25.1