|
|
@ -14,10 +14,10 @@ import sys |
|
|
|
import pkgutil |
|
|
|
import pkgutil |
|
|
|
import posixpath |
|
|
|
import posixpath |
|
|
|
import mimetypes |
|
|
|
import mimetypes |
|
|
|
from unicodedata import normalize |
|
|
|
|
|
|
|
from time import time |
|
|
|
from time import time |
|
|
|
from zlib import adler32 |
|
|
|
from zlib import adler32 |
|
|
|
from threading import RLock |
|
|
|
from threading import RLock |
|
|
|
|
|
|
|
import unicodedata |
|
|
|
from werkzeug.routing import BuildError |
|
|
|
from werkzeug.routing import BuildError |
|
|
|
from functools import update_wrapper |
|
|
|
from functools import update_wrapper |
|
|
|
|
|
|
|
|
|
|
@ -478,6 +478,11 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, |
|
|
|
.. versionchanged:: 0.12 |
|
|
|
.. versionchanged:: 0.12 |
|
|
|
The `attachment_filename` is preferred over `filename` for MIME-type |
|
|
|
The `attachment_filename` is preferred over `filename` for MIME-type |
|
|
|
detection. |
|
|
|
detection. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 0.13 |
|
|
|
|
|
|
|
UTF-8 filenames, as specified in `RFC 2231`_, are supported. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _RFC 2231: https://tools.ietf.org/html/rfc2231#section-4 |
|
|
|
|
|
|
|
|
|
|
|
:param filename_or_fp: the filename of the file to send in `latin-1`. |
|
|
|
:param filename_or_fp: the filename of the file to send in `latin-1`. |
|
|
|
This is relative to the :attr:`~Flask.root_path` |
|
|
|
This is relative to the :attr:`~Flask.root_path` |
|
|
@ -535,7 +540,10 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, |
|
|
|
if attachment_filename is None: |
|
|
|
if attachment_filename is None: |
|
|
|
raise TypeError('filename unavailable, required for ' |
|
|
|
raise TypeError('filename unavailable, required for ' |
|
|
|
'sending as attachment') |
|
|
|
'sending as attachment') |
|
|
|
normalized = normalize('NFKD', text_type(attachment_filename)) |
|
|
|
|
|
|
|
|
|
|
|
normalized = unicodedata.normalize( |
|
|
|
|
|
|
|
'NFKD', text_type(attachment_filename) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
normalized.encode('ascii') |
|
|
|
normalized.encode('ascii') |
|
|
@ -545,12 +553,9 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, |
|
|
|
'filename*': "UTF-8''%s" % url_quote(attachment_filename), |
|
|
|
'filename*': "UTF-8''%s" % url_quote(attachment_filename), |
|
|
|
} |
|
|
|
} |
|
|
|
else: |
|
|
|
else: |
|
|
|
filenames = { |
|
|
|
filenames = {'filename': attachment_filename} |
|
|
|
'filename': attachment_filename, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
headers.add('Content-Disposition', 'attachment', |
|
|
|
headers.add('Content-Disposition', 'attachment', **filenames) |
|
|
|
**filenames) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if current_app.use_x_sendfile and filename: |
|
|
|
if current_app.use_x_sendfile and filename: |
|
|
|
if file is not None: |
|
|
|
if file is not None: |
|
|
|