Skip to content
Myr

python-modernize automated changes: fix_unicode (but without six.u())

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Thomas Waldmann · committed by Thomas Waldmann · parent dcd0523 · Browse files · 6 files+13 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+13 added−9 removed

  • other:+13 added−9 removed

6 files+13 added−9 removed

modified:flask/testsuite/basic.py+2 added-1 removed
20 unmodified lines
21from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning22from werkzeug.exceptions import BadRequest, NotFound23from werkzeug.http import parse_date24from werkzeug.routing import BuildError25import six262728class BasicFunctionalityTestCase(FlaskTestCase):29
247 unmodified lines
277 return ''278279 @app.route('/test')280 def test():280 return unicode(flask.session.permanent)281 return six.text_type(flask.session.permanent)282283 client = app.test_client()284 rv = client.get('/')285 self.assert_('set-cookie' in rv.headers)
868 unmodified lines
modified:flask/testsuite/blueprints.py+2 added-1 removed
16 unmodified lines
17from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning18from werkzeug.exceptions import NotFound19from werkzeug.http import parse_cache_control_header20from jinja2 import TemplateNotFound21import six222324# import moduleapp here because it uses deprecated features and we don't25# want to see the warnings
278 unmodified lines
304 return '%s/%d' % (bar, baz)305306 @bp.route('/bar')307 def bar(bar):307 return unicode(bar)308 return six.text_type(bar)309310 app = flask.Flask(__name__)311 app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23})312 app.register_blueprint(bp, url_prefix='/2', url_defaults={'bar': 19})
455 unmodified lines
modified:flask/testsuite/helpers.py+3 added-3 removed
34 unmodified lines
35 def test_json_bad_requests(self):36 app = flask.Flask(__name__)37 @app.route('/json', methods=['POST'])38 def return_json():39 return unicode(flask.request.json)39 return six.text_type(flask.request.json)40 c = app.test_client()41 rv = c.post('/json', data='malformed', content_type='application/json')42 self.assert_equal(rv.status_code, 400)4344 def test_json_bad_requests_content_type(self):45 app = flask.Flask(__name__)46 @app.route('/json', methods=['POST'])47 def return_json():48 return unicode(flask.request.json)48 return six.text_type(flask.request.json)49 c = app.test_client()50 rv = c.post('/json', data='malformed', content_type='application/json')51 self.assert_equal(rv.status_code, 400)52 self.assert_equal(rv.mimetype, 'application/json')
43 unmodified lines
96 def test_json_attr(self):97 app = flask.Flask(__name__)98 @app.route('/add', methods=['POST'])99 def add():100 return unicode(flask.request.json['a'] + flask.request.json['b'])100 return six.text_type(flask.request.json['a'] + flask.request.json['b'])101 c = app.test_client()102 rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}),103 content_type='application/json')104 self.assert_equal(rv.data, '3')
430 unmodified lines
modified:flask/testsuite/testing.py+2 added-1 removed
12 unmodified lines
1314import flask15import unittest16from flask.testsuite import FlaskTestCase17import six181920class TestToolsTestCase(FlaskTestCase):21
63 unmodified lines
85 app.secret_key = 'testing'8687 @app.route('/')88 def index():88 return unicode(flask.session['foo'])89 return six.text_type(flask.session['foo'])9091 with app.test_client() as c:92 with c.session_transaction() as sess:93 self.assert_equal(len(sess), 0)
151 unmodified lines
modified:flask/json.py+2 added-1 removed
15 unmodified lines
1617# Use the same json implementation as itsdangerous on which we18# depend anyways.19from itsdangerous import simplejson as _json20import six212223# figure out if simplejson escapes slashes. This behavior was changed24# from one version to another without reason.
34 unmodified lines
59 return http_date(o)60 if isinstance(o, uuid.UUID):61 return str(o)62 if hasattr(o, '__html__'):62 return unicode(o.__html__())63 return six.text_type(o.__html__())64 return _json.JSONEncoder.default(self, o)656667class JSONDecoder(_json.JSONDecoder):
106 unmodified lines
modified:flask/sessions.py+2 added-2 removed
61 unmodified lines
62 return {' t': [_tag(x) for x in value]}63 elif isinstance(value, uuid.UUID):64 return {' u': value.hex}65 elif callable(getattr(value, '__html__', None)):66 return {' m': unicode(value.__html__())}66 return {' m': six.text_type(value.__html__())}67 elif isinstance(value, list):68 return [_tag(x) for x in value]69 elif isinstance(value, datetime):70 return {' d': http_date(value)}71 elif isinstance(value, dict):72 return dict((k, _tag(v)) for k, v in six.iteritems(value))73 elif isinstance(value, str):74 try:75 return unicode(value)75 return six.text_type(value)76 except UnicodeError:77 raise UnexpectedUnicodeError(u'A byte string with '78 u'non-ASCII data was passed to the session system '79 u'which can only store unicode strings. Consider '
248 unmodified lines