From 05ccaf676e3714d98ecfd888b24a36e29483bcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 16 Dec 2015 09:58:10 +0100 Subject: [PATCH] workflows: encode model file in base64 in import/export (#9350) --- tests/test_workflow_import.py | 4 ++-- wcs/wf/export_to_model.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_workflow_import.py b/tests/test_workflow_import.py index 063c05f..6815f3a 100644 --- a/tests/test_workflow_import.py +++ b/tests/test_workflow_import.py @@ -214,9 +214,9 @@ def test_export_to_model_action(): export_to = ExportToModel() export_to.label = 'test' - upload = Upload('/foo/bar', content_type='text/rtf') + upload = Upload('/foo/bar', content_type='application/vnd.oasis.opendocument.text') upload.fp = StringIO.StringIO() - upload.fp.write('HELLO WORLD') + upload.fp.write('''PK\x03\x04\x14\x00\x00\x08\x00\x00\'l\x8eG^\xc62\x0c\'\x00''') upload.fp.seek(0) export_to.model_file = UploadedFile(publisher.WcsPublisher.APP_DIR, None, upload) st1.items.append(export_to) diff --git a/wcs/wf/export_to_model.py b/wcs/wf/export_to_model.py index f0ec887..e01fcfb 100644 --- a/wcs/wf/export_to_model.py +++ b/wcs/wf/export_to_model.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, see . +import base64 from StringIO import StringIO from xml.etree import ElementTree as ET import zipfile @@ -331,14 +332,18 @@ class ExportToModel(WorkflowStatusItem): el = ET.SubElement(xml_item, 'model_file') ET.SubElement(el, 'base_filename').text = self.model_file.base_filename ET.SubElement(el, 'content_type').text = self.model_file.content_type - ET.SubElement(el, 'content').text = self.model_file.get_file().read() + ET.SubElement(el, 'b64_content').text = base64.encodestring( + self.model_file.get_file().read()) def model_file_init_with_xml(self, elem, charset, include_id=False): if elem is None: return base_filename = elem.find('base_filename').text content_type = elem.find('content_type').text - content = elem.find('content').text + if elem.find('b64_content') is not None: + content = base64.decodestring(elem.find('b64_content').text) + if elem.find('content') is not None: + content = elem.find('content').text ids = (self.parent.parent.id, self.parent.id, self.id) filename = 'export_to_model-%s-%s-%s.upload' % ids -- 2.6.4