Skip to content
Myr

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 file

Take 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 back
1# -*- coding: utf-8 -*-
2"""3 tests.helpers4 ~~~~~~~~~~~~~~~~~~~~~~~56 Various helpers.7

Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c

line 8why, one step back
8 :copyright: © 2010 by the Pallets team.

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 9–11why, one step back
9 :license: BSD, see LICENSE for more details.
10"""11

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 12why, one step back
12import datetime

Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d

line 13why, one step back
13import io

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 14–16why, one step back
14import os
15import uuid16

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 17why, one step back
17import pytest

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 18–19why, one step back
18from werkzeug.datastructures import Range
19from werkzeug.exceptions import BadRequest, NotFound

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 20why, one step back
20from werkzeug.http import http_date, parse_cache_control_header, parse_options_header

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 21–22why, one step back
21
22import flask

Merge pull request #2691 from pallets/json-encodingDavid Lordbefore adoption465b48e

line 23why, one step back
23from flask import json

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 24why, one step back
24from flask._compat import StringIO, text_type

Add Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522

line 25why, one step back
25from flask.helpers import get_debug_flag, get_env

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 26–30why, one step back
26
2728def has_encoding(name):29 try:30 import codecs

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 31why, one step back
31

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 32–37why, one step back
32 codecs.lookup(name)
33 return True34 except LookupError:35 return False3637

Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca

lines 38–43why, one step back
38class 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 back
44

Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca

lines 45–51why, one step back
45 def __init__(self, path):
46 self.path = path4748 def __fspath__(self):49 return self.path5051

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 52–73why, one step back
52class 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 back
74 @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 back
90 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) == value94

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 95why, one step back
95 def test_ignore_cached_json(self, app):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 96–98why, one step back
96 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 back
99 assert flask.request.get_json(silent=True, cache=True) is None
100 with pytest.raises(BadRequest):101 flask.request.get_json(silent=False, cache=False)102

Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698

