* be explicit about how tuples are unpacked
* allow bytes for status value
* allow Headers for headers value
* use TypeError instead of ValueError
* errors are more descriptive
* document that view must not return None
* update documentation about return values
* test more response types
* test error messages
closes#1676
This enables host_matching to be set properly by the time the constructor adds
the static route, and enables the static route to be properly associated with
the required host.
Previously, you could only enable host_matching once your app was already
instantiated (e.g. app.url_map.host_matching = True), but at that point
the constructor would have already added the static route without host matching
and an associated host, leaving the static route in a broken state.
Fixes#1559.
Also, parse_options_header seems to interpret filename* so we better
test the actual value used in the headers (and since it's valid
in any order, use a set to compare)
This commit implements https://tools.ietf.org/html/rfc2231#section-4 in
order to support sending unicode characters. Tested on both Firefox and
Chromium under Linux.
This adds unidecode as a dependency, which might be relaxed by using
.encode('latin-1', 'ignore') but wouldn't be as useful.
Also, added a test for the correct headers to be added.
Previously, using a filename parameter to send_file with unicode characters, it
failed with the next error since HTTP headers don't allow non latin-1 characters.
Error on request:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/werkzeug/serving.py", line 193, in run_wsgi
execute(self.server.app)
File "/usr/lib/python3.6/site-packages/werkzeug/serving.py", line 186, in execute
write(b'')
File "/usr/lib/python3.6/site-packages/werkzeug/serving.py", line 152, in write
self.send_header(key, value)
File "/usr/lib64/python3.6/http/server.py", line 509, in send_header
("%s: %s\r\n" % (keyword, value)).encode('latin-1', 'strict'))
UnicodeEncodeError: 'latin-1' codec can't encode character '\uff0f' in position 58: ordinal not in range(256)
Fixes#1286
Before:
```
C:\dev\tmp>py -2 -m flask run
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "c:\dev\sourcetree\flask\flask\__main__.py", line 15, in <module>
main(as_module=True)
File "c:\dev\sourcetree\flask\flask\cli.py", line 523, in main
cli.main(args=args, prog_name=name)
File "c:\dev\sourcetree\flask\flask\cli.py", line 383, in main
return AppGroup.main(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "C:\Python27\lib\site-packages\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Python27\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Python27\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "C:\Python27\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "C:\Python27\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\dev\sourcetree\flask\flask\cli.py", line 433, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "c:\dev\sourcetree\flask\flask\cli.py", line 153, in __init__
self._load_unlocked()
File "c:\dev\sourcetree\flask\flask\cli.py", line 177, in _load_unlocked
self._app = rv = self.loader()
File "c:\dev\sourcetree\flask\flask\cli.py", line 238, in load_app
rv = locate_app(self.app_import_path)
File "c:\dev\sourcetree\flask\flask\cli.py", line 91, in locate_app
__import__(module)
File "C:\dev\tmp\error.py", line 1, in <module>
import whatisthisidonteven
ImportError: No module named whatisthisidonteven
```
After:
```
C:\dev\tmp>py -2 -m flask run
Usage: python -m flask run [OPTIONS]
Error: There was an error trying to import the app (error):
Traceback (most recent call last):
File "c:\dev\sourcetree\flask\flask\cli.py", line 91, in locate_app
__import__(module)
File "C:\dev\tmp\error.py", line 1, in <module>
import whatisthisidonteven
ImportError: No module named whatisthisidonteven```
* Don't rely on X-Requested-With for pretty print json response
* Fix test cases for pretty print json patch
* Fix gramma error in docs for pretty print json config
* Add changelog for JSONIFY_PRETTYPRINT_REGULAR
* Test cache argument of Request.get_json
* Ignore cache on request.get_json(cache=False) call
Removes usage of `_cached_json` property when `get_json` is called with
disabled cache argument. (closes#2087)
It is entirely sufficient to walk the MRO of the exception class, no need to check for classes re-appearing later on, no need to add the MRO of any superclass.
* Python refuses point-blank to create a class with a circular MRO.
* All classes in a superclass MRO *already* appear in the MRO of the derived type. Re-adding the contents of a superclass MRO is doing double work.
* Add init to FlaskClient
This addresses #1467. The init in the subclass
can now take in `environ_base`, which will then get
passed to `make_test_environ_builder` and to
`EnvironBuilder` via keyword args.
This should provide the default environment capability
on `app.test_client()` init.
* Add kwarg `environ_base` to `make_test_environ_builder` call
This change now passes `environ_base` from either
`kwargs` in `FlaskClient.open` or `FlaskClient.environ_base`
if passed into the init.
* Fix assignment reference typo
* Add default `environ_base` to `FlaskClient.__init__`
* Set default kwargs for `environ_base` in `FlaskClient.open`
* Remove specific environ_base kwarg since its in kwargs
* Add docstring to FlaskClient detailing environ_base
* Document app.test_client default environ in CHANGES
* Re-word environ_base changes in FlaskClient docstring
* Add client.environ_base tests
* Mention preset default environ in `app.test_client`
* Add versionchanged directive to docstring in FlaskClient
* Remove `-a/--app` from Quickstart documentation
As mentioned in #2009, simplifying the CLI saw the removal of the `-a/--app` flag. Therefore, the only way to specify the module to import is by setting `FLASK_APP`.
* Remove misleading `either` from CLI help
The CLI help details how to run the application, but still uses the phrasing "either through the `FLASK_APP`...". This likely is an artifact from when `-a/--app` was still present in the CLI.