Merge branch 'six' of github.com:ThomasWaldmann/flask into ThomasWaldmann-six
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Conflicts: flask/testsuite/__init__.py
authored by Daniel Neuhäuser · committed by Daniel Neuhäuser · parents aba1d3a, 287905e · Browse files · 13 files·+42 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+42 added−19 removed
- other:+42 added−19 removed
Provenance
- Commit
8494574- Tree
2e28299- Author
Daniel Neuhäuser <dasdasich@gmail.com>- Committer
Daniel Neuhäuser <dasdasich@gmail.com>- Parent 1
aba1d3a- Parent 2
287905e
13 files changed+42 added−19 removed
modified:flask/testsuite/__init__.py+2 added-1 removed
8 unmodified lines9 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11 """12 13+from __future__ import print_function14 from __future__ import with_statement15 16 import os17 import sys203 unmodified lines221 """Runs the testsuite as command line application."""222 try:223 unittest.main(testLoader=BetterLoader(), defaultTest='suite')224 except Exception as e:224- print 'Error: %s' % e225+ print('Error: %s' % e)modified:flask/testsuite/basic.py+2 added-1 removed
20 unmodified lines21 from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning22 from werkzeug.exceptions import BadRequest, NotFound23 from werkzeug.http import parse_date24 from werkzeug.routing import BuildError25+import six26 27 28 class BasicFunctionalityTestCase(FlaskTestCase):29 247 unmodified lines277 return ''278 279 @app.route('/test')280 def test():280- return unicode(flask.session.permanent)281+ return six.text_type(flask.session.permanent)282 283 client = app.test_client()284 rv = client.get('/')285 self.assert_('set-cookie' in rv.headers)868 unmodified linesmodified:flask/testsuite/blueprints.py+2 added-1 removed
16 unmodified lines17 from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning18 from werkzeug.exceptions import NotFound19 from werkzeug.http import parse_cache_control_header20 from jinja2 import TemplateNotFound21+import six22 23 24 # import moduleapp here because it uses deprecated features and we don't25 # want to see the warnings278 unmodified lines304 return '%s/%d' % (bar, baz)305 306 @bp.route('/bar')307 def bar(bar):307- return unicode(bar)308+ return six.text_type(bar)309 310 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 linesmodified:flask/testsuite/config.py+1 added-1 removed
111 unmodified lines112 113 def __getattr__(self, name):114 if name in ('archive', 'get_filename'):115 msg = 'Mocking a loader which does not have `%s.`' % name116- raise AttributeError, msg116+ raise AttributeError(msg)117 return getattr(self.loader, name)118 119 120 @contextmanager180 unmodified linesmodified:flask/testsuite/ext.py+2 added-2 removed
11 unmodified lines12 13 import sys14 import unittest15 from flask.testsuite import FlaskTestCase16+from six import reload_module17 17-18 class ExtImportHookTestCase(FlaskTestCase):19 20 def setup(self):21 # we clear this out for various reasons. The most important one is6 unmodified lines28 entry.startswith('flaskext.') or29 entry == 'flaskext') and value is not None:30 sys.modules.pop(entry, None)31 from flask import ext32- reload(ext)32+ reload_module(ext)33 34 # reloading must not add more hooks35 import_hooks = 036 for item in sys.meta_path:87 unmodified linesmodified:flask/testsuite/helpers.py+5 added-4 removed
16 unmodified lines17 from logging import StreamHandler18 from StringIO import StringIO19 from flask.testsuite import FlaskTestCase, catch_warnings, catch_stderr20 from werkzeug.http import parse_cache_control_header, parse_options_header21+import six22 23 24 def has_encoding(name):25 try:9 unmodified lines35 def test_json_bad_requests(self):36 app = flask.Flask(__name__)37 @app.route('/json', methods=['POST'])38 def return_json():38- 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)43 44 def test_json_bad_requests_content_type(self):45 app = flask.Flask(__name__)46 @app.route('/json', methods=['POST'])47 def return_json():47- 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 lines96 def test_json_attr(self):97 app = flask.Flask(__name__)98 @app.route('/add', methods=['POST'])99 def add():99- 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')402 unmodified lines507 return self508 def close(self):509 called.append(42)510 def next(self):510- return self._gen.next()511+ return six.advance_iterator(self._gen)512 @app.route('/')513 def index():514 def generate():515 yield 'Hello '19 unmodified linesmodified:flask/testsuite/testing.py+2 added-1 removed
12 unmodified lines13 14 import flask15 import unittest16 from flask.testsuite import FlaskTestCase17+import six18 19 20 class TestToolsTestCase(FlaskTestCase):21 63 unmodified lines85 app.secret_key = 'testing'86 87 @app.route('/')88 def index():88- return unicode(flask.session['foo'])89+ return six.text_type(flask.session['foo'])90 91 with app.test_client() as c:92 with c.session_transaction() as sess:93 self.assert_equal(len(sess), 0)151 unmodified linesadded:flask/_compat.py+13 added
1+# -*- coding: utf-8 -*-2+"""3+ flask._compat4+ ~~~~~~~~~~~~~5+6+ Some py2/py3 compatibility support that is not yet available in7+ "six" 1.3.0.8+ There are bugs open for "six" for all this stuff, so we can remove it9+ again from here as soon as we require a new enough "six" release.10+11+ :copyright: (c) 2013 by Armin Ronacher.12+ :license: BSD, see LICENSE for more details.13+"""modified:flask/helpers.py+2 added-1 removed
24 unmodified lines25 26 27 from werkzeug.datastructures import Headers28 from werkzeug.exceptions import NotFound29+import six30 31 # this was moved in 0.732 try:33 from werkzeug.wsgi import wrap_file94 unmodified lines128 # the first dummy None is yielded at which point the context was already129 # pushed. This item is discarded. Then when the iteration continues the130 # real generator is executed.131 wrapped_g = generator()131- wrapped_g.next()132+ six.advance_iterator(wrapped_g)133 return wrapped_g134 135 136 def make_response(*args):710 unmodified linesmodified:flask/json.py+2 added-1 removed
15 unmodified lines16 17 # Use the same json implementation as itsdangerous on which we18 # depend anyways.19 from itsdangerous import simplejson as _json20+import six21 22 23 # figure out if simplejson escapes slashes. This behavior was changed24 # from one version to another without reason.34 unmodified lines59 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)65 66 67 class JSONDecoder(_json.JSONDecoder):105 unmodified linesmodified:flask/sessions.py+5 added-4 removed
15 unmodified lines16 from werkzeug.datastructures import CallbackDict17 from . import Markup, json18 19 from itsdangerous import URLSafeTimedSerializer, BadSignature20+import six21 22 23 def total_seconds(td):24 return td.days * 60 * 60 * 24 + td.seconds37 unmodified lines62 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)):65- 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):71- return dict((k, _tag(v)) for k, v in value.iteritems())72+ return dict((k, _tag(v)) for k, v in six.iteritems(value))73 elif isinstance(value, str):74 try:74- 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 '4 unmodified lines84 def loads(self, value):85 def object_hook(obj):86 if len(obj) != 1:87 return obj87- the_key, the_value = obj.iteritems().next()88+ the_key, the_value = six.advance_iterator(obj.iteritems())89 if the_key == ' t':90 return tuple(the_value)91 elif the_key == ' u':92 return uuid.UUID(the_value)235 unmodified linesmodified:flask/templating.py+3 added-2 removed
13 unmodified lines14 15 from .globals import _request_ctx_stack, _app_ctx_stack16 from .signals import template_rendered17 from .module import blueprint_is_module18+import six19 20 21 def _default_template_ctx_processor():22 """Default template context processor. Injects `request`,56 unmodified lines79 yield loader, local_name80 except (ValueError, KeyError):81 pass82 82- for blueprint in self.app.blueprints.itervalues():83+ for blueprint in six.itervalues(self.app.blueprints):84 if blueprint_is_module(blueprint):85 continue86 loader = blueprint.jinja_loader87 if loader is not None:4 unmodified lines92 loader = self.app.jinja_loader93 if loader is not None:94 result.update(loader.list_templates())95 95- for name, blueprint in self.app.blueprints.iteritems():96+ for name, blueprint in six.iteritems(self.app.blueprints):97 loader = blueprint.jinja_loader98 if loader is not None:99 for template in loader.list_templates():100 prefix = ''43 unmodified linesmodified:setup.py+1 added
88 unmodified lines89 include_package_data=True,90 zip_safe=False,91 platforms='any',92 install_requires=[93+ 'six>=1.3.0',94 'Werkzeug>=0.7',95 'Jinja2>=2.4',96 'itsdangerous>=0.17'97 ],15 unmodified lines