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