Skip to content
Myr

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

13 files+42 added−19 removed

modified:flask/testsuite/__init__.py+2 added-1 removed
8 unmodified lines
9 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213from __future__ import print_function14from __future__ import with_statement1516import os17import sys
203 unmodified lines
221 """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 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/config.py+1 added-1 removed
111 unmodified lines
112113 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)118119120@contextmanager
180 unmodified lines
modified:flask/testsuite/ext.py+2 added-2 removed
11 unmodified lines
1213import sys14import unittest15from flask.testsuite import FlaskTestCase16from six import reload_module171718class ExtImportHookTestCase(FlaskTestCase):1920 def setup(self):21 # we clear this out for various reasons. The most important one is
6 unmodified lines
28 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)3334 # reloading must not add more hooks35 import_hooks = 036 for item in sys.meta_path:
87 unmodified lines
modified:flask/testsuite/helpers.py+5 added-4 removed
16 unmodified lines
17from logging import StreamHandler18from StringIO import StringIO19from flask.testsuite import FlaskTestCase, catch_warnings, catch_stderr20from werkzeug.http import parse_cache_control_header, parse_options_header21import six222324def has_encoding(name):25 try:
9 unmodified lines
35 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)4344 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 lines
96 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 lines
507 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 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
added:flask/_compat.py+13 added
1# -*- coding: utf-8 -*-2"""3 flask._compat4 ~~~~~~~~~~~~~56 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.1011 :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 lines
252627from werkzeug.datastructures import Headers28from werkzeug.exceptions import NotFound29import six3031# this was moved in 0.732try:33 from werkzeug.wsgi import wrap_file
94 unmodified lines
128 # 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_g134135136def make_response(*args):
710 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):
105 unmodified lines
modified:flask/sessions.py+5 added-4 removed
15 unmodified lines
16from werkzeug.datastructures import CallbackDict17from . import Markup, json1819from itsdangerous import URLSafeTimedSerializer, BadSignature20import six212223def total_seconds(td):24 return td.days * 60 * 60 * 24 + td.seconds
37 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)):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 lines
84 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 lines
modified:flask/templating.py+3 added-2 removed
13 unmodified lines
1415from .globals import _request_ctx_stack, _app_ctx_stack16from .signals import template_rendered17from .module import blueprint_is_module18import six192021def _default_template_ctx_processor():22 """Default template context processor. Injects `request`,
56 unmodified lines
79 yield loader, local_name80 except (ValueError, KeyError):81 pass8282 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 lines
92 loader = self.app.jinja_loader93 if loader is not None:94 result.update(loader.list_templates())9595 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 lines
modified:setup.py+1 added
88 unmodified lines
89 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