From 8d655a8dce0c5065303f9a75920d49bf1b9491c6 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Sat, 8 May 2021 12:24:23 +0200 Subject: [PATCH] Storage/S3: Move content disposition util to plugin It was in the indico core because flask did not expose it and we needed it there, but that's no longer the case (still not exposed though) so we include it here now. --- storage_s3/indico_storage_s3/storage.py | 4 +++- storage_s3/indico_storage_s3/util.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 storage_s3/indico_storage_s3/util.py diff --git a/storage_s3/indico_storage_s3/storage.py b/storage_s3/indico_storage_s3/storage.py index 7283afd..2f83e43 100644 --- a/storage_s3/indico_storage_s3/storage.py +++ b/storage_s3/indico_storage_s3/storage.py @@ -26,7 +26,9 @@ from indico.core.config import config from indico.core.storage import Storage, StorageError from indico.core.storage.backend import ReadOnlyStorageMixin, StorageReadOnlyError from indico.util.fs import get_file_checksum -from indico.web.flask.util import make_content_disposition_args, send_file +from indico.web.flask.util import send_file + +from indico_storage_s3.util import make_content_disposition_args s3_session_cache = threading.local() diff --git a/storage_s3/indico_storage_s3/util.py b/storage_s3/indico_storage_s3/util.py new file mode 100644 index 0000000..ce3f5c8 --- /dev/null +++ b/storage_s3/indico_storage_s3/util.py @@ -0,0 +1,22 @@ +# This file is part of the Indico plugins. +# Copyright (C) 2002 - 2021 CERN +# +# The Indico plugins are free software; you can redistribute +# them and/or modify them under the terms of the MIT License; +# see the LICENSE file for more details. + +import unicodedata + +from werkzeug.urls import url_quote + + +def make_content_disposition_args(attachment_filename): + try: + attachment_filename = attachment_filename.encode('ascii') + except UnicodeEncodeError: + return { + 'filename': unicodedata.normalize('NFKD', attachment_filename).encode('ascii', 'ignore'), + 'filename*': "UTF-8''%s" % url_quote(attachment_filename, safe=b''), + } + else: + return {'filename': attachment_filename}