From 8bac887035a75c58edeee320431533667d54a222 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 5 Aug 2020 15:10:35 +0100 Subject: [PATCH 1/4] Change StringIO to BytesIO to work on Python 3. --- swf/export.py | 5 ++--- swf/movie.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/swf/export.py b/swf/export.py index 33838a8..49e3c72 100644 --- a/swf/export.py +++ b/swf/export.py @@ -18,7 +18,6 @@ except ImportError: from PIL import Image from io import BytesIO -from six.moves import cStringIO import math import re import copy @@ -542,11 +541,11 @@ def export(self, swf, force_stroke=False): self.bounds.width, self.bounds.height] self.svg.set("viewBox", "%s" % " ".join(map(str,vb))) - # Return the SVG as StringIO + # Return the SVG as BytesIO return self._serialize() def _serialize(self): - return cStringIO(etree.tostring(self.svg, + return BytesIO(etree.tostring(self.svg, encoding="UTF-8", xml_declaration=True)) def export_define_sprite(self, tag, parent=None): diff --git a/swf/movie.py b/swf/movie.py index bb2f721..c2fcc2b 100644 --- a/swf/movie.py +++ b/swf/movie.py @@ -5,7 +5,6 @@ from .tag import SWFTimelineContainer from .stream import SWFStream from .export import SVGExporter -from six.moves import cStringIO from io import BytesIO class SWFHeaderException(Exception): From 69822b78f2a4eb0d0d43a18b4bc125287ba6612c Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 5 Aug 2020 15:29:45 +0100 Subject: [PATCH 2/4] Import unichr for Python 3. --- swf/export.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swf/export.py b/swf/export.py index 49e3c72..00c3424 100644 --- a/swf/export.py +++ b/swf/export.py @@ -13,6 +13,7 @@ import base64 from six.moves import map from six.moves import range +from six import unichr try: import Image except ImportError: From d0078048128a7034533cdd9ada81e437b00187b4 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Sat, 8 Aug 2020 17:01:27 +0100 Subject: [PATCH 3/4] Some strings need to be bytestrings. --- swf/export.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swf/export.py b/swf/export.py index 00c3424..5e5ed81 100644 --- a/swf/export.py +++ b/swf/export.py @@ -421,7 +421,7 @@ def export_define_bits(self, tag): image_data = image.getdata() image_data_len = len(image_data) if num_alpha == image_data_len: - buff = "" + buff = b"" for i in range(0, num_alpha): alpha = ord(tag.bitmapAlphaData.read(1)) rgb = list(image_data[i]) @@ -1100,10 +1100,10 @@ def _push_transform(self, transform): self._matrix = self._calc_combined_matrix() def _encode_jpeg(data): - return "data:image/jpeg;base64," + base64.encodestring(data)[:-1] + return b"data:image/jpeg;base64," + base64.encodestring(data)[:-1] def _encode_png(data): - return "data:image/png;base64," + base64.encodestring(data)[:-1] + return b"data:image/png;base64," + base64.encodestring(data)[:-1] def _swf_matrix_to_matrix(swf_matrix=None, need_scale=False, need_translate=True, need_rotation=False, unit_div=20.0): From e05464b880ac5cd8e7655ff2b214be89f04542c1 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Sat, 8 Aug 2020 17:07:22 +0100 Subject: [PATCH 4/4] Very basic exporting test. --- test/test_swf.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_swf.py b/test/test_swf.py index 6659e94..72bffde 100644 --- a/test/test_swf.py +++ b/test/test_swf.py @@ -1,5 +1,6 @@ from __future__ import absolute_import from swf.movie import SWF +from swf.export import SVGExporter def test_header(): @@ -8,3 +9,12 @@ def test_header(): swf = SWF(f) assert swf.header.frame_count == 1 + +def test_export(): + f = open('./test/data/test.swf', 'rb') + swf = SWF(f) + + svg_exporter = SVGExporter() + svg = svg_exporter.export(swf) + + assert b'