From 8572b059c55ebde3134b03f5a1fa78f29f69746e Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 22 Oct 2018 12:00:45 +0200 Subject: [PATCH 2/3] evalutils: add attachment(content, filename, content_type) helper (#27323) --- wcs/qommon/evalutils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wcs/qommon/evalutils.py b/wcs/qommon/evalutils.py index 98ce810a..9d2cd797 100644 --- a/wcs/qommon/evalutils.py +++ b/wcs/qommon/evalutils.py @@ -118,6 +118,19 @@ def age_in_seconds(born, today=None): today = make_datetime(today) return datetime_delta(today, born).total_seconds() + def add_days(date, count): '''Add the given number of days to date''' return make_date(date) + datetime.timedelta(days=count) + + +def attachment(content, filename='', content_type='application/octet-stream'): + '''Serialize content as an attachment''' + import base64 + + return { + 'filename': filename, + 'content_type': content_type, + 'b64_content': base64.b64encode(content), + } + -- 2.18.0