Commit graph

901 commits

Author SHA1 Message Date
David Lord
09b49104f3
filename can be latin-1, not just ascii
only normalize basic name when utf-8 header is needed
ref #2223
2017-04-12 09:59:25 -07:00
David Lord
8b45009dbc Merge pull request #2223 from antlarr/master
Fix send_file's attachment_filename to work with non-ascii filenames
2017-04-08 10:54:20 -07:00
David Lord
c1973016ea
style cleanup
break out header parts in test
test for no filename* parameter for ascii header
2017-04-07 18:02:31 -07:00
Antonio Larrosa
d50a5db5ed Keep using only filename if it's valid ascii 2017-04-07 20:34:52 +02:00
jab
00d6e339ec Change Flask.__init__ to accept two new keyword arguments, host_matching and static_host. (#1560)
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.
2017-04-07 16:31:54 +02:00
asilversempirical
d76d68cd38 Update out of date jsonify documentation
https://github.com/pallets/flask/pull/2193 changed the conditions for when jsonify pretty prints, but this comment wasn't updated.
2017-04-06 11:26:01 -04:00
Markus Unterwaditzer
de555c82ce Merge branch '0.12-maintenance' 2017-03-31 18:44:33 +02:00
Markus Unterwaditzer
c935eaceaf Revert "Handle BaseExceptions (#2222)"
This reverts commit 1d4448abe3.
2017-03-31 18:44:14 +02:00
Markus Unterwaditzer
07a705888c Bump to dev version 2017-03-31 18:43:52 +02:00
Markus Unterwaditzer
a34d0e6878 Bump version number to 0.12.1 2017-03-31 18:43:36 +02:00
Diggory Blake
12c49c75fb Handle BaseExceptions 2017-03-31 18:40:46 +02:00
Diggory Blake
1d4448abe3 Handle BaseExceptions (#2222)
* Handle BaseExceptions

* Add test and changes

* Make test more idiomatic
2017-03-31 18:07:43 +02:00
Antonio Larrosa
bf023e7dc0 Remove unidecode dependency and use unicodedata instead
I found a way to remove the unidecode dependency without sacrificing
much by using unicodedata.normalize .
2017-03-30 17:32:21 +02:00
Antonio Larrosa
6ef45f30ab Fix previous commits to work with python 2 and python 3
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)
2017-03-24 20:05:01 +01:00
Antonio Larrosa
0049922f2e Fix send_file to work with non-ascii filenames
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
2017-03-23 17:30:48 +01:00
Ed Brannin
7a7a163ff1 shorten output when ImportError due to app bug.
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```
2017-03-21 15:22:15 -04:00
Sven-Hendrik Haase
ad42d88fb2 Remove useless pass 2017-03-16 14:42:16 +01:00
Sven-Hendrik Haase
5b7fd9ad88 Print a stacktrace on CLI error (closes #2208) 2017-03-16 14:37:58 +01:00
John Bodley
46e8427d81 Document run() host defaulting to SERVER_NAME 2017-03-11 18:59:34 +01:00
Hsiaoming Yang
a7f1a21c12 Don't rely on X-Requested-With for pretty print json response (#2193)
* 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
2017-03-07 10:09:46 +09:00
Static
f5adb61b28 Fix typos/grammar in docs (#2201) 2017-03-06 14:05:59 +01:00
Nick Ficano
eaba4a73aa Fix typo in file header (jsonimpl => json) 2017-02-15 17:55:56 +01:00
Armin Ronacher
c9b33d0e86 Convert Flask.run into a noop when run from the CLI 2017-01-29 12:26:52 +01:00
Raphael Deem
1636a4c410 use SERVER_NAME to set host and port in app.run() (#2152) 2017-01-17 13:22:16 -08:00
Kim Blomqvist
3fc8be5a4e Disable debug when FLASK_DEBUG=False (#2155)
Convert FLASK_DEBUG envvar to lower before test if in tuple
2017-01-17 07:15:51 -08:00
Markus Unterwaditzer
71c534d2c6 Merge branch '0.12-maintenance' 2016-12-30 22:46:26 +01:00
Paul Brown
0832e77b14 prevent NoAppException when ImportError occurs within imported module 2016-12-30 22:45:53 +01:00
Markus Unterwaditzer
f18fe15e6d Merge branch '0.12-maintenance' 2016-12-26 03:51:12 +01:00
Markus Unterwaditzer
789715adb9 Fix config.from_pyfile on Python 3 (#2123)
* Fix config.from_pyfile on Python 3

Fix #2118

* Support Python 2.6

* Fix tests on Python 2
2016-12-26 03:50:47 +01:00
Markus Unterwaditzer
8cd0b03bee Bump to dev 0.12.1 2016-12-25 16:35:30 +01:00
Markus Unterwaditzer
b2e0886f48 Bump to dev version 2016-12-21 21:22:26 +01:00
Markus Unterwaditzer
1042d9d23f Bump version number to 0.12 2016-12-21 21:22:08 +01:00
Jiri Kuncar
36425d5f91 Ignore cache on request.get_json(cache=False) call (#2089)
* 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)
2016-12-21 21:08:38 +01:00
Raphael Deem
0e79aba40d use dict instead of if/else logic (#2093) 2016-12-21 21:07:57 +01:00
Clenimar Filemon
77af942b98 Capitalize occurrences of 'flask' (#2067) 2016-11-01 18:52:32 -07:00
Martijn Pieters
de1652467b Remove busy-work. (#2072)
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.
2016-11-01 07:35:17 -07:00
Clenimar Filemon
cb30a3b562 Update docstring for errorhandler() (#2070) 2016-10-31 17:41:38 +01:00
Michael Recachinas
bd5e297aa9 Default environ (#2047)
* 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
2016-10-12 08:54:24 +02:00
Michael Recachinas
49ecc88d99 Remove -a/--app from Quickstart documentation (#2046)
* 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.
2016-10-01 18:45:22 +02:00
Joël Charles
7186a5aaf5 make use of range requests if available in werkzeug (#2031)
* make use of range requests if available in werkzeug

* different logic for testing werkzeug functionality
2016-09-26 12:43:46 +02:00
小明
f3d661de66 Fix unbound error (#2039) 2016-09-25 18:25:54 +02:00
Markus Unterwaditzer
01081dbe6c Avoid always-false statement
See https://github.com/pallets/flask/pull/1849/files#r79371299
2016-09-19 23:30:24 +02:00
Benjamin Dopplinger
dbeed24067 Fix typo in MethodView doc (#2028) 2016-09-18 20:24:46 -07:00
Bruno Thalmann
09fec941f4 Removed unused import. (#2026) 2016-09-18 14:10:00 +02:00
Armin Ronacher
83fd5b26b8 Merge branch 'feature/logger-propagation' 2016-09-12 21:54:41 +03:00
Armin Ronacher
a40489e0ce Merge pull request #2019 from pallets/bugfix/sendfile-error
Do not cause errors for unknown files for sendfile
2016-09-12 21:52:42 +03:00
Pablo Marti
2b47615998 Fix typo in docs
Also added one missing comma for readability
2016-09-12 08:41:09 +01:00
Armin Ronacher
1f0ca894a2 Killed now dead code 2016-09-11 16:57:43 +03:00
Armin Ronacher
9e41eca7f8 Merge pull request #2013 from pallets/bugfix/error-handler-error-handler
Corrected after response for error handlers
2016-09-10 03:36:29 +03:00
Armin Ronacher
a30951ec28 Do not error for unknown files if send_file sends an actual file 2016-09-10 03:33:53 +03:00