lines 103–104why, one step back
103 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 back
105 "/", 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 back
107 assert flask.request.get_json(silent=True) is None
108 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 back
112 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 back
113 silent_rv = flask.request.get_json(silent=True)
114 normal_rv = flask.request.get_json(silent=False)115 assert silent_rv is normal_rv

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 116why, one step back
116 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 back
117

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 118–122why, one step back
118 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"] = False

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 123why, one step back
123

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 124why, one step back
124 @app.route("/json", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 125–128why, one step back
125 def post_json():
126 flask.request.get_json()127 return None128

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 129why, one step back
129 rv = client.post("/json", data=None, content_type="application/json")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 130why, one step back
130 assert rv.status_code == 400

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 131why, one step back
131 assert b"Failed to decode JSON object" in rv.data

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 132why, one step back
132

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 133–137why, one step back
133 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"] = False

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 138why, one step back
138

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 139why, one step back
139 @app.route("/json", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 140–143why, one step back
140 def post_json():
141 flask.request.get_json()142 return None143

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 144why, one step back
144 rv = client.post("/json", data=None, content_type="application/json")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 145why, one step back
145 assert rv.status_code == 400

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 146why, one step back
146 assert b"Failed to decode JSON object" not in rv.data

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 147–148why, one step back
147
148 def test_json_bad_requests(self, app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 149why, one step back
149 @app.route("/json", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 150–152why, one step back
150 def return_json():
151 return flask.jsonify(foo=text_type(flask.request.get_json()))152

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 153why, one step back
153 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 back
154 assert rv.status_code == 400
155156 def test_json_custom_mimetypes(self, app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 157why, one step back
157 @app.route("/json", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 158–160why, one step back
158 def return_json():
159 return flask.request.get_json()160

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 161–162why, one step back
161 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 back
163

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 164–166why, one step back
164 @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 back
167 def test_json_as_unicode(self, test_value, expected, app, app_ctx):
168

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 169–170why, one step back
169 app.config["JSON_AS_ASCII"] = test_value
170 rv = flask.json.dumps(u"\N{SNOWMAN}")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 171–173why, one step back
171 assert rv == expected
172173 def test_json_dump_to_file(self, app, app_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 174why, one step back
174 test_data = {"name": "Flask"}

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 175–181why, one step back
175 out = StringIO()
176177 flask.json.dump(test_data, out)178 out.seek(0)179 rv = flask.json.load(out)180 assert rv == test_data181

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 182–184why, one step back
182 @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 back
185 def test_jsonify_basic_types(self, test_value, app, client):
186 """Test jsonify with basic types."""187

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 188why, one step back
188 url = "/jsonify_basic_types"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 189–190why, one step back
189 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 back
191 assert rv.mimetype == "application/json"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 192–195why, one step back
192 assert flask.json.loads(rv.data) == test_value
193194 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 back
196 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 back
207

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 208why, one step back
208 @app.route("/kw")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 209–211why, one step back
209 def return_kwargs():
210 return flask.jsonify(**d)211

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 212why, one step back
212 @app.route("/dict")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 213–215why, one step back
213 def return_dict():
214 return flask.jsonify(d)215

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 216why, one step back
216 for url in "/kw", "/dict":

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 217why, one step back
217 rv = client.get(url)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 218why, one step back
218 assert rv.mimetype == "application/json"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 219–223why, one step back
219 assert flask.json.loads(rv.data) == d
220221 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 back
224 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 back
233 ]
234

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 235why, one step back
235 @app.route("/args_unpack")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 236–238why, one step back
236 def return_args_unpack():
237 return flask.jsonify(*l)238

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 239why, one step back
239 @app.route("/array")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 240–242why, one step back
240 def return_array():
241 return flask.jsonify(l)242

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 243why, one step back
243 for url in "/args_unpack", "/array":

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 244why, one step back
244 rv = client.get(url)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 245why, one step back
245 assert rv.mimetype == "application/json"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 246–251why, one step back
246 assert flask.json.loads(rv.data) == l
247248 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 back
252 datetime.date(1975, 1, 5),

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 253–255why, one step back
253 )
254255 for i, d in enumerate(test_dates):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 256why, one step back
256 url = "/datetest{0}".format(i)

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 257–258why, one step back
257 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 back
259 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 back
261

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 262why, one step back
262 @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 back
263 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 back
267 gmt = FixedOffset(hours=0, name="GMT")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 268–273why, one step back
268 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"""273

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 274–275why, one step back
274 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 back
276 app.add_url_rule(url, url, lambda: flask.jsonify(x=test_uuid))
277278 rv = client.get(url)279

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 280why, one step back
280 rv_x = flask.json.loads(rv.data)["x"]

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 281–285why, one step back
281 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 back
286 @app.route("/add", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 287–288why, one step back
287 def add():
288 json = flask.request.get_json()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 289why, one step back
289 return text_type(json["a"] + json["b"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 290why, one step back
290

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 291–296why, one step back
291 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 back
297
298 def test_template_escaping(self, app, req_ctx):299 render = flask.render_template_string

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 300why, one step back
300 rv = flask.json.htmlsafe_dumps("</script>")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 301–312why, one step back
301 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 back
313 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 back
316 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 back
326 return "<%d>" % o.val

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 327–330why, one step back
327 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 back
331 kwargs.setdefault("object_hook", self.object_hook)

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 332–334why, one step back
332 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 back
335 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 back
337 return obj
338339 app.json_encoder = MyEncoder340 app.json_decoder = MyDecoder341

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 342why, one step back
342 @app.route("/", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 343why, one step back
343 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 344why, one step back
344 return flask.json.dumps(flask.request.get_json()["x"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 345why, one step back
345

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 346–350why, one step back
346 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 back
351 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 back
361 return "<%d>" % o.val

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 362–366why, one step back
362
363 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 back
367 kwargs.setdefault("object_hook", self.object_hook)

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 368–370why, one step back
368 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 back
371 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 back
373
374 return obj375

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 376why, one step back
376 bp = flask.Blueprint("bp", __name__)

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 377–379why, one step back
377 bp.json_encoder = MyEncoder
378 bp.json_decoder = MyDecoder379

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 380why, one step back
380 @bp.route("/bp", methods=["POST"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 381why, one step back
381 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 382why, one step back
382 return flask.json.dumps(flask.request.get_json()["x"])

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 383–385why, one step back
383
384 app.register_blueprint(bp)385

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 386–390why, one step back
386 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 back
391 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 back
395 url_charset = "euc-kr"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 396–397why, one step back
396
397 app.request_class = ModifiedRequest

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 398why, one step back
398 app.url_map.charset = "euc-kr"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 399why, one step back
399

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 400why, one step back
400 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 401why, one step back
401 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 402why, one step back
402 return flask.request.args["foo"]

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 403why, one step back
403

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 404why, one step back
404 rv = client.get(u"/?foo=정상처리".encode("euc-kr"))

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 405why, one step back
405 assert rv.status_code == 200

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 406why, one step back
406 assert rv.data == u"정상처리".encode("utf-8")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 407why, one step back
407

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 408why, one step back
408 if not has_encoding("euc-kr"):

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 409–413why, one step back
409 test_modified_url_encoding = None
410411 def test_json_key_sorting(self, app, client):412 app.debug = True413

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 414–415why, one step back
414 assert app.config["JSON_SORT_KEYS"] == True
415 d = dict.fromkeys(range(20), "foo")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 416why, one step back
416

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 417why, one step back
417 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 418–420why, one step back
418 def index():
419 return flask.jsonify(values=d)420

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 421–422why, one step back
421 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 back
423 sorted_by_str = [

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 424why, one step back
424 "{",

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 425–445why, one step back
425 '"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 back
446 "}",
447 "}",

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 448–449why, one step back
448 ]
449 sorted_by_int = [

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 450why, one step back
450 "{",

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 451–471why, one step back
451 '"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 back
472 "}",
473 "}",

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 474–483why, one step back
474 ]
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 back
484 rv = flask.send_file("static/index.html")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 485why, one step back
485 assert rv.direct_passthrough

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 486–487why, one step back
486 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 back
488 rv.direct_passthrough = False
489 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 = True

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 494why, one step back
494 rv = flask.send_file("static/index.html")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 495why, one step back
495 assert rv.direct_passthrough

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 496–500why, one step back
496 assert "x-sendfile" in rv.headers
497 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 back
501 rv.close()
502503 def test_send_file_last_modified(self, app, client):504 last_modified = datetime.datetime(1999, 1, 1)505

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 506why, one step back
506 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 507why, one step back
507 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 508–512why, one step back
508 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 back
513

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 514why, one step back
514 rv = client.get("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 515–519why, one step back
515 assert rv.last_modified == last_modified
516517 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 back
520 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 back
522

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 523why, one step back
523 flask.send_file(StringIO("LOL"), attachment_filename="filename")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 524–525why, one step back
524
525 def test_send_file_object(self, app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 526–527why, one step back
526 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 back
528 rv.direct_passthrough = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 529why, one step back
529 with app.open_resource("static/index.html") as f:

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 530why, one step back
530 assert rv.data == f.read()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 531why, one step back
531 assert rv.mimetype == "text/html"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 532–535why, one step back
532 rv.close()
533534 app.use_x_sendfile = True535

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 536–539why, one step back
536 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.headers

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 540–542why, one step back
540 rv.close()
541542 app.use_x_sendfile = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 543–544why, one step back
543 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 back
545 rv.direct_passthrough = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 546–547why, one step back
546 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 back
548 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)556

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 557–558why, one step back
557 f = PyStringIO("Test")
558 f.name = "test.txt"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 559–560why, one step back
559 rv = flask.send_file(f, attachment_filename=f.name)
560 rv.direct_passthrough = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 561–562why, one step back
561 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 back
563 rv.close()
564

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 565–566why, one step back
565 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 back
567 rv.direct_passthrough = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 568–569why, one step back
568 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 back
570 rv.close()
571572 app.use_x_sendfile = True573

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 574–576why, one step back
574 f = StringIO("Test")
575 rv = flask.send_file(f, mimetype="text/html")576 assert "x-sendfile" not in rv.headers

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 577–578why, one step back
577 rv.close()
578

Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca

line 579why, one step back
579 def test_send_file_pathlike(self, app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 580why, one step back
580 rv = flask.send_file(FakePath("static/index.html"))

Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca

line 581why, one step back
581 assert rv.direct_passthrough

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 582–583why, one step back
582 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 back
584 rv.direct_passthrough = False
585 assert rv.data == f.read()586 rv.close()587

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 588why, one step back
588 @pytest.mark.skipif(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 589–590why, one step back
589 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 back
591 )
592 def test_send_file_range_request(self, app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 593why, one step back
593 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 594why, one step back
594 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 595why, one step back
595 return flask.send_file("static/index.html", conditional=True)

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 596why, one step back
596

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 597why, one step back
597 rv = client.get("/", headers={"Range": "bytes=4-15"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 598why, one step back
598 assert rv.status_code == 206

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 599why, one step back
599 with app.open_resource("static/index.html") as f:

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 600–602why, one step back
600 assert rv.data == f.read()[4:16]
601 rv.close()602

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 603why, one step back
603 rv = client.get("/", headers={"Range": "bytes=4-"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 604why, one step back
604 assert rv.status_code == 206

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 605why, one step back
605 with app.open_resource("static/index.html") as f:

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 606–608why, one step back
606 assert rv.data == f.read()[4:]
607 rv.close()608

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 609why, one step back
609 rv = client.get("/", headers={"Range": "bytes=4-1000"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 610why, one step back
610 assert rv.status_code == 206

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 611why, one step back
611 with app.open_resource("static/index.html") as f:

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 612–614why, one step back
612 assert rv.data == f.read()[4:]
613 rv.close()614

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 615why, one step back
615 rv = client.get("/", headers={"Range": "bytes=-10"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 616why, one step back
616 assert rv.status_code == 206

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 617why, one step back
617 with app.open_resource("static/index.html") as f:

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 618–620why, one step back
618 assert rv.data == f.read()[-10:]
619 rv.close()620

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 621why, one step back
621 rv = client.get("/", headers={"Range": "bytes=1000-"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 622–624why, one step back
622 assert rv.status_code == 416
623 rv.close()624

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 625why, one step back
625 rv = client.get("/", headers={"Range": "bytes=-"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 626–628why, one step back
626 assert rv.status_code == 416
627 rv.close()628

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 629why, one step back
629 rv = client.get("/", headers={"Range": "somethingsomething"})

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 630–632why, one step back
630 assert rv.status_code == 416
631 rv.close()632

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 633–635why, one step back
633 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 back
636

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 637–639why, one step back
637 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 back
640 assert rv.status_code == 206
641 rv.close()642

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 643–649why, one step back
643 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 back
650 assert rv.status_code == 200

Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d

lines 651–653why, one step back
651 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 back
654 @app.route("/")

Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d

line 655why, one step back
655 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 656why, one step back
656 file = io.BytesIO(b"somethingsomething")

Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d

line 657why, one step back
657 return flask.send_file(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 658why, one step back
658 file, attachment_filename="filename", conditional=True

Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d

lines 659–660why, one step back
659 )
660

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 661why, one step back
661 rv = client.get("/", headers={"Range": "bytes=4-15"})

Merge pull request #2957 from IgnasiBosch/2943-bytesio-partial-contentDavid Lordbefore adoption4f32c6d

line 662why, one step back
662 assert rv.status_code == 206

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 663why, one step back
663 assert rv.data == b"somethingsomething"[4:16]

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 664–665why, one step back
664 rv.close()
665

Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa

line 666why, one step back
666 @pytest.mark.skipif(

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 667–668why, one step back
667 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 back
669 )
670 def test_send_file_range_request_xsendfile_invalid(self, app, client):671 # https://github.com/pallets/flask/issues/2526672 app.use_x_sendfile = True673

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 674why, one step back
674 @app.route("/")

Fix broken testAdrian Moennichbefore adoption777cc17

line 675why, one step back
675 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 676why, one step back
676 return flask.send_file("static/index.html", conditional=True)

Fix broken testAdrian Moennichbefore adoption777cc17

line 677why, one step back
677

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 678why, one step back
678 rv = client.get("/", headers={"Range": "bytes=1000-"})

Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa

lines 679–681why, one step back
679 assert rv.status_code == 416
680 rv.close()681

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 682why, one step back
682 def test_attachment(self, app, req_ctx):

Merge remote-tracking branch 'upstream/0.12-maintenance'Adrian Moennichbefore adoptioneb1c2fa

lines 683–684why, one step back
683 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 back
685 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 back
691 rv.close()

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 692why, one step back
692

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 693–700why, one step back
693 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 back
701 rv.close()
702

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 703–706why, one step back
703 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 back
707 rv.close()
708

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 709–718why, one step back
709 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 back
719 rv.close()
720

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 721–735why, one step back
721 @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 back
736 def test_attachment_filename_encoding(self, filename, ascii, utf8):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 737–739why, one step back
737 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 back
740 rv.close()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 741–742why, one step back
741 content_disposition = rv.headers["Content-Disposition"]
742 assert "filename=%s" % ascii in content_disposition

Merge branch '1.0-maintenance'ThiefMasterbefore adoption161c436

lines 743–746why, one step back
743 if utf8:
744 assert "filename*=UTF-8''" + utf8 in content_disposition745 else:746 assert "filename*=UTF-8''" not in content_disposition

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 747–751why, one step back
747
748 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 back
752 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 back
754 assert cc.max_age == 12 * 60 * 60
755 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 back
757 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 back
759 assert cc.max_age == 12 * 60 * 60
760 rv.close()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 761why, one step back
761 app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 3600

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 762–763why, one step back
762
763 # Test with static file handler.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 764–765why, one step back
764 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 back
766 assert cc.max_age == 3600
767 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 back
769 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 back
771 assert cc.max_age == 3600
772 rv.close()773

Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca

line 774why, one step back
774 # Test with static file handler.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 775–776why, one step back
775 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 back
777 assert cc.max_age == 3600
778 rv.close()779

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 780–786why, one step back
780 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 back
787 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 back
789 assert cc.max_age == 10
790 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 back
792 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 back
794 assert cc.max_age == 10
795 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 back
798 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 back
802 rv.direct_passthrough = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 803why, one step back
803 assert rv.data.strip() == b"Hello Subdomain"

Merge pull request #3059 from mattrobenolt/fspathDavid Lordbefore adoption4d37aca

lines 804–806why, one step back
804 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 back
807 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 back
811 rv.direct_passthrough = False

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 812why, one step back
812 assert rv.data.strip() == b"Hello Subdomain"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 813–815why, one step back
813 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 back
816 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 back
819
820 with pytest.raises(BadRequest):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 821why, one step back
821 flask.send_from_directory("static", "bad\x00")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 822–823why, one step back
822
823

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 824why, one step back
824class TestUrlFor(object):

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 825why, one step back
825 def test_url_for_with_anchor(self, app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 826why, one step back
826 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 827why, one step back
827 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 828why, one step back
828 return "42"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 829why, one step back
829

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 830why, one step back
830 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 back
831
832 def test_url_for_with_scheme(self, app, req_ctx):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 833why, one step back
833 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 834why, one step back
834 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 835why, one step back
835 return "42"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 836why, one step back
836

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 837–840why, one step back
837 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 back
841
842 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 back
843 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 844why, one step back
844 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 845why, one step back
845 return "42"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 846why, one step back
846

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 847why, one step back
847 pytest.raises(ValueError, flask.url_for, "index", _scheme="https")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 848–849why, one step back
848
849 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 back
850 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 851why, one step back
851 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 852why, one step back
852 return "42"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 853why, one step back
853

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 854–859why, one step back
854 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 back
860
861 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 back
867 return "List"
868 return "Get %d" % id

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 869–870why, one step back
869
870 def post(self):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 871why, one step back
871 return "Create"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 872why, one step back
872

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 873–876why, one step back
873 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 back
877

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 878–880why, one step back
878 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 back
881
882883class 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 back
895 modules_tmpdir.join("importerror.py").write("raise NotImplementedError()")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 896why, one step back
896 try:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 897why, one step back
897 flask.Flask("importerror")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 898why, one step back
898 except NotImplementedError:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 899why, one step back
899 assert False, "Flask(import_name) is importing import_name."

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 900–903why, one step back
900
901902class 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 back
904 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 905–906why, one step back
905 def index():
906 def generate():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 907–909why, one step back
907 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 back
910
911 return flask.Response(flask.stream_with_context(generate()))912

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 913–914why, one step back
913 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 back
915
916 def test_streaming_with_context_as_decorator(self, app, client):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 917why, one step back
917 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 918–921why, one step back
918 def index():
919 @flask.stream_with_context920 def generate(hello):921 yield hello

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 922–923why, one step back
922 yield flask.request.args["name"]
923 yield "!"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 924why, one step back
924

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 925why, one step back
925 return flask.Response(generate("Hello "))

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 926why, one step back
926

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 927–928why, one step back
927 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 back
929
930 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__947

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 948why, one step back
948 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 949–950why, one step back
949 def index():
950 def generate():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 951–953why, one step back
951 yield "Hello "
952 yield flask.request.args["name"]953 yield "!"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 954why, one step back
954

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 955why, one step back
955 return flask.Response(flask.stream_with_context(Wrapper(generate())))

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 956why, one step back
956

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 957–958why, one step back
957 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 back
959 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 back
962 @app.route("/")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 963why, one step back
963 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 964why, one step back
964 flask.session["test"] = "flask"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 965–967why, one step back
965
966 @flask.stream_with_context967 def gen():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 968why, one step back
968 yield flask.session["test"]

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 969–971why, one step back
969
970 return flask.Response(gen())971

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 972–973why, one step back
972 rv = client.get("/")
973 assert rv.data == b"flask"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 974–979why, one step back
974
975976class 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 back
980 (("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 back
986 # If last path is '' add a slash

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 987why, one step back
987 (("/a/b/c", ""), "/a/b/c/"),

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 988why, one step back
988 # Preserve dot slash

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 989–990why, one step back
989 (("/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 back
991 # Base directory is always considered safe

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 992–993why, one step back
992 (("../", "a/b/c"), "../a/b/c"),
993 (("/..",), "/.."),

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 994–1002why, one step back
994 )
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 ``..'' checks

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1003–1005why, one step back
1003 ("/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 back
1006 # Boundaries violations after path normalization

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1007–1009why, one step back
1007 ("/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 back
1010 )
10111012 for args in failing:1013 with pytest.raises(NotFound):1014 print(flask.safe_join(*args))10151016

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1017–1031why, one step back
1017class 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 back
1032 if expected_flag is None:
1033 assert get_debug_flag() is None1034 else:1035 assert get_debug_flag() == expected_flag

Add Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522

lines 1036–1037why, one step back
1036 assert get_debug_flag() == expected_default_flag
1037

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1038–1046why, one step back
1038 @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 back
1047 def test_get_env(self, monkeypatch, env, ref_env, debug):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1048why, one step back
1048 monkeypatch.setenv("FLASK_ENV", env)

Add Support for FLASK_ENV (#2570)Armin Ronacherbefore adoption2433522

lines 1049–1050why, one step back
1049 assert get_debug_flag() == debug
1050 assert get_env() == ref_env

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

lines 1051–1056why, one step back
1051
1052 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 == 200

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1057why, one step back
1057 assert rv.mimetype == "text/html"

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 1058why, one step back
1058

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 1059why, one step back
1059 rv = flask.helpers.make_response("Hello")

Merge pull request #2395 from davidism/remove-extDavid Lordbefore adoptionbce8ec7

line 1060why, one step back
1060 assert rv.status_code == 200

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 1061–1062why, one step back
1061 assert rv.data == b"Hello"
1062 assert rv.mimetype == "text/html"