test_helpers.py
This file
Path
tests/test_helpers.py
1,062 lines · 34.4 KiB · Python
Last changed by
Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
History of this fileTake it
The walk stopped after 200 commits: lines older than bce8ec7 point at it.
Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 1–7why, one step back1# -*- coding: utf-8 -*-2"""3 tests.helpers4 ~~~~~~~~~~~~~~~~~~~~~~~56 Various helpers.7Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c
line 8why, one step back8 :copyright: © 2010 by the Pallets team.Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 9–11why, one step back9 :license: BSD, see LICENSE for more details.10"""11Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 12why, one step back12import datetimeMerge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d
line 13why, one step back13import ioMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 14–16why, one step back14import os15import uuid16Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 17why, one step back17import pytestMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 18–19why, one step back18from werkzeug.datastructures import Range19from werkzeug.exceptions import BadRequest, NotFoundMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 20why, one step back20from werkzeug.http import http_date, parse_cache_control_header, parse_options_headerMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 21–22why, one step back2122import flaskMerge pull request #2691 from pallets/json-encodingDavid Lordbefore adoption465b48e
line 23why, one step back23from flask import jsonMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 24why, one step back24from flask._compat import StringIO, text_typeAdd Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522
line 25why, one step back25from flask.helpers import get_debug_flag, get_envMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 26–30why, one step back262728def has_encoding(name):29 try:30 import codecsMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 31why, one step back31Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 32–37why, one step back32 codecs.lookup(name)33 return True34 except LookupError:35 return False3637Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
lines 38–43why, one step back38class FakePath(object):39 """Fake object to represent a ``PathLike object``.4041 This represents a ``pathlib.Path`` object in python 3.42 See: https://www.python.org/dev/peps/pep-0519/43 """Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 44why, one step back44Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
lines 45–51why, one step back45 def __init__(self, path):46 self.path = path4748 def __fspath__(self):49 return self.path5051Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 52–73why, one step back52class FixedOffset(datetime.tzinfo):53 """Fixed offset in hours east from UTC.5455 This is a slight adaptation of the ``FixedOffset`` example found in56 https://docs.python.org/2.7/library/datetime.html.57 """5859 def __init__(self, hours, name):60 self.__offset = datetime.timedelta(hours=hours)61 self.__name = name6263 def utcoffset(self, dt):64 return self.__offset6566 def tzname(self, dt):67 return self.__name6869 def dst(self, dt):70 return datetime.timedelta()717273class TestJSON(object):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 74–89why, one step back74 @pytest.mark.parametrize(75 "value", (1, "t", True, False, None, [], [1, 2, 3], {}, {"foo": u"🐍"})76 )77 @pytest.mark.parametrize(78 "encoding",79 (80 "utf-8",81 "utf-8-sig",82 "utf-16-le",83 "utf-16-be",84 "utf-16",85 "utf-32-le",86 "utf-32-be",87 "utf-32",88 ),89 )Merge pull request #2691 from pallets/json-encodingDavid Lordbefore adoption465b48e
lines 90–94why, one step back90 def test_detect_encoding(self, value, encoding):91 data = json.dumps(value).encode(encoding)92 assert json.detect_encoding(data) == encoding93 assert json.loads(data) == value94Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 95why, one step back95 def test_ignore_cached_json(self, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 96–98why, one step back96 with app.test_request_context(97 "/", method="POST", data="malformed", content_type="application/json"98 ):Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 99–102why, one step back99 assert flask.request.get_json(silent=True, cache=True) is None100 with pytest.raises(BadRequest):101 flask.request.get_json(silent=False, cache=False)102Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 103–104why, one step back103 def test_different_silent_on_bad_request(self, app):104 with app.test_request_context(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 105–106why, one step back105 "/", method="POST", data="malformed", content_type="application/json"106 ):Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 107–111why, one step back107 assert flask.request.get_json(silent=True) is None108 with pytest.raises(BadRequest):109 flask.request.get_json(silent=False)110111 def test_different_silent_on_normal_request(self, app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 112why, one step back112 with app.test_request_context("/", method="POST", json={"foo": "bar"}):Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 113–115why, one step back113 silent_rv = flask.request.get_json(silent=True)114 normal_rv = flask.request.get_json(silent=False)115 assert silent_rv is normal_rvMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 116why, one step back116 assert normal_rv["foo"] == "bar"Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
line 117why, one step back117Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 118–122why, one step back118 def test_post_empty_json_adds_exception_to_response_content_in_debug(119 self, app, client120 ):121 app.config["DEBUG"] = True122 app.config["TRAP_BAD_REQUEST_ERRORS"] = FalseMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 123why, one step back123Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 124why, one step back124 @app.route("/json", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 125–128why, one step back125 def post_json():126 flask.request.get_json()127 return None128Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 129why, one step back129 rv = client.post("/json", data=None, content_type="application/json")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 130why, one step back130 assert rv.status_code == 400Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 131why, one step back131 assert b"Failed to decode JSON object" in rv.dataMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 132why, one step back132Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 133–137why, one step back133 def test_post_empty_json_wont_add_exception_to_response_if_no_debug(134 self, app, client135 ):136 app.config["DEBUG"] = False137 app.config["TRAP_BAD_REQUEST_ERRORS"] = FalseMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 138why, one step back138Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 139why, one step back139 @app.route("/json", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 140–143why, one step back140 def post_json():141 flask.request.get_json()142 return None143Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 144why, one step back144 rv = client.post("/json", data=None, content_type="application/json")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 145why, one step back145 assert rv.status_code == 400Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 146why, one step back146 assert b"Failed to decode JSON object" not in rv.dataMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 147–148why, one step back147148 def test_json_bad_requests(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 149why, one step back149 @app.route("/json", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 150–152why, one step back150 def return_json():151 return flask.jsonify(foo=text_type(flask.request.get_json()))152Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 153why, one step back153 rv = client.post("/json", data="malformed", content_type="application/json")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 154–156why, one step back154 assert rv.status_code == 400155156 def test_json_custom_mimetypes(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 157why, one step back157 @app.route("/json", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 158–160why, one step back158 def return_json():159 return flask.request.get_json()160Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 161–162why, one step back161 rv = client.post("/json", data='"foo"', content_type="application/x+json")162 assert rv.data == b"foo"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 163why, one step back163Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 164–166why, one step back164 @pytest.mark.parametrize(165 "test_value,expected", [(True, '"\\u2603"'), (False, u'"\u2603"')]166 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 167–168why, one step back167 def test_json_as_unicode(self, test_value, expected, app, app_ctx):168Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 169–170why, one step back169 app.config["JSON_AS_ASCII"] = test_value170 rv = flask.json.dumps(u"\N{SNOWMAN}")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 171–173why, one step back171 assert rv == expected172173 def test_json_dump_to_file(self, app, app_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 174why, one step back174 test_data = {"name": "Flask"}Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 175–181why, one step back175 out = StringIO()176177 flask.json.dump(test_data, out)178 out.seek(0)179 rv = flask.json.load(out)180 assert rv == test_data181Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 182–184why, one step back182 @pytest.mark.parametrize(183 "test_value", [0, -1, 1, 23, 3.14, "s", "longer string", True, False, None]184 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 185–187why, one step back185 def test_jsonify_basic_types(self, test_value, app, client):186 """Test jsonify with basic types."""187Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 188why, one step back188 url = "/jsonify_basic_types"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 189–190why, one step back189 app.add_url_rule(url, url, lambda x=test_value: flask.jsonify(x))190 rv = client.get(url)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 191why, one step back191 assert rv.mimetype == "application/json"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 192–195why, one step back192 assert flask.json.loads(rv.data) == test_value193194 def test_jsonify_dicts(self, app, client):195 """Test jsonify with dicts and kwargs unpacking."""Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 196–206why, one step back196 d = {197 "a": 0,198 "b": 23,199 "c": 3.14,200 "d": "t",201 "e": "Hi",202 "f": True,203 "g": False,204 "h": ["test list", 10, False],205 "i": {"test": "dict"},206 }Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 207why, one step back207Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 208why, one step back208 @app.route("/kw")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 209–211why, one step back209 def return_kwargs():210 return flask.jsonify(**d)211Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 212why, one step back212 @app.route("/dict")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 213–215why, one step back213 def return_dict():214 return flask.jsonify(d)215Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 216why, one step back216 for url in "/kw", "/dict":Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 217why, one step back217 rv = client.get(url)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 218why, one step back218 assert rv.mimetype == "application/json"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 219–223why, one step back219 assert flask.json.loads(rv.data) == d220221 def test_jsonify_arrays(self, app, client):222 """Test jsonify of lists and args unpacking."""223 l = [Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 224–232why, one step back224 0,225 42,226 3.14,227 "t",228 "hello",229 True,230 False,231 ["test list", 2, False],232 {"test": "dict"},Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 233–234why, one step back233 ]234Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 235why, one step back235 @app.route("/args_unpack")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 236–238why, one step back236 def return_args_unpack():237 return flask.jsonify(*l)238Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 239why, one step back239 @app.route("/array")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 240–242why, one step back240 def return_array():241 return flask.jsonify(l)242Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 243why, one step back243 for url in "/args_unpack", "/array":Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 244why, one step back244 rv = client.get(url)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 245why, one step back245 assert rv.mimetype == "application/json"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 246–251why, one step back246 assert flask.json.loads(rv.data) == l247248 def test_jsonify_date_types(self, app, client):249 """Test jsonify with datetime.date and datetime.datetime types."""250 test_dates = (251 datetime.datetime(1973, 3, 11, 6, 30, 45),Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 252why, one step back252 datetime.date(1975, 1, 5),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 253–255why, one step back253 )254255 for i, d in enumerate(test_dates):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 256why, one step back256 url = "/datetest{0}".format(i)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 257–258why, one step back257 app.add_url_rule(url, str(i), lambda val=d: flask.jsonify(x=val))258 rv = client.get(url)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 259–260why, one step back259 assert rv.mimetype == "application/json"260 assert flask.json.loads(rv.data)["x"] == http_date(d.timetuple())Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 261why, one step back261Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 262why, one step back262 @pytest.mark.parametrize("tz", (("UTC", 0), ("PST", -8), ("KST", 9)))Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 263–266why, one step back263 def test_jsonify_aware_datetimes(self, tz):264 """Test if aware datetime.datetime objects are converted into GMT."""265 tzinfo = FixedOffset(hours=tz[1], name=tz[0])266 dt = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=tzinfo)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 267why, one step back267 gmt = FixedOffset(hours=0, name="GMT")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 268–273why, one step back268 expected = dt.astimezone(gmt).strftime('"%a, %d %b %Y %H:%M:%S %Z"')269 assert flask.json.JSONEncoder().encode(dt) == expected270271 def test_jsonify_uuid_types(self, app, client):272 """Test jsonify with uuid.UUID types"""273Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 274–275why, one step back274 test_uuid = uuid.UUID(bytes=b"\xDE\xAD\xBE\xEF" * 4)275 url = "/uuid_test"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 276–279why, one step back276 app.add_url_rule(url, url, lambda: flask.jsonify(x=test_uuid))277278 rv = client.get(url)279Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 280why, one step back280 rv_x = flask.json.loads(rv.data)["x"]Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 281–285why, one step back281 assert rv_x == str(test_uuid)282 rv_uuid = uuid.UUID(rv_x)283 assert rv_uuid == test_uuid284285 def test_json_attr(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 286why, one step back286 @app.route("/add", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 287–288why, one step back287 def add():288 json = flask.request.get_json()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 289why, one step back289 return text_type(json["a"] + json["b"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 290why, one step back290Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 291–296why, one step back291 rv = client.post(292 "/add",293 data=flask.json.dumps({"a": 1, "b": 2}),294 content_type="application/json",295 )296 assert rv.data == b"3"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 297–299why, one step back297298 def test_template_escaping(self, app, req_ctx):299 render = flask.render_template_stringMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 300why, one step back300 rv = flask.json.htmlsafe_dumps("</script>")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 301–312why, one step back301 assert rv == u'"\\u003c/script\\u003e"'302 assert type(rv) == text_type303 rv = render('{{ "</script>"|tojson }}')304 assert rv == '"\\u003c/script\\u003e"'305 rv = render('{{ "<\0/script>"|tojson }}')306 assert rv == '"\\u003c\\u0000/script\\u003e"'307 rv = render('{{ "<!--<script>"|tojson }}')308 assert rv == '"\\u003c!--\\u003cscript\\u003e"'309 rv = render('{{ "&"|tojson }}')310 assert rv == '"\\u0026"'311 rv = render('{{ "\'"|tojson }}')312 assert rv == '"\\u0027"'Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 313–315why, one step back313 rv = render(314 "<a ng-data='{{ data|tojson }}'></a>", data={"x": ["foo", "bar", "baz'"]}315 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 316–325why, one step back316 assert rv == '<a ng-data=\'{"x": ["foo", "bar", "baz\\u0027"]}\'></a>'317318 def test_json_customization(self, app, client):319 class X(object):320 def __init__(self, val):321 self.val = val322323 class MyEncoder(flask.json.JSONEncoder):324 def default(self, o):325 if isinstance(o, X):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 326why, one step back326 return "<%d>" % o.valMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 327–330why, one step back327 return flask.json.JSONEncoder.default(self, o)328329 class MyDecoder(flask.json.JSONDecoder):330 def __init__(self, *args, **kwargs):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 331why, one step back331 kwargs.setdefault("object_hook", self.object_hook)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 332–334why, one step back332 flask.json.JSONDecoder.__init__(self, *args, **kwargs)333334 def object_hook(self, obj):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 335–336why, one step back335 if len(obj) == 1 and "_foo" in obj:336 return X(obj["_foo"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 337–341why, one step back337 return obj338339 app.json_encoder = MyEncoder340 app.json_decoder = MyDecoder341Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 342why, one step back342 @app.route("/", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 343why, one step back343 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 344why, one step back344 return flask.json.dumps(flask.request.get_json()["x"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 345why, one step back345Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 346–350why, one step back346 rv = client.post(347 "/",348 data=flask.json.dumps({"x": {"_foo": 42}}),349 content_type="application/json",350 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 351–360why, one step back351 assert rv.data == b'"<42>"'352353 def test_blueprint_json_customization(self, app, client):354 class X(object):355 def __init__(self, val):356 self.val = val357358 class MyEncoder(flask.json.JSONEncoder):359 def default(self, o):360 if isinstance(o, X):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 361why, one step back361 return "<%d>" % o.valMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 362–366why, one step back362363 return flask.json.JSONEncoder.default(self, o)364365 class MyDecoder(flask.json.JSONDecoder):366 def __init__(self, *args, **kwargs):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 367why, one step back367 kwargs.setdefault("object_hook", self.object_hook)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 368–370why, one step back368 flask.json.JSONDecoder.__init__(self, *args, **kwargs)369370 def object_hook(self, obj):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 371–372why, one step back371 if len(obj) == 1 and "_foo" in obj:372 return X(obj["_foo"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 373–375why, one step back373374 return obj375Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 376why, one step back376 bp = flask.Blueprint("bp", __name__)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 377–379why, one step back377 bp.json_encoder = MyEncoder378 bp.json_decoder = MyDecoder379Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 380why, one step back380 @bp.route("/bp", methods=["POST"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 381why, one step back381 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 382why, one step back382 return flask.json.dumps(flask.request.get_json()["x"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 383–385why, one step back383384 app.register_blueprint(bp)385Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 386–390why, one step back386 rv = client.post(387 "/bp",388 data=flask.json.dumps({"x": {"_foo": 42}}),389 content_type="application/json",390 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 391–394why, one step back391 assert rv.data == b'"<42>"'392393 def test_modified_url_encoding(self, app, client):394 class ModifiedRequest(flask.Request):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 395why, one step back395 url_charset = "euc-kr"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 396–397why, one step back396397 app.request_class = ModifiedRequestMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 398why, one step back398 app.url_map.charset = "euc-kr"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 399why, one step back399Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 400why, one step back400 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 401why, one step back401 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 402why, one step back402 return flask.request.args["foo"]Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 403why, one step back403Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 404why, one step back404 rv = client.get(u"/?foo=정상처리".encode("euc-kr"))Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 405why, one step back405 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 406why, one step back406 assert rv.data == u"정상처리".encode("utf-8")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 407why, one step back407Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 408why, one step back408 if not has_encoding("euc-kr"):Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 409–413why, one step back409 test_modified_url_encoding = None410411 def test_json_key_sorting(self, app, client):412 app.debug = True413Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 414–415why, one step back414 assert app.config["JSON_SORT_KEYS"] == True415 d = dict.fromkeys(range(20), "foo")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 416why, one step back416Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 417why, one step back417 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 418–420why, one step back418 def index():419 return flask.jsonify(values=d)420Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 421–422why, one step back421 rv = client.get("/")422 lines = [x.strip() for x in rv.data.strip().decode("utf-8").splitlines()]Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 423why, one step back423 sorted_by_str = [Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 424why, one step back424 "{",Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 425–445why, one step back425 '"values": {',426 '"0": "foo",',427 '"1": "foo",',428 '"10": "foo",',429 '"11": "foo",',430 '"12": "foo",',431 '"13": "foo",',432 '"14": "foo",',433 '"15": "foo",',434 '"16": "foo",',435 '"17": "foo",',436 '"18": "foo",',437 '"19": "foo",',438 '"2": "foo",',439 '"3": "foo",',440 '"4": "foo",',441 '"5": "foo",',442 '"6": "foo",',443 '"7": "foo",',444 '"8": "foo",',445 '"9": "foo"',Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 446–447why, one step back446 "}",447 "}",Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 448–449why, one step back448 ]449 sorted_by_int = [Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 450why, one step back450 "{",Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 451–471why, one step back451 '"values": {',452 '"0": "foo",',453 '"1": "foo",',454 '"2": "foo",',455 '"3": "foo",',456 '"4": "foo",',457 '"5": "foo",',458 '"6": "foo",',459 '"7": "foo",',460 '"8": "foo",',461 '"9": "foo",',462 '"10": "foo",',463 '"11": "foo",',464 '"12": "foo",',465 '"13": "foo",',466 '"14": "foo",',467 '"15": "foo",',468 '"16": "foo",',469 '"17": "foo",',470 '"18": "foo",',471 '"19": "foo"',Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 472–473why, one step back472 "}",473 "}",Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 474–483why, one step back474 ]475476 try:477 assert lines == sorted_by_int478 except AssertionError:479 assert lines == sorted_by_str480481482class TestSendfile(object):483 def test_send_file_regular(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 484why, one step back484 rv = flask.send_file("static/index.html")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 485why, one step back485 assert rv.direct_passthroughMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 486–487why, one step back486 assert rv.mimetype == "text/html"487 with app.open_resource("static/index.html") as f:Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 488–493why, one step back488 rv.direct_passthrough = False489 assert rv.data == f.read()490 rv.close()491492 def test_send_file_xsendfile(self, app, req_ctx, catch_deprecation_warnings):493 app.use_x_sendfile = TrueMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 494why, one step back494 rv = flask.send_file("static/index.html")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 495why, one step back495 assert rv.direct_passthroughMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 496–500why, one step back496 assert "x-sendfile" in rv.headers497 assert rv.headers["x-sendfile"] == os.path.join(498 app.root_path, "static/index.html"499 )500 assert rv.mimetype == "text/html"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 501–505why, one step back501 rv.close()502503 def test_send_file_last_modified(self, app, client):504 last_modified = datetime.datetime(1999, 1, 1)505Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 506why, one step back506 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 507why, one step back507 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 508–512why, one step back508 return flask.send_file(509 StringIO("party like it's"),510 last_modified=last_modified,511 mimetype="text/plain",512 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 513why, one step back513Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 514why, one step back514 rv = client.get("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 515–519why, one step back515 assert rv.last_modified == last_modified516517 def test_send_file_object_without_mimetype(self, app, req_ctx):518 with pytest.raises(ValueError) as excinfo:519 flask.send_file(StringIO("LOL"))Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 520–521why, one step back520 assert "Unable to infer MIME-type" in str(excinfo)521 assert "no filename is available" in str(excinfo)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 522why, one step back522Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 523why, one step back523 flask.send_file(StringIO("LOL"), attachment_filename="filename")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 524–525why, one step back524525 def test_send_file_object(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 526–527why, one step back526 with open(os.path.join(app.root_path, "static/index.html"), mode="rb") as f:527 rv = flask.send_file(f, mimetype="text/html")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 528why, one step back528 rv.direct_passthrough = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 529why, one step back529 with app.open_resource("static/index.html") as f:Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 530why, one step back530 assert rv.data == f.read()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 531why, one step back531 assert rv.mimetype == "text/html"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 532–535why, one step back532 rv.close()533534 app.use_x_sendfile = True535Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 536–539why, one step back536 with open(os.path.join(app.root_path, "static/index.html")) as f:537 rv = flask.send_file(f, mimetype="text/html")538 assert rv.mimetype == "text/html"539 assert "x-sendfile" not in rv.headersMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 540–542why, one step back540 rv.close()541542 app.use_x_sendfile = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 543–544why, one step back543 f = StringIO("Test")544 rv = flask.send_file(f, mimetype="application/octet-stream")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 545why, one step back545 rv.direct_passthrough = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 546–547why, one step back546 assert rv.data == b"Test"547 assert rv.mimetype == "application/octet-stream"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 548–556why, one step back548 rv.close()549550 class PyStringIO(object):551 def __init__(self, *args, **kwargs):552 self._io = StringIO(*args, **kwargs)553554 def __getattr__(self, name):555 return getattr(self._io, name)556Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 557–558why, one step back557 f = PyStringIO("Test")558 f.name = "test.txt"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 559–560why, one step back559 rv = flask.send_file(f, attachment_filename=f.name)560 rv.direct_passthrough = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 561–562why, one step back561 assert rv.data == b"Test"562 assert rv.mimetype == "text/plain"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 563–564why, one step back563 rv.close()564Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 565–566why, one step back565 f = StringIO("Test")566 rv = flask.send_file(f, mimetype="text/plain")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 567why, one step back567 rv.direct_passthrough = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 568–569why, one step back568 assert rv.data == b"Test"569 assert rv.mimetype == "text/plain"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 570–573why, one step back570 rv.close()571572 app.use_x_sendfile = True573Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 574–576why, one step back574 f = StringIO("Test")575 rv = flask.send_file(f, mimetype="text/html")576 assert "x-sendfile" not in rv.headersMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 577–578why, one step back577 rv.close()578Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
line 579why, one step back579 def test_send_file_pathlike(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 580why, one step back580 rv = flask.send_file(FakePath("static/index.html"))Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
line 581why, one step back581 assert rv.direct_passthroughMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 582–583why, one step back582 assert rv.mimetype == "text/html"583 with app.open_resource("static/index.html") as f:Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
lines 584–587why, one step back584 rv.direct_passthrough = False585 assert rv.data == f.read()586 rv.close()587Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 588why, one step back588 @pytest.mark.skipif(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 589–590why, one step back589 not callable(getattr(Range, "to_content_range_header", None)),590 reason="not implemented within werkzeug",Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 591–592why, one step back591 )592 def test_send_file_range_request(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 593why, one step back593 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 594why, one step back594 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 595why, one step back595 return flask.send_file("static/index.html", conditional=True)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 596why, one step back596Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 597why, one step back597 rv = client.get("/", headers={"Range": "bytes=4-15"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 598why, one step back598 assert rv.status_code == 206Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 599why, one step back599 with app.open_resource("static/index.html") as f:Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 600–602why, one step back600 assert rv.data == f.read()[4:16]601 rv.close()602Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 603why, one step back603 rv = client.get("/", headers={"Range": "bytes=4-"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 604why, one step back604 assert rv.status_code == 206Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 605why, one step back605 with app.open_resource("static/index.html") as f:Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 606–608why, one step back606 assert rv.data == f.read()[4:]607 rv.close()608Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 609why, one step back609 rv = client.get("/", headers={"Range": "bytes=4-1000"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 610why, one step back610 assert rv.status_code == 206Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 611why, one step back611 with app.open_resource("static/index.html") as f:Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 612–614why, one step back612 assert rv.data == f.read()[4:]613 rv.close()614Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 615why, one step back615 rv = client.get("/", headers={"Range": "bytes=-10"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 616why, one step back616 assert rv.status_code == 206Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 617why, one step back617 with app.open_resource("static/index.html") as f:Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 618–620why, one step back618 assert rv.data == f.read()[-10:]619 rv.close()620Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 621why, one step back621 rv = client.get("/", headers={"Range": "bytes=1000-"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 622–624why, one step back622 assert rv.status_code == 416623 rv.close()624Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 625why, one step back625 rv = client.get("/", headers={"Range": "bytes=-"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 626–628why, one step back626 assert rv.status_code == 416627 rv.close()628Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 629why, one step back629 rv = client.get("/", headers={"Range": "somethingsomething"})Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 630–632why, one step back630 assert rv.status_code == 416631 rv.close()632Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 633–635why, one step back633 last_modified = datetime.datetime.utcfromtimestamp(634 os.path.getmtime(os.path.join(app.root_path, "static/index.html"))635 ).replace(microsecond=0)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 636why, one step back636Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 637–639why, one step back637 rv = client.get(638 "/", headers={"Range": "bytes=4-15", "If-Range": http_date(last_modified)}639 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 640–642why, one step back640 assert rv.status_code == 206641 rv.close()642Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 643–649why, one step back643 rv = client.get(644 "/",645 headers={646 "Range": "bytes=4-15",647 "If-Range": http_date(datetime.datetime(1999, 1, 1)),648 },649 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 650why, one step back650 assert rv.status_code == 200Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d
lines 651–653why, one step back651 rv.close()652653 def test_send_file_range_request_bytesio(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 654why, one step back654 @app.route("/")Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d
line 655why, one step back655 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 656why, one step back656 file = io.BytesIO(b"somethingsomething")Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d
line 657why, one step back657 return flask.send_file(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 658why, one step back658 file, attachment_filename="filename", conditional=TrueMerge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d
lines 659–660why, one step back659 )660Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 661why, one step back661 rv = client.get("/", headers={"Range": "bytes=4-15"})Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d
line 662why, one step back662 assert rv.status_code == 206Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 663why, one step back663 assert rv.data == b"somethingsomething"[4:16]Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 664–665why, one step back664 rv.close()665Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa
line 666why, one step back666 @pytest.mark.skipif(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 667–668why, one step back667 not callable(getattr(Range, "to_content_range_header", None)),668 reason="not implemented within werkzeug",Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa
lines 669–673why, one step back669 )670 def test_send_file_range_request_xsendfile_invalid(self, app, client):671 # https://github.com/pallets/flask/issues/2526672 app.use_x_sendfile = True673Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 674why, one step back674 @app.route("/")Fix broken testAdrian Moennichbefore adoption777cc17
line 675why, one step back675 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 676why, one step back676 return flask.send_file("static/index.html", conditional=True)Fix broken testAdrian Moennichbefore adoption777cc17
line 677why, one step back677Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 678why, one step back678 rv = client.get("/", headers={"Range": "bytes=1000-"})Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa
lines 679–681why, one step back679 assert rv.status_code == 416680 rv.close()681Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 682why, one step back682 def test_attachment(self, app, req_ctx):Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa
lines 683–684why, one step back683 app = flask.Flask(__name__)684 with app.test_request_context():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 685–690why, one step back685 with open(os.path.join(app.root_path, "static/index.html")) as f:686 rv = flask.send_file(687 f, as_attachment=True, attachment_filename="index.html"688 )689 value, options = parse_options_header(rv.headers["Content-Disposition"])690 assert value == "attachment"Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa
line 691why, one step back691 rv.close()Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 692why, one step back692Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 693–700why, one step back693 with open(os.path.join(app.root_path, "static/index.html")) as f:694 rv = flask.send_file(695 f, as_attachment=True, attachment_filename="index.html"696 )697 value, options = parse_options_header(rv.headers["Content-Disposition"])698 assert value == "attachment"699 assert options["filename"] == "index.html"700 assert "filename*" not in rv.headers["Content-Disposition"]Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 701–702why, one step back701 rv.close()702Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 703–706why, one step back703 rv = flask.send_file("static/index.html", as_attachment=True)704 value, options = parse_options_header(rv.headers["Content-Disposition"])705 assert value == "attachment"706 assert options["filename"] == "index.html"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 707–708why, one step back707 rv.close()708Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 709–718why, one step back709 rv = flask.send_file(710 StringIO("Test"),711 as_attachment=True,712 attachment_filename="index.txt",713 add_etags=False,714 )715 assert rv.mimetype == "text/plain"716 value, options = parse_options_header(rv.headers["Content-Disposition"])717 assert value == "attachment"718 assert options["filename"] == "index.txt"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 719–720why, one step back719 rv.close()720Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 721–735why, one step back721 @pytest.mark.usefixtures("req_ctx")722 @pytest.mark.parametrize(723 ("filename", "ascii", "utf8"),724 (725 ("index.html", "index.html", False),726 (727 u"Ñandú/pingüino.txt",728 '"Nandu/pinguino.txt"',729 "%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt",730 ),731 (u"Vögel.txt", "Vogel.txt", "V%C3%B6gel.txt"),732 # Native string not marked as Unicode on Python 2733 ("tést.txt", "test.txt", "t%C3%A9st.txt"),734 ),735 )Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
line 736why, one step back736 def test_attachment_filename_encoding(self, filename, ascii, utf8):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 737–739why, one step back737 rv = flask.send_file(738 "static/index.html", as_attachment=True, attachment_filename=filename739 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 740why, one step back740 rv.close()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 741–742why, one step back741 content_disposition = rv.headers["Content-Disposition"]742 assert "filename=%s" % ascii in content_dispositionMerge branch '1.0-maintenance'ThiefMasterbefore adoption161c436
lines 743–746why, one step back743 if utf8:744 assert "filename*=UTF-8''" + utf8 in content_disposition745 else:746 assert "filename*=UTF-8''" not in content_dispositionMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 747–751why, one step back747748 def test_static_file(self, app, req_ctx):749 # default cache timeout is 12 hours750751 # Test with static file handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 752–753why, one step back752 rv = app.send_static_file("index.html")753 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 754–756why, one step back754 assert cc.max_age == 12 * 60 * 60755 rv.close()756 # Test again with direct use of send_file utility.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 757–758why, one step back757 rv = flask.send_file("static/index.html")758 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 759–760why, one step back759 assert cc.max_age == 12 * 60 * 60760 rv.close()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 761why, one step back761 app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 3600Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 762–763why, one step back762763 # Test with static file handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 764–765why, one step back764 rv = app.send_static_file("index.html")765 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 766–768why, one step back766 assert cc.max_age == 3600767 rv.close()768 # Test again with direct use of send_file utility.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 769–770why, one step back769 rv = flask.send_file("static/index.html")770 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 771–773why, one step back771 assert cc.max_age == 3600772 rv.close()773Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
line 774why, one step back774 # Test with static file handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 775–776why, one step back775 rv = app.send_static_file(FakePath("index.html"))776 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
lines 777–779why, one step back777 assert cc.max_age == 3600778 rv.close()779Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 780–786why, one step back780 class StaticFileApp(flask.Flask):781 def get_send_file_max_age(self, filename):782 return 10783784 app = StaticFileApp(__name__)785 with app.test_request_context():786 # Test with static file handler.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 787–788why, one step back787 rv = app.send_static_file("index.html")788 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 789–791why, one step back789 assert cc.max_age == 10790 rv.close()791 # Test again with direct use of send_file utility.Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 792–793why, one step back792 rv = flask.send_file("static/index.html")793 cc = parse_cache_control_header(rv.headers["Cache-Control"])Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 794–797why, one step back794 assert cc.max_age == 10795 rv.close()796797 def test_send_from_directory(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 798–801why, one step back798 app.root_path = os.path.join(799 os.path.dirname(__file__), "test_apps", "subdomaintestmodule"800 )801 rv = flask.send_from_directory("static", "hello.txt")Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
line 802why, one step back802 rv.direct_passthrough = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 803why, one step back803 assert rv.data.strip() == b"Hello Subdomain"Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca
lines 804–806why, one step back804 rv.close()805806 def test_send_from_directory_pathlike(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 807–810why, one step back807 app.root_path = os.path.join(808 os.path.dirname(__file__), "test_apps", "subdomaintestmodule"809 )810 rv = flask.send_from_directory(FakePath("static"), FakePath("hello.txt"))Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 811why, one step back811 rv.direct_passthrough = FalseMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 812why, one step back812 assert rv.data.strip() == b"Hello Subdomain"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 813–815why, one step back813 rv.close()814815 def test_send_from_directory_bad_request(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 816–818why, one step back816 app.root_path = os.path.join(817 os.path.dirname(__file__), "test_apps", "subdomaintestmodule"818 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 819–820why, one step back819820 with pytest.raises(BadRequest):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 821why, one step back821 flask.send_from_directory("static", "bad\x00")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 822–823why, one step back822823Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 824why, one step back824class TestUrlFor(object):Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 825why, one step back825 def test_url_for_with_anchor(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 826why, one step back826 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 827why, one step back827 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 828why, one step back828 return "42"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 829why, one step back829Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 830why, one step back830 assert flask.url_for("index", _anchor="x y") == "/#x%20y"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 831–832why, one step back831832 def test_url_for_with_scheme(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 833why, one step back833 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 834why, one step back834 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 835why, one step back835 return "42"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 836why, one step back836Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 837–840why, one step back837 assert (838 flask.url_for("index", _external=True, _scheme="https")839 == "https://localhost/"840 )Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 841–842why, one step back841842 def test_url_for_with_scheme_not_external(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 843why, one step back843 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 844why, one step back844 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 845why, one step back845 return "42"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 846why, one step back846Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 847why, one step back847 pytest.raises(ValueError, flask.url_for, "index", _scheme="https")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 848–849why, one step back848849 def test_url_for_with_alternating_schemes(self, app, req_ctx):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 850why, one step back850 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 851why, one step back851 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 852why, one step back852 return "42"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 853why, one step back853Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 854–859why, one step back854 assert flask.url_for("index", _external=True) == "http://localhost/"855 assert (856 flask.url_for("index", _external=True, _scheme="https")857 == "https://localhost/"858 )859 assert flask.url_for("index", _external=True) == "http://localhost/"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 860–866why, one step back860861 def test_url_with_method(self, app, req_ctx):862 from flask.views import MethodView863864 class MyView(MethodView):865 def get(self, id=None):866 if id is None:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 867–868why, one step back867 return "List"868 return "Get %d" % idMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 869–870why, one step back869870 def post(self):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 871why, one step back871 return "Create"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 872why, one step back872Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 873–876why, one step back873 myview = MyView.as_view("myview")874 app.add_url_rule("/myview/", methods=["GET"], view_func=myview)875 app.add_url_rule("/myview/<int:id>", methods=["GET"], view_func=myview)876 app.add_url_rule("/myview/create", methods=["POST"], view_func=myview)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 877why, one step back877Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 878–880why, one step back878 assert flask.url_for("myview", _method="GET") == "/myview/"879 assert flask.url_for("myview", id=42, _method="GET") == "/myview/42"880 assert flask.url_for("myview", _method="POST") == "/myview/create"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 881–894why, one step back881882883class TestNoImports(object):884 """Test Flasks are created without import.885886 Avoiding ``__import__`` helps create Flask instances where there are errors887 at import time. Those runtime errors will be apparent to the user soon888 enough, but tools which build Flask instances meta-programmatically benefit889 from a Flask which does not ``__import__``. Instead of importing to890 retrieve file paths or metadata on a module or package, use the pkgutil and891 imp modules in the Python standard library.892 """893894 def test_name_with_import_error(self, modules_tmpdir):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 895why, one step back895 modules_tmpdir.join("importerror.py").write("raise NotImplementedError()")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 896why, one step back896 try:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 897why, one step back897 flask.Flask("importerror")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 898why, one step back898 except NotImplementedError:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 899why, one step back899 assert False, "Flask(import_name) is importing import_name."Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 900–903why, one step back900901902class TestStreaming(object):903 def test_streaming_with_context(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 904why, one step back904 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 905–906why, one step back905 def index():906 def generate():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 907–909why, one step back907 yield "Hello "908 yield flask.request.args["name"]909 yield "!"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 910–912why, one step back910911 return flask.Response(flask.stream_with_context(generate()))912Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 913–914why, one step back913 rv = client.get("/?name=World")914 assert rv.data == b"Hello World!"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 915–916why, one step back915916 def test_streaming_with_context_as_decorator(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 917why, one step back917 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 918–921why, one step back918 def index():919 @flask.stream_with_context920 def generate(hello):921 yield helloMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 922–923why, one step back922 yield flask.request.args["name"]923 yield "!"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 924why, one step back924Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 925why, one step back925 return flask.Response(generate("Hello "))Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 926why, one step back926Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 927–928why, one step back927 rv = client.get("/?name=World")928 assert rv.data == b"Hello World!"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 929–947why, one step back929930 def test_streaming_with_context_and_custom_close(self, app, client):931 called = []932933 class Wrapper(object):934 def __init__(self, gen):935 self._gen = gen936937 def __iter__(self):938 return self939940 def close(self):941 called.append(42)942943 def __next__(self):944 return next(self._gen)945946 next = __next__947Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 948why, one step back948 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 949–950why, one step back949 def index():950 def generate():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 951–953why, one step back951 yield "Hello "952 yield flask.request.args["name"]953 yield "!"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 954why, one step back954Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 955why, one step back955 return flask.Response(flask.stream_with_context(Wrapper(generate())))Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 956why, one step back956Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 957–958why, one step back957 rv = client.get("/?name=World")958 assert rv.data == b"Hello World!"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 959–961why, one step back959 assert called == [42]960961 def test_stream_keeps_session(self, app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 962why, one step back962 @app.route("/")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 963why, one step back963 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 964why, one step back964 flask.session["test"] = "flask"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 965–967why, one step back965966 @flask.stream_with_context967 def gen():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 968why, one step back968 yield flask.session["test"]Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 969–971why, one step back969970 return flask.Response(gen())971Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 972–973why, one step back972 rv = client.get("/")973 assert rv.data == b"flask"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 974–979why, one step back974975976class TestSafeJoin(object):977 def test_safe_join(self):978 # Valid combinations of *args and expected joined paths.979 passing = (Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 980–985why, one step back980 (("a/b/c",), "a/b/c"),981 (("/", "a/", "b/", "c/"), "/a/b/c"),982 (("a", "b", "c"), "a/b/c"),983 (("/a", "b/c"), "/a/b/c"),984 (("a/b", "X/../c"), "a/b/c"),985 (("/a/b", "c/X/.."), "/a/b/c"),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 986why, one step back986 # If last path is '' add a slashMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 987why, one step back987 (("/a/b/c", ""), "/a/b/c/"),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 988why, one step back988 # Preserve dot slashMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 989–990why, one step back989 (("/a/b/c", "./"), "/a/b/c/."),990 (("a/b/c", "X/.."), "a/b/c/."),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 991why, one step back991 # Base directory is always considered safeMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 992–993why, one step back992 (("../", "a/b/c"), "../a/b/c"),993 (("/..",), "/.."),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 994–1002why, one step back994 )995996 for args, expected in passing:997 assert flask.safe_join(*args) == expected998999 def test_safe_join_exceptions(self):1000 # Should raise werkzeug.exceptions.NotFound on unsafe joins.1001 failing = (1002 # path.isabs and ``..'' checksMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1003–1005why, one step back1003 ("/a", "b", "/c"),1004 ("/a", "../b/c"),1005 ("/a", "..", "b/c"),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 1006why, one step back1006 # Boundaries violations after path normalizationMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1007–1009why, one step back1007 ("/a", "b/../b/../../c"),1008 ("/a", "b", "c/../.."),1009 ("/a", "b/../../c"),Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 1010–1016why, one step back1010 )10111012 for args in failing:1013 with pytest.raises(NotFound):1014 print(flask.safe_join(*args))10151016Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1017–1031why, one step back1017class TestHelpers(object):1018 @pytest.mark.parametrize(1019 "debug, expected_flag, expected_default_flag",1020 [1021 ("", False, False),1022 ("0", False, False),1023 ("False", False, False),1024 ("No", False, False),1025 ("True", True, True),1026 ],1027 )1028 def test_get_debug_flag(1029 self, monkeypatch, debug, expected_flag, expected_default_flag1030 ):1031 monkeypatch.setenv("FLASK_DEBUG", debug)Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 1032–1035why, one step back1032 if expected_flag is None:1033 assert get_debug_flag() is None1034 else:1035 assert get_debug_flag() == expected_flagAdd Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522
lines 1036–1037why, one step back1036 assert get_debug_flag() == expected_default_flag1037Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1038–1046why, one step back1038 @pytest.mark.parametrize(1039 "env, ref_env, debug",1040 [1041 ("", "production", False),1042 ("production", "production", False),1043 ("development", "development", True),1044 ("other", "other", False),1045 ],1046 )Add Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522
line 1047why, one step back1047 def test_get_env(self, monkeypatch, env, ref_env, debug):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1048why, one step back1048 monkeypatch.setenv("FLASK_ENV", env)Add Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522
lines 1049–1050why, one step back1049 assert get_debug_flag() == debug1050 assert get_env() == ref_envMerge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
lines 1051–1056why, one step back10511052 def test_make_response(self):1053 app = flask.Flask(__name__)1054 with app.test_request_context():1055 rv = flask.helpers.make_response()1056 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1057why, one step back1057 assert rv.mimetype == "text/html"Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 1058why, one step back1058Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 1059why, one step back1059 rv = flask.helpers.make_response("Hello")Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7
line 1060why, one step back1060 assert rv.status_code == 200Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 1061–1062why, one step back1061 assert rv.data == b"Hello"1062 assert rv.mimetype == "text/html"