Change all unicode() calls with six.text_type().
authorBerker Peksag <berker.peksag@gmail.com>
Thu, 25 Jun 2015 19:24:03 +0000 (22:24 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Thu, 25 Jun 2015 19:24:50 +0000 (22:24 +0300)
Fixes #5329.

mediagoblin/edit/views.py
mediagoblin/gmg_commands/batchaddmedia.py
mediagoblin/gmg_commands/users.py
mediagoblin/media_types/audio/processing.py
mediagoblin/media_types/video/processing.py
mediagoblin/plugins/archivalook/tools.py

index 97e33e6a0215aba36b8176e424a915b89db7a543..8cee1cc035bc52397d9617e400e40781395d852d 100644 (file)
@@ -219,10 +219,10 @@ def edit_profile(request, url_user=None):
 
         # Save location
         if form.location.data and user.location is None:
-            user.get_location = Location(name=unicode(form.location.data))
+            user.get_location = Location(name=six.text_type(form.location.data))
         elif form.location.data:
             location = user.get_location
-            location.name = unicode(form.location.data)
+            location.name = six.text_type(form.location.data)
             location.save()
 
         user.save()
index 4137b55c0718805109dc02ee1db2e4cf7140734c..5a47d69848b998934d53c389bb28147b105eceda 100644 (file)
@@ -178,11 +178,12 @@ u"FAIL: This file is larger than the upload limits for this site."))
 
 def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
     # csv.py doesn't do Unicode; encode temporarily as UTF-8:
+    # TODO: this probably won't be necessary in Python 3
     csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                             dialect=dialect, **kwargs)
     for row in csv_reader:
         # decode UTF-8 back to Unicode, cell by cell:
-        yield [unicode(cell, 'utf-8') for cell in row]
+        yield [six.text_type(cell, 'utf-8') for cell in row]
 
 def utf_8_encoder(unicode_csv_data):
     for line in unicode_csv_data:
index 158a1a2d9d1522ae5693d27a2383035ccc96447b..ad22c169600667df608ea681794bdfa3e7b61165 100644 (file)
@@ -38,7 +38,7 @@ def adduser(args):
     #TODO: Lets trust admins this do not validate Emails :)
     commands_util.setup_app(args)
 
-    args.username = unicode(commands_util.prompt_if_not_set(args.username, "Username:"))
+    args.username = six.text_type(commands_util.prompt_if_not_set(args.username, "Username:"))
     args.password = commands_util.prompt_if_not_set(args.password, "Password:",True)
     args.email = commands_util.prompt_if_not_set(args.email, "Email:")
 
index c1f6cb6b53d140baead0586d9d366bd2df52a3a3..427309de5f212cdf9d34789c68b0ea6db4e01363 100644 (file)
@@ -18,6 +18,8 @@ import argparse
 import logging
 import os
 
+import six
+
 from mediagoblin import mg_globals as mgg
 from mediagoblin.processing import (
     BadMediaFail, FilenameBuilder,
@@ -39,7 +41,7 @@ def sniff_handler(media_file, filename):
     try:
         data = discover(media_file.name)
     except Exception as e:
-        _log.info(unicode(e))
+        _log.info(six.text_type(e))
         return None
     if data and data.get_audio_streams() and not data.get_video_streams():
         return MEDIA_TYPE
index a85b232cc4c07ef27988b84dac006e5c1351eb72..0cdfbdceeab1b00b7fccb8076625349032ff495c 100644 (file)
@@ -19,6 +19,8 @@ import os.path
 import logging
 import datetime
 
+import six
+
 from mediagoblin import mg_globals as mgg
 from mediagoblin.processing import (
     FilenameBuilder, BaseProcessingFail,
@@ -52,8 +54,8 @@ def sniffer(media_file):
         data = transcoders.discover(media_file.name)
     except Exception as e:
         # this is usually GLib.GError, but we don't really care which one
-        _log.warning(u'GStreamer: {0}'.format(unicode(e)))
-        raise MissingComponents(u'GStreamer: {0}'.format(unicode(e)))
+        _log.warning(u'GStreamer: {0}'.format(six.text_type(e)))
+        raise MissingComponents(u'GStreamer: {0}'.format(six.text_type(e)))
     _log.debug('Discovered: {0}'.format(data))
 
     if not data.get_video_streams():
@@ -110,7 +112,7 @@ def get_tags(stream_info):
             dt.get_microsecond()).isoformat()
     for k, v in tags.items():
         # types below are accepted by json; others must not present
-        if not isinstance(v, (dict, list, basestring, int, float, bool,
+        if not isinstance(v, (dict, list, six.string_types, int, float, bool,
                               type(None))):
             del tags[k]
     return dict(tags)
index 9c715c9b84e0cca2711082ca6c147cffd92472b3..b495624cac18a0f01626be2a311e5b3b167b0807 100644 (file)
@@ -13,6 +13,9 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import six
+
 from mediagoblin.db.models import MediaEntry, User
 from mediagoblin.plugins.archivalook.models import FeaturedMedia
 from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
@@ -53,7 +56,7 @@ def parse_url(url):
                                         who uploaded the piece of media, slug is
                                         the media entry's url slug.
     """
-    url = unicode(url)
+    url = six.text_type(url)
     u_end, m_start, m_end, end = (url.find('/u/') + 3,
                                   url.find('/m/'),
                                   url.find('/m/') + 3,
@@ -84,7 +87,7 @@ def split_featured_media_list(featured_media):
                                                 or tertiary)
     """
 
-    featured_media = unicode(featured_media)
+    featured_media = six.text_type(featured_media)
     featured_media_list = featured_media.split("\n")
     display_type = 0
     media_already_featured = []