Ejemplo n.º 1
0
class TestSwfProcessor(unittest.TestCase):
    def setUp(self):
        self.swf_bitmap = Swf(open('sample/bitmap/bitmap.swf').read())
        self.swf_tank = Swf(open('sample/mc/tank.swf').read())

    def test_bits(self):
        int_num = 31415
        signed_num = -27182
        float_num = 1.6180339
        self.assertEqual(int_num, int(Bits(int_num)))
        self.assertEqual(signed_num, int(SB(signed_num)))
        self.assertAlmostEqual(float_num, float(FB(float_num)), 4)

    def test_bits2string(self):
        spam_string = "This is a spam!"
        self.assertEqual(spam_string, bits_list2string([Bits(spam_string)]))

    def test_matrixes(self):
        self.assertEqual(True, test_matrix())
        self.assertEqual(True, test_matrix(translate=(1250, 744)))
        self.assertEqual(True, test_matrix(scale=(2,4, 3.7)))
        self.assertEqual(True, test_matrix(scale=(-55, -66), translate=(1250, 744)))
        self.assertEqual(True, test_matrix(rotate=(-2.4, -3.8)))
        self.assertEqual(True, test_matrix(rotate=(33, 66), translate=(1250, 744)))
        self.assertEqual(True, test_matrix(scale=(77, 44), rotate=(1,5, -3.7)))
        self.assertEqual(True, test_matrix(translate=(1250, 744), rotate=(-1, -1), scale=(-3, -1)))

    def test_fields_io_serialize_and_deserialize(self):
        m1 = MATRIX().generate(
            scale=(2.4, 3.7),
            translate=(1500, 1500))
        tpl = m1.serialize()
        m2 = MATRIX().deserialize(tpl)
        self.assertEqual(m1.value, m2.value)

    def test_getting_movie_clip(self):
        self.assertNotEqual(None, self.swf_tank.get_movie_clip('kombu'))
        self.assertRaises(MovieClipDoesNotExist, 
            self.swf_bitmap.get_movie_clip, 'this_is_not_spam')

    def test_delete_movie_clip(self):
        self.swf_tank.delete_movie_clip('kombu')
        self.swf_tank.write(open('sample/mc/tank_without_kombu.swf', 'w'))

    def test_copy_swf(self):
        c_tank = self.swf_tank.copy()
        c_bitmap = self.swf_bitmap.copy()
        self.assertEqual(c_tank.write(), self.swf_tank.write())
        self.assertEqual(c_bitmap.write(), self.swf_bitmap.write())
        c_tank.write(open('sample/mc/copy_tank.swf', 'w'))
        c_bitmap.write(open('sample/mc/copy_bitmap.swf', 'w'))
Ejemplo n.º 2
0
def mc2swf(in_swf_filename, out_dir, limit_depth):
    print "parsing %s ..." % in_swf_filename
    in_swf = Swf(open(in_swf_filename).read())
    mc_base_bin = open('sample/mc/blank.swf').read()

    for mc_name in in_swf.get_movie_clip_name():
        # generating MovieClip
        mc_base = Swf(mc_base_bin)
        ret = mc_base.replace_movie_clip("replace_movie_clip", in_swf.get_movie_clip(mc_name))
        ret.place_object2.set_name(mc_name)
        mc_file_str = os.path.join(out_dir, mc_name) + ".swf"
        print "writing %s ..." % mc_file_str
        mc_base.write(open(mc_file_str, 'w'))
        
        # checking MC's depth
        SwfDepthChecker(mc_base, limit_depth)
Ejemplo n.º 3
0
 def setUp(self):
     self.swf_bitmap = Swf(open('sample/bitmap/bitmap.swf').read())
     self.swf_tank = Swf(open('sample/mc/tank.swf').read())
Ejemplo n.º 4
0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import sys
from tomato.swf_processor import Swf

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print "usage: python swf_serializer.py [input.swf] [out.p]"
        sys.exit(1)

    input_swf = Swf(open(sys.argv[1]).read())
    input_swf.dumps(open(sys.argv[2], 'w'))