From: Berker Peksag Date: Thu, 25 Jun 2015 19:24:03 +0000 (+0300) Subject: Change all unicode() calls with six.text_type(). X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=896d00fbf22f5701f811bb4cea28b01cbb618ee1;p=mediagoblin.git Change all unicode() calls with six.text_type(). Fixes #5329. --- diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 97e33e6a..8cee1cc0 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -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() diff --git a/mediagoblin/gmg_commands/batchaddmedia.py b/mediagoblin/gmg_commands/batchaddmedia.py index 4137b55c..5a47d698 100644 --- a/mediagoblin/gmg_commands/batchaddmedia.py +++ b/mediagoblin/gmg_commands/batchaddmedia.py @@ -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: diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 158a1a2d..ad22c169 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -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:") diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py index c1f6cb6b..427309de 100644 --- a/mediagoblin/media_types/audio/processing.py +++ b/mediagoblin/media_types/audio/processing.py @@ -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 diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index a85b232c..0cdfbdce 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -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) diff --git a/mediagoblin/plugins/archivalook/tools.py b/mediagoblin/plugins/archivalook/tools.py index 9c715c9b..b495624c 100644 --- a/mediagoblin/plugins/archivalook/tools.py +++ b/mediagoblin/plugins/archivalook/tools.py @@ -13,6 +13,9 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +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 = []