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