diff --git a/swf/export.py b/swf/export.py index 33838a8..5e5ed81 100644 --- a/swf/export.py +++ b/swf/export.py @@ -13,12 +13,12 @@ import base64 from six.moves import map from six.moves import range +from six import unichr try: import Image except ImportError: from PIL import Image from io import BytesIO -from six.moves import cStringIO import math import re import copy @@ -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]) @@ -542,11 +542,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): @@ -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): 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): 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'