Skip to content

Commit

Permalink
Add python3 support
Browse files Browse the repository at this point in the history
Fixes issue timknip#34
  • Loading branch information
CounterPillow committed Feb 20, 2016
1 parent 6dcc9b9 commit 339c85e
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 46 deletions.
1 change: 1 addition & 0 deletions bin/swf2svg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import argparse
from swf.movie import SWF
from swf.export import SVGExporter
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import os
from setuptools import setup, find_packages

Expand All @@ -19,7 +20,7 @@ def read(fname):
author_email='[email protected]',
url='https://github.com/timknip/pyswf',

install_requires = ["lxml>=3.3.0", "Pillow>=2.3.0", "pylzma>=0.4.6"],
install_requires = ["lxml>=3.3.0", "Pillow>=2.3.0", "pylzma>=0.4.6", "six"],
packages=find_packages(),
license = "MIT",
classifiers=[
Expand Down
4 changes: 3 additions & 1 deletion swf/actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from __future__ import absolute_import
import six
class Action(object):
def __init__(self, code, length):
self._code = code
Expand Down Expand Up @@ -177,7 +179,7 @@ def __init__(self, code, length):
# urgh! some 100 to go...

ActionTable = {}
for name, value in dict(locals()).iteritems():
for name, value in six.iteritems(dict(locals())):
if type(value) == type and issubclass(value, Action) and hasattr(value, 'CODE'):
ActionTable[value.CODE] = value

Expand Down
11 changes: 7 additions & 4 deletions swf/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from consts import *
from utils import *
from __future__ import absolute_import
from .consts import *
from .utils import *
from six.moves import map
from six.moves import range

class _dumb_repr(object):
def __repr__(self):
Expand Down Expand Up @@ -70,7 +73,7 @@ def parse(self, data, level=1):
def export(self, handler=None):
self._create_edge_maps()
if handler is None:
from export import SVGShapeExporter
from .export import SVGShapeExporter
handler = SVGShapeExporter()
handler.begin_shape()
for i in range(0, self.num_groups):
Expand Down Expand Up @@ -1340,7 +1343,7 @@ def parse(self, data):
self.outPoint = data.readUI32() if self.hasOutPoint else None
self.loopCount = data.readUI16() if self.hasLoops else None
self.envPointCount = data.readUI8() if self.hasEnvelope else None
self.envelopePoints = [data.readSOUNDENVELOPE() for x in xrange(self.envPointCount)] if self.hasEnvelope else None
self.envelopePoints = [data.readSOUNDENVELOPE() for x in range(self.envPointCount)] if self.hasEnvelope else None

def __str__(self):
return "[SWFSoundInfo]"
Expand Down
22 changes: 11 additions & 11 deletions swf/export.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"""
This module defines exporters for the SWF fileformat.
"""
from consts import *
from geom import *
from utils import *
from data import *
from tag import *
from filters import *
from __future__ import absolute_import
from .consts import *
from .geom import *
from .utils import *
from .data import *
from .tag import *
from .filters import *
from lxml import objectify
from lxml import etree
import base64
from six.moves import map
from six.moves import range
try:
import Image
except ImportError:
from PIL import Image
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from six.moves import cStringIO
import math
import re
import copy
Expand Down Expand Up @@ -992,7 +992,7 @@ def _parse(self, element):
def _build_matrix(self, transform):
if transform.find("matrix") >= 0:
raw = str(transform).replace("matrix(", "").replace(")", "")
f = map(float, re.split("\s+|,", raw))
f = list(map(float, re.split("\s+|,", raw)))
return Matrix2(f[0], f[1], f[2], f[3], f[4], f[5])

def _calc_combined_matrix(self):
Expand Down
5 changes: 4 additions & 1 deletion swf/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from utils import ColorUtils
from __future__ import absolute_import
from .utils import ColorUtils
from six.moves import map
from six.moves import range

class Filter(object):
"""
Expand Down
1 change: 1 addition & 0 deletions swf/geom.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import math

SNAP = 0.001
Expand Down
12 changes: 5 additions & 7 deletions swf/movie.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""
SWF
"""
from tag import SWFTimelineContainer
from stream import SWFStream
from export import SVGExporter
try:
import cStringIO as StringIO
except ImportError:
import StringIO
from __future__ import absolute_import
from .tag import SWFTimelineContainer
from .stream import SWFStream
from .export import SVGExporter
from six.moves import cStringIO

class SWFHeaderException(Exception):
""" Exception raised in case of an invalid SWFHeader """
Expand Down
7 changes: 4 additions & 3 deletions swf/sound.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import consts
import tag
from __future__ import absolute_import
from . import consts
from . import tag
import wave
import stream
from . import stream

supportedCodecs = (
consts.AudioCodec.MP3,
Expand Down
15 changes: 9 additions & 6 deletions swf/stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import absolute_import
import struct, math
from data import *
from actions import *
from filters import SWFFilterFactory
from .data import *
from .actions import *
from .filters import SWFFilterFactory
from six.moves import range
from functools import reduce

class SWFStream(object):
"""
Expand Down Expand Up @@ -381,7 +384,7 @@ def readFILTER(self):
def readFILTERLIST(self):
""" Read a length-prefixed list of FILTERs """
number = self.readUI8()
return [self.readFILTER() for _ in xrange(number)]
return [self.readFILTER() for _ in range(number)]

def readZONEDATA(self):
""" Read a SWFZoneData """
Expand Down Expand Up @@ -440,14 +443,14 @@ def readMORPHFILLSTYLEARRAY(self):
count = self.readUI8()
if count == 0xff:
count = self.readUI16()
return [self.readMORPHFILLSTYLE() for _ in xrange(count)]
return [self.readMORPHFILLSTYLE() for _ in range(count)]

def readMORPHLINESTYLEARRAY(self, version):
count = self.readUI8()
if count == 0xff:
count = self.readUI16()
kind = self.readMORPHLINESTYLE if version == 1 else self.readMORPHLINESTYLE2
return [kind() for _ in xrange(count)]
return [kind() for _ in range(count)]

def readraw_tag(self):
""" Read a SWFRawTag """
Expand Down
21 changes: 10 additions & 11 deletions swf/tag.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from consts import *
from data import *
from utils import *
from stream import *
from __future__ import absolute_import
from .consts import *
from .data import *
from .utils import *
from .stream import *
import datetime
from six.moves import range
try:
import Image
except ImportError:
from PIL import Image
import struct

try:
import cStringIO as StringIO
except ImportError:
import StringIO
from six.moves import cStringIO

class TagFactory(object):
@classmethod
Expand Down Expand Up @@ -883,7 +882,7 @@ def parse(self, data, length, version=1):

# create the image buffer
s = StringIO.StringIO()
for i in xrange(t):
for i in range(t):
s.write(indexed_colors[ord(temp.read(1))])
self.image_buffer = s.getvalue()
s.close()
Expand Down Expand Up @@ -2220,7 +2219,7 @@ def type(self):

def parse(self, data, length, version=1):
self.count = data.readUI16()
self.exports = [data.readEXPORT() for i in xrange(self.count)]
self.exports = [data.readEXPORT() for i in range(self.count)]

def __str__(self):
s = super(TagExportAssets, self).__str__()
Expand Down Expand Up @@ -2642,7 +2641,7 @@ def parse(self, data, length, version=1):

if __name__ == '__main__':
# some table checks
for x in xrange(256):
for x in range(256):
y = TagFactory.create(x)
if y:
assert y.type == x, y.name + ' is misnamed'
Expand Down
3 changes: 2 additions & 1 deletion swf/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from consts import BitmapType
from __future__ import absolute_import
from .consts import BitmapType
import math

class NumberUtils(object):
Expand Down
1 change: 1 addition & 0 deletions test/test_swf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from swf.movie import SWF

def test_header():
Expand Down

0 comments on commit 339c85e

Please sign in to comment.