示例#1
0
    def test_longstring(self):
        self.set_name('longstring')
        self.add_get_test('\x00\x00\x00\x0btest string', 'test string')
        self.add_get_test('\x00\x00\x00\x1azażółć gęślą jaźń', 'zażółć gęślą jaźń')
        self.add_make_test('zażółć gęślą jaźń', '\x00\x00\x00\x1azażółć gęślą jaźń')
        # the resulting string should be UTF-8 encoded, just like this file
        self.add_make_test(u'λ', '\x00\x00\x00\x02λ')
        # A random blob should also work
        self.add_make_test('\x45\x2d\x6e\x55\x00\x23\x50', '\x00\x00\x00\x07\x45\x2d\x6e\x55\x00\x23\x50')
        self.add_make_test('', '\x00\x00\x00\x00')
        self.run_tests()

        # Longstrings are not getter/maker equivalent, because *all*
        # strings are serialized as normal strings, not longstrings.
        # So to test proper deserialization from script_data_values we
        # need to do it manually.
        val = 'a test longstring'
        # serialize, should get a string
        self.assertEquals(astypes.make_script_data_value(val),
                          primitives.make_ui8(constants.VALUE_TYPE_STRING)
                          + '\x00\x11a test longstring')
        # deserialize a longstring
        s = StringIO(primitives.make_ui8(constants.VALUE_TYPE_LONGSTRING)
                     + astypes.make_longstring(val))
        self.assertEquals(val, astypes.get_script_data_value(s))
        self.assertEquals(s.read(), '')
示例#2
0
    def test_longstring(self):
        self.set_name('longstring')
        self.add_get_test('\x00\x00\x00\x0btest string', 'test string')
        self.add_get_test('\x00\x00\x00\x1azażółć gęślą jaźń',
                          'zażółć gęślą jaźń')
        self.add_make_test('zażółć gęślą jaźń',
                           '\x00\x00\x00\x1azażółć gęślą jaźń')
        # the resulting string should be UTF-8 encoded, just like this file
        self.add_make_test(u'λ', '\x00\x00\x00\x02λ')
        # A random blob should also work
        self.add_make_test('\x45\x2d\x6e\x55\x00\x23\x50',
                           '\x00\x00\x00\x07\x45\x2d\x6e\x55\x00\x23\x50')
        self.add_make_test('', '\x00\x00\x00\x00')
        self.run_tests()

        # Longstrings are not getter/maker equivalent, because *all*
        # strings are serialized as normal strings, not longstrings.
        # So to test proper deserialization from script_data_values we
        # need to do it manually.
        val = 'a test longstring'
        # serialize, should get a string
        self.assertEquals(
            astypes.make_script_data_value(val),
            primitives.make_ui8(constants.VALUE_TYPE_STRING) +
            '\x00\x11a test longstring')
        # deserialize a longstring
        s = StringIO(
            primitives.make_ui8(constants.VALUE_TYPE_LONGSTRING) +
            astypes.make_longstring(val))
        self.assertEquals(val, astypes.get_script_data_value(s))
        self.assertEquals(s.read(), '')
def output_offset_tag(fi, fo, tag, offset):
    new_timestamp = tag.timestamp - offset
    # do not offset non-media and media header
    if not is_nonheader_media(tag):
        new_timestamp = tag.timestamp

    # write the FLV tag value
    fo.write(make_ui8(class_to_tag[tag.__class__]))
    # the tag size remains unchanged
    fo.write(make_ui24(tag.size))
    # wirte the new timestamp
    fo.write(make_si32_extended(new_timestamp))
    # seek inside the input file
    #   seek position: tag offset + tag (1) + size (3) + timestamp (4)
    fi.seek(tag.offset + 8, os.SEEK_SET)
    # copy the tag content to the output file
    #   content size:  tag size + stream ID (3) + previous tag size (4)
    fo.write(fi.read(tag.size + 7))
示例#4
0
def output_offset_tag(fi, fo, tag, offset):
    new_timestamp = tag.timestamp - offset
    # do not offset non-media and media header
    if not is_nonheader_media(tag):
        new_timestamp = tag.timestamp

    # write the FLV tag value
    fo.write(make_ui8(class_to_tag[tag.__class__]))
    # the tag size remains unchanged
    fo.write(make_ui24(tag.size))
    # wirte the new timestamp
    fo.write(make_si32_extended(new_timestamp))
    # seek inside the input file
    #   seek position: tag offset + tag (1) + size (3) + timestamp (4)
    fi.seek(tag.offset + 8, os.SEEK_SET)
    # copy the tag content to the output file
    #   content size:  tag size + stream ID (3) + previous tag size (4)
    fo.write(fi.read(tag.size + 7))
示例#5
0
 def script_data_value_equivalent(self, val, getter, maker, value_type):
     s = StringIO(primitives.make_ui8(value_type) + maker(val))
     self.assertEquals(astypes.make_script_data_value(val), s.getvalue())
     self.assertEquals(val, astypes.get_script_data_value(s))
     self.assertEquals(s.read(), '')
示例#6
0
 def script_data_value_equivalent(self, val, getter, maker, value_type):
     s = StringIO(primitives.make_ui8(value_type) + maker(val))
     self.assertEquals(astypes.make_script_data_value(val), s.getvalue())
     self.assertEquals(val, astypes.get_script_data_value(s))
     self.assertEquals(s.read(), '')