mirror of https://github.com/pallets/flask.git
python-modernize automated changes: fix_unicode (but without six.u())
This commit is contained in:
parent
dcd052366b
commit
522cd00093
|
|
@ -17,6 +17,7 @@ from werkzeug.http import http_date
|
|||
# Use the same json implementation as itsdangerous on which we
|
||||
# depend anyways.
|
||||
from itsdangerous import simplejson as _json
|
||||
import six
|
||||
|
||||
|
||||
# figure out if simplejson escapes slashes. This behavior was changed
|
||||
|
|
@ -59,7 +60,7 @@ class JSONEncoder(_json.JSONEncoder):
|
|||
if isinstance(o, uuid.UUID):
|
||||
return str(o)
|
||||
if hasattr(o, '__html__'):
|
||||
return unicode(o.__html__())
|
||||
return six.text_type(o.__html__())
|
||||
return _json.JSONEncoder.default(self, o)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class TaggedJSONSerializer(object):
|
|||
elif isinstance(value, uuid.UUID):
|
||||
return {' u': value.hex}
|
||||
elif callable(getattr(value, '__html__', None)):
|
||||
return {' m': unicode(value.__html__())}
|
||||
return {' m': six.text_type(value.__html__())}
|
||||
elif isinstance(value, list):
|
||||
return [_tag(x) for x in value]
|
||||
elif isinstance(value, datetime):
|
||||
|
|
@ -72,7 +72,7 @@ class TaggedJSONSerializer(object):
|
|||
return dict((k, _tag(v)) for k, v in six.iteritems(value))
|
||||
elif isinstance(value, str):
|
||||
try:
|
||||
return unicode(value)
|
||||
return six.text_type(value)
|
||||
except UnicodeError:
|
||||
raise UnexpectedUnicodeError(u'A byte string with '
|
||||
u'non-ASCII data was passed to the session system '
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
|
|||
from werkzeug.exceptions import BadRequest, NotFound
|
||||
from werkzeug.http import parse_date
|
||||
from werkzeug.routing import BuildError
|
||||
import six
|
||||
|
||||
|
||||
class BasicFunctionalityTestCase(FlaskTestCase):
|
||||
|
|
@ -277,7 +278,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
|
||||
@app.route('/test')
|
||||
def test():
|
||||
return unicode(flask.session.permanent)
|
||||
return six.text_type(flask.session.permanent)
|
||||
|
||||
client = app.test_client()
|
||||
rv = client.get('/')
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
|
|||
from werkzeug.exceptions import NotFound
|
||||
from werkzeug.http import parse_cache_control_header
|
||||
from jinja2 import TemplateNotFound
|
||||
import six
|
||||
|
||||
|
||||
# import moduleapp here because it uses deprecated features and we don't
|
||||
|
|
@ -304,7 +305,7 @@ class BlueprintTestCase(FlaskTestCase):
|
|||
|
||||
@bp.route('/bar')
|
||||
def bar(bar):
|
||||
return unicode(bar)
|
||||
return six.text_type(bar)
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23})
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class JSONTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
@app.route('/json', methods=['POST'])
|
||||
def return_json():
|
||||
return unicode(flask.request.json)
|
||||
return six.text_type(flask.request.json)
|
||||
c = app.test_client()
|
||||
rv = c.post('/json', data='malformed', content_type='application/json')
|
||||
self.assert_equal(rv.status_code, 400)
|
||||
|
|
@ -45,7 +45,7 @@ class JSONTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
@app.route('/json', methods=['POST'])
|
||||
def return_json():
|
||||
return unicode(flask.request.json)
|
||||
return six.text_type(flask.request.json)
|
||||
c = app.test_client()
|
||||
rv = c.post('/json', data='malformed', content_type='application/json')
|
||||
self.assert_equal(rv.status_code, 400)
|
||||
|
|
@ -97,7 +97,7 @@ class JSONTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
@app.route('/add', methods=['POST'])
|
||||
def add():
|
||||
return unicode(flask.request.json['a'] + flask.request.json['b'])
|
||||
return six.text_type(flask.request.json['a'] + flask.request.json['b'])
|
||||
c = app.test_client()
|
||||
rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}),
|
||||
content_type='application/json')
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from __future__ import with_statement
|
|||
import flask
|
||||
import unittest
|
||||
from flask.testsuite import FlaskTestCase
|
||||
import six
|
||||
|
||||
|
||||
class TestToolsTestCase(FlaskTestCase):
|
||||
|
|
@ -85,7 +86,7 @@ class TestToolsTestCase(FlaskTestCase):
|
|||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return unicode(flask.session['foo'])
|
||||
return six.text_type(flask.session['foo'])
|
||||
|
||||
with app.test_client() as c:
|
||||
with c.session_transaction() as sess:
|
||||
|
|
|
|||
Loading…
Reference in New Issue