Use six.text_type instead of unicode().
authorBerker Peksag <berker.peksag@gmail.com>
Mon, 2 Jun 2014 17:59:28 +0000 (20:59 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Mon, 2 Jun 2014 17:59:28 +0000 (20:59 +0300)
I will be switch to use ``from __future__ import unicode_literals`` later.

36 files changed:
mediagoblin/auth/tools.py
mediagoblin/auth/views.py
mediagoblin/db/migrations.py
mediagoblin/db/models.py
mediagoblin/edit/views.py
mediagoblin/gmg_commands/addmedia.py
mediagoblin/gmg_commands/users.py
mediagoblin/media_types/ascii/processing.py
mediagoblin/media_types/blog/views.py
mediagoblin/media_types/image/processing.py
mediagoblin/plugins/api/views.py
mediagoblin/plugins/basic_auth/tools.py
mediagoblin/plugins/httpapiauth/__init__.py
mediagoblin/plugins/ldap/views.py
mediagoblin/plugins/oauth/tools.py
mediagoblin/plugins/oauth/views.py
mediagoblin/plugins/openid/store.py
mediagoblin/plugins/openid/views.py
mediagoblin/plugins/persona/views.py
mediagoblin/plugins/piwigo/views.py
mediagoblin/processing/__init__.py
mediagoblin/storage/__init__.py
mediagoblin/submit/lib.py
mediagoblin/submit/views.py
mediagoblin/tests/test_auth.py
mediagoblin/tests/test_http_callback.py
mediagoblin/tests/test_ldap.py
mediagoblin/tests/test_oauth2.py
mediagoblin/tests/test_openid.py
mediagoblin/tests/test_persona.py
mediagoblin/tests/test_reporting.py
mediagoblin/tests/test_storage.py
mediagoblin/tests/test_submission.py
mediagoblin/tests/test_util.py
mediagoblin/tools/url.py
mediagoblin/user_pages/views.py

index 88716e1c0fc0a6e5333e681104805172b41efefc..8c919498a06ee9a7b879f22c096b9a2c77cdad85 100644 (file)
@@ -16,6 +16,8 @@
 
 
 import logging
+
+import six
 import wtforms
 from sqlalchemy import or_
 
@@ -140,7 +142,7 @@ def register_user(request, register_form):
         user.save()
 
         # log the user in
-        request.session['user_id'] = unicode(user.id)
+        request.session['user_id'] = six.text_type(user.id)
         request.session.save()
 
         # send verification email
index 3d132f84e33ce898133e0d652de039f95a7c14d9..a90db0eae9645c65688fe450b9edd53dfea4bce4 100644 (file)
@@ -14,6 +14,8 @@
 # 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 itsdangerous import BadSignature
 
 from mediagoblin import messages, mg_globals
@@ -93,7 +95,7 @@ def login(request):
                 # set up login in session
                 if login_form.stay_logged_in.data:
                     request.session['stay_logged_in'] = True
-                request.session['user_id'] = unicode(user.id)
+                request.session['user_id'] = six.text_type(user.id)
                 request.session.save()
 
                 if request.form.get('next'):
index 426080a2def9b0b573ef182e01336fa0e8489efd..dd96c3f32671098a4d8ebbde0b8286e40ecd5416 100644 (file)
@@ -17,6 +17,8 @@
 import datetime
 import uuid
 
+import six
+
 from sqlalchemy import (MetaData, Table, Column, Boolean, SmallInteger,
                         Integer, Unicode, UnicodeText, DateTime,
                         ForeignKey, Date)
@@ -248,7 +250,7 @@ def mediaentry_new_slug_era(db):
     for row in db.execute(media_table.select()):
         # no slug, try setting to an id
         if not row.slug:
-            append_garbage_till_unique(row, unicode(row.id))
+            append_garbage_till_unique(row, six.text_type(row.id))
         # has "=" or ":" in it... we're getting rid of those
         elif u"=" in row.slug or u":" in row.slug:
             append_garbage_till_unique(
@@ -277,7 +279,7 @@ def unique_collections_slug(db):
                 existing_slugs[row.creator].append(row.slug)
 
     for row_id in slugs_to_change:
-        new_slug = unicode(uuid.uuid4())
+        new_slug = six.text_type(uuid.uuid4())
         db.execute(collection_table.update().
                    where(collection_table.c.id == row_id).
                    values(slug=new_slug))
index 1fecbaaa2a6732cf68e4885f41019de0281069a1..4b2fb632be93386b39b9176fe0864c96a0300257 100644 (file)
@@ -304,7 +304,7 @@ class MediaEntry(Base, MediaEntryMixin):
         return the value of the key.
         """
         media_file = MediaFile.query.filter_by(media_entry=self.id,
-                                               name=unicode(file_key)).first()
+                                               name=six.text_type(file_key)).first()
 
         if media_file:
             if metadata_key:
@@ -317,7 +317,7 @@ class MediaEntry(Base, MediaEntryMixin):
         Update the file_metadata of a MediaFile.
         """
         media_file = MediaFile.query.filter_by(media_entry=self.id,
-                                               name=unicode(file_key)).first()
+                                               name=six.text_type(file_key)).first()
 
         file_metadata = media_file.file_metadata or {}
 
index 80590875680379d29baea9a67d579d9fa4f99df9..52f808b66e7b9684babc209930ae681b8f0bc020 100644 (file)
@@ -14,6 +14,8 @@
 # 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 datetime import datetime
 
 from itsdangerous import BadSignature
@@ -77,7 +79,7 @@ def edit_media(request, media):
             media.tags = convert_to_tag_list_of_dicts(
                                    form.tags.data)
 
-            media.license = unicode(form.license.data) or None
+            media.license = six.text_type(form.license.data) or None
             media.slug = slug
             media.save()
 
@@ -135,7 +137,7 @@ def edit_attachments(request, media):
 
             attachment_public_filepath \
                 = mg_globals.public_store.get_unique_filepath(
-                ['media_entries', unicode(media.id), 'attachment',
+                ['media_entries', six.text_type(media.id), 'attachment',
                  public_filename])
 
             attachment_public_file = mg_globals.public_store.get_file(
@@ -200,8 +202,8 @@ def edit_profile(request, url_user=None):
         bio=user.bio)
 
     if request.method == 'POST' and form.validate():
-        user.url = unicode(form.url.data)
-        user.bio = unicode(form.bio.data)
+        user.url = six.text_type(form.url.data)
+        user.bio = six.text_type(form.bio.data)
 
         user.save()
 
@@ -316,9 +318,9 @@ def edit_collection(request, collection):
             form.slug.errors.append(
                 _(u'A collection with that slug already exists for this user.'))
         else:
-            collection.title = unicode(form.title.data)
-            collection.description = unicode(form.description.data)
-            collection.slug = unicode(form.slug.data)
+            collection.title = six.text_type(form.title.data)
+            collection.description = six.text_type(form.description.data)
+            collection.slug = six.text_type(form.slug.data)
 
             collection.save()
 
index c33a8c56f80738056abe3223a3fc7feb244e3fdc..34add88b158247c6caced1240e336ce84ab1704d 100644 (file)
 # 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/>.
 
+from __future__ import print_function
+
 import os
 
+import six
+
 from mediagoblin.gmg_commands import util as commands_util
 from mediagoblin.submit.lib import (
     submit_media, get_upload_file_limits,
@@ -68,14 +72,14 @@ def addmedia(args):
     # get the user
     user = app.db.User.query.filter_by(username=args.username.lower()).first()
     if user is None:
-        print "Sorry, no user by username '%s'" % args.username
+        print("Sorry, no user by username '%s'" % args.username)
         return
     
     # check for the file, if it exists...
     filename = os.path.split(args.filename)[-1]
     abs_filename = os.path.abspath(args.filename)
     if not os.path.exists(abs_filename):
-        print "Can't find a file with filename '%s'" % args.filename
+        print("Can't find a file with filename '%s'" % args.filename)
         return
 
     upload_limit, max_file_size = get_upload_file_limits(user)
@@ -85,7 +89,7 @@ def addmedia(args):
         if some_string is None:
             return None
         else:
-            return unicode(some_string)
+            return six.text_type(some_string)
 
     try:
         submit_media(
@@ -98,8 +102,8 @@ def addmedia(args):
             tags_string=maybe_unicodeify(args.tags) or u"",
             upload_limit=upload_limit, max_file_size=max_file_size)
     except FileUploadLimit:
-        print "This file is larger than the upload limits for this site."
+        print("This file is larger than the upload limits for this site.")
     except UserUploadLimit:
-        print "This file will put this user past their upload limits."
+        print("This file will put this user past their upload limits.")
     except UserPastUploadLimit:
-        print "This user is already past their upload limits."
+        print("This user is already past their upload limits.")
index 4a730d9e866756afb0d4ef25274439d6b9a80261..9014da8784080f958886bd53b1452d3b6a794569 100644 (file)
@@ -14,6 +14,8 @@
 # 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.gmg_commands import util as commands_util
 from mediagoblin import auth
 from mediagoblin import mg_globals
@@ -50,8 +52,8 @@ def adduser(args):
     else:
         # Create the user
         entry = db.User()
-        entry.username = unicode(args.username.lower())
-        entry.email = unicode(args.email)
+        entry.username = six.text_type(args.username.lower())
+        entry.email = six.text_type(args.email)
         entry.pw_hash = auth.gen_password_hash(args.password)
         default_privileges = [
             db.Privilege.query.filter(
@@ -81,7 +83,7 @@ def makeadmin(args):
     db = mg_globals.database
 
     user = db.User.query.filter_by(
-        username=unicode(args.username.lower())).one()
+        username=six.text_type(args.username.lower())).one()
     if user:
         user.all_privileges.append(
             db.Privilege.query.filter(
@@ -108,7 +110,7 @@ def changepw(args):
     db = mg_globals.database
 
     user = db.User.query.filter_by(
-        username=unicode(args.username.lower())).one()
+        username=six.text_type(args.username.lower())).one()
     if user:
         user.pw_hash = auth.gen_password_hash(args.password)
         user.save()
index 84030362fda9e786244098e356440c3d0009256f..6f388573d525c8c1b91d1cfbda3a5d2a23c538c5 100644 (file)
@@ -22,6 +22,8 @@ except ImportError:
     import Image
 import logging
 
+import six
+
 from mediagoblin import mg_globals as mgg
 from mediagoblin.processing import (
     create_pub_filepath, FilenameBuilder,
@@ -104,7 +106,7 @@ class CommonAsciiProcessor(MediaProcessor):
                 # Encode the unicode instance to ASCII and replace any
                 # non-ASCII with an HTML entity (&#
                 unicode_file.write(
-                    unicode(orig_file.read().decode(
+                    six.text_type(orig_file.read().decode(
                             self.charset)).encode(
                                 'ascii',
                                 'xmlcharrefreplace'))
index a367bef857550228438d3daff42ebcb5e83028b5..3a4dfe6a364e0821cebd3f6e10504f2c4f387402 100644 (file)
@@ -19,6 +19,8 @@ _log = logging.getLogger(__name__)
 
 from datetime import datetime
 
+import six
+
 from werkzeug.exceptions import Forbidden
 from mediagoblin.tools import pluginapi
 
@@ -75,8 +77,8 @@ def blog_edit(request):
             if request.method=='POST' and form.validate():
                 _log.info("Here")
                 blog = request.db.Blog()
-                blog.title = unicode(form.title.data)
-                blog.description = unicode(cleaned_markdown_conversion((form.description.data)))
+                blog.title = six.text_type(form.title.data)
+                blog.description = six.text_type(cleaned_markdown_conversion((form.description.data)))
                 blog.author = request.user.id
                 blog.generate_slug()
 
@@ -112,8 +114,8 @@ def blog_edit(request):
                      'app_config': mg_globals.app_config})
         else:
             if request.method == 'POST' and form.validate():
-                blog.title = unicode(form.title.data)
-                blog.description = unicode(cleaned_markdown_conversion((form.description.data)))
+                blog.title = six.text_type(form.title.data)
+                blog.description = six.text_type(cleaned_markdown_conversion((form.description.data)))
                 blog.author = request.user.id
                 blog.generate_slug()
 
@@ -137,10 +139,10 @@ def blogpost_create(request):
 
         blogpost = request.db.MediaEntry()
         blogpost.media_type = 'mediagoblin.media_types.blogpost'
-        blogpost.title = unicode(form.title.data)
-        blogpost.description = unicode(cleaned_markdown_conversion((form.description.data)))
+        blogpost.title = six.text_type(form.title.data)
+        blogpost.description = six.text_type(cleaned_markdown_conversion((form.description.data)))
         blogpost.tags =  convert_to_tag_list_of_dicts(form.tags.data)
-        blogpost.license = unicode(form.license.data) or None
+        blogpost.license = six.text_type(form.license.data) or None
         blogpost.uploader = request.user.id
         blogpost.generate_slug()
 
@@ -187,10 +189,10 @@ def blogpost_edit(request):
 
     form = blog_forms.BlogPostEditForm(request.form, **defaults)
     if request.method == 'POST' and form.validate():
-        blogpost.title = unicode(form.title.data)
-        blogpost.description = unicode(cleaned_markdown_conversion((form.description.data)))
+        blogpost.title = six.text_type(form.title.data)
+        blogpost.description = six.text_type(cleaned_markdown_conversion((form.description.data)))
         blogpost.tags =  convert_to_tag_list_of_dicts(form.tags.data)
-        blogpost.license = unicode(form.license.data)
+        blogpost.license = six.text_type(form.license.data)
         set_blogpost_state(request, blogpost)
         blogpost.generate_slug()
         blogpost.save()
index a9b966ffb3851f828575e8ef4f6c203816cefacb..ae9ece2465e5e050cc219f713decfa53c4e2a380 100644 (file)
@@ -24,6 +24,8 @@ import os
 import logging
 import argparse
 
+import six
+
 from mediagoblin import mg_globals as mgg
 from mediagoblin.processing import (
     BadMediaFail, FilenameBuilder,
@@ -67,7 +69,7 @@ def resize_image(entry, resized, keyname, target_name, new_size,
         resize_filter = PIL_FILTERS[filter.upper()]
     except KeyError:
         raise Exception('Filter "{0}" not found, choose one of {1}'.format(
-            unicode(filter),
+            six.text_type(filter),
             u', '.join(PIL_FILTERS.keys())))
 
     resized.thumbnail(new_size, resize_filter)
@@ -116,7 +118,7 @@ def resize_tool(entry,
         or im.size[1] > new_size[1]\
         or exif_image_needs_rotation(exif_tags):
         resize_image(
-            entry, im, unicode(keyname), target_name,
+            entry, im, six.text_type(keyname), target_name,
             tuple(new_size),
             exif_tags, conversions_subdir,
             quality, filter)
index 69fae7bbbb8288e285657e774db1b6898fe784af..a9aaacee5325683b19e72d920ba36f5f69f88dd5 100644 (file)
@@ -17,6 +17,8 @@
 import json
 import logging
 
+import six
+
 from werkzeug.exceptions import BadRequest
 from werkzeug.wrappers import Response
 
@@ -55,15 +57,15 @@ def post_entry(request):
 
     callback_url = request.form.get('callback_url')
     if callback_url:
-        callback_url = unicode(callback_url)
+        callback_url = six.text_type(callback_url)
     try:
         entry = submit_media(
             mg_app=request.app, user=request.user,
             submitted_file=request.files['file'],
             filename=request.files['file'].filename,
-            title=unicode(request.form.get('title')),
-            description=unicode(request.form.get('description')),
-            license=unicode(request.form.get('license', '')),
+            title=six.text_type(request.form.get('title')),
+            description=six.text_type(request.form.get('description')),
+            license=six.text_type(request.form.get('license', '')),
             upload_limit=upload_limit, max_file_size=max_file_size,
             callback_url=callback_url)
 
@@ -88,7 +90,7 @@ def post_entry(request):
         '''
         if isinstance(e, InvalidFileType) or \
                 isinstance(e, FileTypeNotSupported):
-            raise BadRequest(unicode(e))
+            raise BadRequest(six.text_type(e))
         else:
             raise
 
index f943bf396a5778f99ed698df2dfca923457c51cb..13f240b25d81847a9226d9f13c5ffcdb93458038 100644 (file)
@@ -16,6 +16,8 @@
 import bcrypt
 import random
 
+import six
+
 from mediagoblin import mg_globals
 from mediagoblin.tools.crypto import get_timed_signer_url
 from mediagoblin.tools.mail import send_email
@@ -66,7 +68,7 @@ def bcrypt_gen_password_hash(raw_pass, extra_salt=None):
     if extra_salt:
         raw_pass = u"%s:%s" % (extra_salt, raw_pass)
 
-    return unicode(
+    return six.text_type(
         bcrypt.hashpw(raw_pass.encode('utf-8'), bcrypt.gensalt()))
 
 
index 2b2d593c9503b281686030d1e5e9f11985a118fe..d7180463d1a1570add22982c4d10f6f90923f5d0 100644 (file)
@@ -16,6 +16,8 @@
 
 import logging
 
+import six
+
 from werkzeug.exceptions import Unauthorized
 
 from mediagoblin.auth.tools import check_login_simple
@@ -40,7 +42,7 @@ class HTTPAuth(Auth):
         if not request.authorization:
             return False
 
-        user = check_login_simple(unicode(request.authorization['username']),
+        user = check_login_simple(six.text_type(request.authorization['username']),
                                   request.authorization['password'])
 
         if user:
index aef1bf56fff630036897e2f7fc0fccfc010205ad..be434daf2afd8cdd880431d8328a83bfece15804 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 import mg_globals, messages
 from mediagoblin.auth.tools import register_user
 from mediagoblin.db.models import User
@@ -40,7 +43,7 @@ def login(request):
 
             if user:
                 # set up login in session
-                request.session['user_id'] = unicode(user.id)
+                request.session['user_id'] = six.text_type(user.id)
                 request.session.save()
 
                 if request.form.get('next'):
index af0a3305acf53cdc1a3b9fda718bb5cfb5a0a14f..2053d5d4be25bbfcb0b8bc2a3f13b6b566f5a2a7 100644 (file)
@@ -23,6 +23,8 @@ from datetime import datetime
 
 from functools import wraps
 
+import six
+
 from mediagoblin.tools.response import json_response
 
 
@@ -86,7 +88,7 @@ def create_token(client, user):
 
 def generate_identifier():
     ''' Generates a ``uuid.uuid4()`` '''
-    return unicode(uuid.uuid4())
+    return six.text_type(uuid.uuid4())
 
 
 def generate_token():
@@ -110,5 +112,5 @@ def generate_secret():
     '''
     # XXX: We might not want it to use bcrypt, since bcrypt takes its time to
     # generate the result.
-    return unicode(getrandbits(192))
+    return six.text_type(getrandbits(192))
 
index de637d6b5027676251c9653ca92775fe7975278b..9e3b87c9d56abeb8a121ce4bef2cd64be83f3491 100644 (file)
@@ -19,6 +19,8 @@ import logging
 
 from urllib import urlencode
 
+import six
+
 from werkzeug.exceptions import BadRequest
 
 from mediagoblin.tools.response import render_to_response, redirect, json_response
@@ -44,11 +46,11 @@ def register_client(request):
 
     if request.method == 'POST' and form.validate():
         client = OAuthClient()
-        client.name = unicode(form.name.data)
-        client.description = unicode(form.description.data)
-        client.type = unicode(form.type.data)
+        client.name = six.text_type(form.name.data)
+        client.description = six.text_type(form.description.data)
+        client.type = six.text_type(form.type.data)
         client.owner_id = request.user.id
-        client.redirect_uri = unicode(form.redirect_uri.data)
+        client.redirect_uri = six.text_type(form.redirect_uri.data)
 
         client.save()
 
index 8f9a7012d7542558ae08ae4f59205c689f9d85c3..24726814ef06956c8adb5339854628f1c5787975 100644 (file)
@@ -16,6 +16,8 @@
 import base64
 import time
 
+import six
+
 from openid.association import Association as OIDAssociation
 from openid.store.interface import OpenIDStore
 from openid.store import nonce
@@ -34,12 +36,12 @@ class SQLAlchemyOpenIDStore(OpenIDStore):
 
         if not assoc:
             assoc = Association()
-            assoc.server_url = unicode(server_url)
+            assoc.server_url = six.text_type(server_url)
             assoc.handle = association.handle
 
         # django uses base64 encoding, python-openid uses a blob field for
         # secret
-        assoc.secret = unicode(base64.encodestring(association.secret))
+        assoc.secret = six.text_type(base64.encodestring(association.secret))
         assoc.issued = association.issued
         assoc.lifetime = association.lifetime
         assoc.assoc_type = association.assoc_type
index bb2de7ab2efdd1b4d52d6fbed039f1f329aca7e3..71f444faaf80680fb3600b22db2c4d1a15baeaa8 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 openid.consumer import consumer
 from openid.consumer.discover import DiscoveryFailure
 from openid.extensions.sreg import SRegRequest, SRegResponse
@@ -186,7 +189,7 @@ def finish_login(request):
 
     if user:
         # Set up login in session
-        request.session['user_id'] = unicode(user.id)
+        request.session['user_id'] = six.text_type(user.id)
         request.session.save()
 
         if request.session.get('next'):
index 1bba3b8cf1e39fc1997852da05da3f09f32b0267..41d38353252a997a17b8483d384a8fcbfb2bfb0a 100644 (file)
@@ -17,6 +17,8 @@ import json
 import logging
 import requests
 
+import six
+
 from werkzeug.exceptions import BadRequest
 
 from mediagoblin import messages, mg_globals
@@ -63,7 +65,7 @@ def login(request):
         user = query.user if query else None
 
         if user:
-            request.session['user_id'] = unicode(user.id)
+            request.session['user_id'] = six.text_type(user.id)
             request.session['persona_login_email'] = email
             request.session.save()
 
index f913a730c88d11b015bd0f8826b4bcdfb7809f9b..1fe1e576a109f8a5c53ced254d0c3c084f1ee44c 100644 (file)
@@ -17,6 +17,8 @@
 import logging
 import re
 
+import six
+
 from werkzeug.exceptions import MethodNotAllowed, BadRequest, NotImplemented
 from werkzeug.wrappers import BaseResponse
 
@@ -133,8 +135,8 @@ def pwg_images_addSimple(request):
             mg_app=request.app, user=request.user,
             submitted_file=request.files['image'],
             filename=request.files['image'].filename,
-            title=unicode(form.name.data),
-            description=unicode(form.comment.data),
+            title=six.text_type(form.name.data),
+            description=six.text_type(form.comment.data),
             upload_limit=upload_limit, max_file_size=max_file_size)
 
         collection_id = form.category.data
index 102fd5de3ee83ad4f6041d1b2702af8dc26cb26a..5a88ddeadf9aa3a01669554c4b727de428f6dfae 100644 (file)
@@ -24,6 +24,8 @@ except:
 import logging
 import os
 
+import six
+
 from mediagoblin import mg_globals as mgg
 from mediagoblin.db.util import atomic_update
 from mediagoblin.db.models import MediaEntry
@@ -46,7 +48,7 @@ class ProgressCallback(object):
 def create_pub_filepath(entry, filename):
     return mgg.public_store.get_unique_filepath(
             ['media_entries',
-             unicode(entry.id),
+             six.text_type(entry.id),
              filename])
 
 
@@ -319,7 +321,7 @@ def mark_entry_failed(entry_id, exc):
         atomic_update(mgg.database.MediaEntry,
             {'id': entry_id},
             {u'state': u'failed',
-             u'fail_error': unicode(exc.exception_path),
+             u'fail_error': six.text_type(exc.exception_path),
              u'fail_metadata': exc.metadata})
     else:
         _log.warn("No idea what happened here, but it failed: %r", exc)
index 121097482ad4f393f57b215986791a55a6e37966..8462e08ef1a55279a093ed392b60de112a1cdba9 100644 (file)
@@ -224,7 +224,7 @@ def clean_listy_filepath(listy_filepath):
       A cleaned list of unicode objects.
     """
     cleaned_filepath = [
-        unicode(secure_filename(filepath))
+        six.text_type(secure_filename(filepath))
         for filepath in listy_filepath]
 
     if u'' in cleaned_filepath:
index c70e273185ea4c03ef7d3ea202bace7ef65dd236..7d3ea8df501dbd2ec232ac2b387b1027d5b688ae 100644 (file)
@@ -18,6 +18,8 @@ import logging
 import uuid
 from os.path import splitext
 
+import six
+
 from werkzeug.utils import secure_filename
 from werkzeug.datastructures import FileStorage
 
@@ -127,7 +129,7 @@ def submit_media(mg_app, user, submitted_file, filename,
 
     # If the filename contains non ascii generate a unique name
     if not all(ord(c) < 128 for c in filename):
-        filename = unicode(uuid.uuid4()) + splitext(filename)[-1]
+        filename = six.text_type(uuid.uuid4()) + splitext(filename)[-1]
 
     # Sniff the submitted media to determine which
     # media plugin should handle processing
@@ -136,7 +138,7 @@ def submit_media(mg_app, user, submitted_file, filename,
     # create entry and save in database
     entry = new_upload_entry(user)
     entry.media_type = media_type
-    entry.title = (title or unicode(splitext(filename)[0]))
+    entry.title = (title or six.text_type(splitext(filename)[0]))
 
     entry.description = description or u""
 
@@ -210,7 +212,7 @@ def prepare_queue_task(app, entry, filename):
     # (If we got it off the task's auto-generation, there'd be
     # a risk of a race condition when we'd save after sending
     # off the task)
-    task_id = unicode(uuid.uuid4())
+    task_id = six.text_type(uuid.uuid4())
     entry.queued_task_id = task_id
 
     # Now store generate the queueing related filename
index 42c378a837e3d5d851cfb88ed8f37f092383a016..b0588599d181563494096f0177538c54578a2b61 100644 (file)
@@ -14,6 +14,8 @@
 # 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 import messages
 import mediagoblin.mg_globals as mg_globals
 
@@ -59,9 +61,9 @@ def submit_start(request):
                     mg_app=request.app, user=request.user,
                     submitted_file=request.files['file'],
                     filename=request.files['file'].filename,
-                    title=unicode(submit_form.title.data),
-                    description=unicode(submit_form.description.data),
-                    license=unicode(submit_form.license.data) or None,
+                    title=six.text_type(submit_form.title.data),
+                    description=six.text_type(submit_form.description.data),
+                    license=six.text_type(submit_form.license.data) or None,
                     tags_string=submit_form.tags.data,
                     upload_limit=upload_limit, max_file_size=max_file_size,
                     urlgen=request.urlgen)
@@ -117,8 +119,8 @@ def add_collection(request, media=None):
     if request.method == 'POST' and submit_form.validate():
         collection = request.db.Collection()
 
-        collection.title = unicode(submit_form.title.data)
-        collection.description = unicode(submit_form.description.data)
+        collection.title = six.text_type(submit_form.title.data)
+        collection.description = six.text_type(submit_form.description.data)
         collection.creator = request.user.id
         collection.generate_slug()
 
index e8fd76d8458c1ea11ca24209624560ec87084957..9b7f9825b7985110e2703a0457df2b4f1d5914dc 100644 (file)
@@ -18,6 +18,8 @@
 import pkg_resources
 import pytest
 
+import six
+
 import six.moves.urllib.parse as urlparse
 
 from mediagoblin import mg_globals
@@ -109,7 +111,7 @@ def test_register_views(test_app):
     ## Make sure user is logged in
     request = template.TEMPLATE_TEST_CONTEXT[
         'mediagoblin/user_pages/user_nonactive.html']['request']
-    assert request.session['user_id'] == unicode(new_user.id)
+    assert request.session['user_id'] == six.text_type(new_user.id)
 
     ## Make sure we get email confirmation, and try verifying
     assert len(mail.EMAIL_TEST_INBOX) == 1
@@ -307,7 +309,7 @@ def test_authentication_views(test_app):
     # Make sure user is in the session
     context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
     session = context['request'].session
-    assert session['user_id'] == unicode(test_user.id)
+    assert session['user_id'] == six.text_type(test_user.id)
 
     # Successful logout
     # -----------------
index 64b7ee8f4cec8d389dcd5758a930b22db0413425..d0a8c823177d3d9a58662e1b89163731772daa2e 100644 (file)
@@ -17,6 +17,8 @@
 import json
 
 import pytest
+import six
+
 from urlparse import urlparse, parse_qs
 
 from mediagoblin import mg_globals
@@ -63,7 +65,7 @@ class TestHTTPCallback(object):
         code = parse_qs(urlparse(redirect.location).query)['code'][0]
 
         client = self.db.OAuthClient.query.filter(
-                self.db.OAuthClient.identifier == unicode(client_id)).first()
+                self.db.OAuthClient.identifier == six.text_type(client_id)).first()
 
         client_secret = client.secret
 
index 33cf85d6c33713ffe104fe5a2c7216a3cbb79a66..e69a32034c45bd9deb6e0ceae86d947ed2abb8c0 100644 (file)
@@ -17,6 +17,7 @@
 import pkg_resources
 import pytest
 import mock
+import six
 
 import six.moves.urllib.parse as urlparse
 
@@ -122,6 +123,6 @@ def test_ldap_plugin(ldap_plugin_app):
         # Make sure user is in the session
         context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
         session = context['request'].session
-        assert session['user_id'] == unicode(test_user.id)
+        assert session['user_id'] == six.text_type(test_user.id)
 
     _test_authentication()
index 957f4e658e11bc959e587ee535e579fdb795cc73..6bdb729e84029904f48b89c31eec9c45c200500e 100644 (file)
@@ -18,6 +18,8 @@ import json
 import logging
 
 import pytest
+import six
+
 from urlparse import parse_qs, urlparse
 
 from mediagoblin import mg_globals
@@ -154,7 +156,7 @@ class TestOAuth(object):
         code = self.get_code_from_redirect_uri(code_redirect.location)
 
         client = self.db.OAuthClient.query.filter(
-                self.db.OAuthClient.identifier == unicode(client_id)).first()
+                self.db.OAuthClient.identifier == six.text_type(client_id)).first()
 
         token_res = self.test_app.get('/oauth-2/access_token?client_id={0}&\
 code={1}&client_secret={2}'.format(client_id, code, client.secret))
@@ -182,7 +184,7 @@ code={1}&client_secret={2}'.format(client_id, code, client.secret))
         code = self.get_code_from_redirect_uri(code_redirect.location)
 
         client = self.db.OAuthClient.query.filter(
-                self.db.OAuthClient.identifier == unicode(client_id)).first()
+                self.db.OAuthClient.identifier == six.text_type(client_id)).first()
 
         token_res = self.test_app.get('/oauth-2/access_token?\
 code={0}&client_secret={1}'.format(code, client.secret))
index 0424fdda511ea95270bc78bceddc6ac7bd69c68b..7ef010522cbb30da50fe42b30113bd01832e1557 100644 (file)
@@ -18,6 +18,7 @@ import urlparse
 import pkg_resources
 import pytest
 import mock
+import six
 
 openid_consumer = pytest.importorskip(
     "openid.consumer.consumer")
@@ -206,7 +207,7 @@ class TestOpenIDPlugin(object):
             # Make sure user is in the session
             context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
             session = context['request'].session
-            assert session['user_id'] == unicode(test_user.id)
+            assert session['user_id'] == six.text_type(test_user.id)
 
         _test_new_user()
 
index dbc4797a5c72909bac696a36c047b8f35e78afc1..f2dd400162825ff8b2f2b2a9c460205ea3e92100 100644 (file)
@@ -17,6 +17,7 @@
 import pkg_resources
 import pytest
 import mock
+import six
 
 import six.moves.urllib.parse as urlparse
 
@@ -142,7 +143,7 @@ class TestPersonaPlugin(object):
             # Make sure user is in the session
             context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
             session = context['request'].session
-            assert session['user_id'] == unicode(test_user.id)
+            assert session['user_id'] == six.text_type(test_user.id)
 
         _test_registration()
 
index a154a061d12a2899387a4adf8d4ff190875fd990..6a9fe205ffde0ad828461810bf111cbb7e72b19f 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pytest
+import six
 
 from mediagoblin.tools import template
 from mediagoblin.tests.tools import (fixture_add_user, fixture_media_entry,
@@ -75,7 +76,7 @@ class TestReportFiling:
 
         response, context = self.do_post(
             {'report_reason':u'Testing Media Report',
-            'reporter_id':unicode(allie_id)},url= media_uri_slug + "report/")
+            'reporter_id':six.text_type(allie_id)},url= media_uri_slug + "report/")
 
         assert response.status == "302 FOUND"
 
@@ -110,7 +111,7 @@ class TestReportFiling:
 
         response, context = self.do_post({
             'report_reason':u'Testing Comment Report',
-            'reporter_id':unicode(allie_id)},url= comment_uri_slug + "report/")
+            'reporter_id':six.text_type(allie_id)},url= comment_uri_slug + "report/")
 
         assert response.status == "302 FOUND"
 
index f6f1d18f532004b9e4280638fab10e1dfc70554c..2194741596135a2039ab941b101701a95e7b4b6d 100644 (file)
@@ -19,6 +19,8 @@ import os
 import tempfile
 
 import pytest
+import six
+
 from werkzeug.utils import secure_filename
 
 from mediagoblin import storage
@@ -78,7 +80,7 @@ def test_storage_system_from_config():
              'mediagoblin.tests.test_storage:FakeStorageSystem'})
     assert this_storage.foobie == 'eiboof'
     assert this_storage.blech == 'hcelb'
-    assert unicode(this_storage.__class__) == \
+    assert six.text_type(this_storage.__class__) == \
         u'mediagoblin.tests.test_storage.FakeStorageSystem'
 
 
index 5ddd882c4041fc628272c98def91bc7cdf2304fd..6143c0ac9eb4fe4e2c6dbae062b7948e06b79264 100644 (file)
@@ -20,6 +20,7 @@ sys.setdefaultencoding('utf-8')
 
 import os
 import pytest
+import six
 
 import six.moves.urllib.parse as urlparse
 
@@ -35,7 +36,7 @@ from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \
     BIG_BLUE, GOOD_PDF, GPS_JPG, MED_PNG, BIG_PNG
 
 GOOD_TAG_STRING = u'yin,yang'
-BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26)
+BAD_TAG_STRING = six.text_type('rage,' + 'f' * 26 + 'u' * 26)
 
 FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form']
 REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
index 9d9b1c161448b291b26b8854da9d0412eb1521da..e108e9bbf6691775056c9eae4ca30d140c4236a1 100644 (file)
@@ -16,6 +16,8 @@
 
 import email
 
+import six
+
 from mediagoblin.tools import common, url, translate, mail, text, testing
 
 testing._activate_testing()
@@ -117,13 +119,13 @@ def test_gettext_lazy_proxy():
     orig = u"Password"
 
     set_thread_locale("es")
-    p1 = unicode(proxy)
+    p1 = six.text_type(proxy)
     p1_should = pass_to_ugettext(orig)
     assert p1_should != orig, "Test useless, string not translated"
     assert p1 == p1_should
 
     set_thread_locale("sv")
-    p2 = unicode(proxy)
+    p2 = six.text_type(proxy)
     p2_should = pass_to_ugettext(orig)
     assert p2_should != orig, "Test broken, string not translated"
     assert p2 == p2_should
index 657c0373d4397d66873ddfcf0bd1458ae6b3fac7..4d97247ad12c59efb0fff55adfad358ef953fff6 100644 (file)
@@ -17,6 +17,8 @@
 import re
 from unidecode import unidecode
 
+import six
+
 _punct_re = re.compile(r'[\t !"#:$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
 
 
@@ -27,4 +29,4 @@ def slugify(text, delim=u'-'):
     result = []
     for word in _punct_re.split(text.lower()):
         result.extend(unidecode(word).split())
-    return unicode(delim.join(result))
+    return six.text_type(delim.join(result))
index 78751a28f85ef0d2ccc794618c2ba0b71b7033c0..1f0b9dcd0a0600aa7180aa51f6bd0d6c49b32eea 100644 (file)
@@ -18,6 +18,8 @@ import logging
 import datetime
 import json
 
+import six
+
 from mediagoblin import messages, mg_globals
 from mediagoblin.db.models import (MediaEntry, MediaTag, Collection,
                                    CollectionItem, User)
@@ -178,7 +180,7 @@ def media_post_comment(request, media):
     comment = request.db.MediaComment()
     comment.media_entry = media.id
     comment.author = request.user.id
-    comment.content = unicode(request.form['comment_content'])
+    comment.content = six.text_type(request.form['comment_content'])
 
     # Show error message if commenting is disabled.
     if not mg_globals.app_config['allow_comments']:
@@ -212,7 +214,7 @@ def media_preview_comment(request):
     if not request.is_xhr:
         return render_404(request)
 
-    comment = unicode(request.form['comment_content'])
+    comment = six.text_type(request.form['comment_content'])
     cleancomment = { "content":cleaned_markdown_conversion(comment)}
 
     return Response(json.dumps(cleancomment))