コード例 #1
0
ファイル: test.py プロジェクト: trb116/pythonanalyzer
def test_str():
    str_test = [("msg", b.string(5))]

    data = bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f])
    result = b.parse(data, str_test)
    assert_equal(result.msg.decode('utf-8'), "hello")

    assert_equal(b.write(result, str_test), data)
コード例 #2
0
def test_str():
    str_test = [("msg", b.string(5))]

    data = bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f])
    result = b.parse(data, str_test)
    assert_equal(result.msg.decode('utf-8'), "hello")

    assert_equal(b.write(result, str_test), data)
コード例 #3
0
ファイル: test.py プロジェクト: trb116/pythonanalyzer
def test_parse_str():
    test_struct = [("str", b.string(13))]

    test_str = str("gabbagabbahey")

    test_parsed = b.parse(test_str, test_struct)

    assert_equal(test_parsed.str.decode('utf-8'), "gabbagabbahey")
コード例 #4
0
ファイル: test.py プロジェクト: yurtaev/bread
def test_str():
    str_test = [("msg", b.string(5))]

    data = bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f])
    result = b.parse(data, str_test)

    assert result.msg == "hello"

    assert b.write(result, str_test) == data
コード例 #5
0
def test_parse_str():
    test_struct = [
        ("str", b.string(13))
    ]

    test_str = str("gabbagabbahey")

    test_parsed = b.parse(test_str, test_struct)

    assert_equal(test_parsed.str.decode('utf-8'), "gabbagabbahey")
コード例 #6
0
ファイル: test.py プロジェクト: alexras/bread
def test_parse_str():
    test_struct = [
        ("str", b.string(13))
    ]

    test_str = str("gabbagabbahey")

    test_parsed = b.parse(test_str, test_struct)

    assert test_parsed.str == "gabbagabbahey"
コード例 #7
0
ファイル: test.py プロジェクト: alexras/bread
def test_str():
    str_test = [("msg", b.string(5))]

    data = bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f])
    result = b.parse(data, str_test)
    assert result.msg == "hello"

    assert b.write(result, str_test) == data

    assert result.as_json() == json.dumps({'msg': 'hello'})
コード例 #8
0
ファイル: test.py プロジェクト: trb116/pythonanalyzer
def test_read_and_write_prefix():
    lsdsng_preamble = [("name", b.string(8)), ("version", b.byte)]

    data = 'hellomon'.encode('utf-8')

    data += bytearray([10, 20, 30, 40, 50])

    parsed = b.parse(data, lsdsng_preamble)

    assert_equal(len(parsed), 9 * 8)

    output_bytes = b.write(parsed)

    assert_equal(len(output_bytes), 9)
コード例 #9
0
def test_get_slice():
    data = bytearray([0x61, 0x62, 0x63, 0x64, 0x65, 0x66])

    slice_test_format = [('arr', b.array(6, b.string(1)))]

    slice_test = b.parse(data, slice_test_format)

    assert_equal([b'a', b'b', b'c', b'd', b'e', b'f'], list(slice_test.arr))

    assert_equal([b'c', b'd', b'e', b'f'], slice_test.arr[2:])
    assert_equal([b'a', b'b'], slice_test.arr[:2])
    assert_equal([b'f', b'e', b'd', b'c', b'b', b'a'], slice_test.arr[::-1])
    assert_equal([b'c', b'd', b'e'], slice_test.arr[2:5])
    assert_equal([b'f', b'e', b'd'], slice_test.arr[5:2:-1])
    assert_equal([b'f', b'e', b'd'], slice_test.arr[:2:-1])
コード例 #10
0
ファイル: test.py プロジェクト: trb116/pythonanalyzer
def test_new():
    format_spec = [("greeting", b.string(5)), ("age", b.nibble)]

    empty_struct = b.new(format_spec)

    assert_equal(len(empty_struct), 8 * 5 + 4)

    assert_equal(empty_struct.greeting, b'\x00\x00\x00\x00\x00')
    assert_equal(empty_struct.age, 0)

    empty_struct.greeting = 'hello'
    empty_struct.age = 0xb

    output_bytes = b.write(empty_struct)
    assert_equal(output_bytes, bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xb0]))
コード例 #11
0
ファイル: test.py プロジェクト: trb116/pythonanalyzer
def test_get_slice():
    data = bytearray([0x61, 0x62, 0x63, 0x64, 0x65, 0x66])

    slice_test_format = [('arr', b.array(6, b.string(1)))]

    slice_test = b.parse(data, slice_test_format)

    assert_equal([b'a', b'b', b'c', b'd', b'e', b'f'], list(slice_test.arr))

    assert_equal([b'c', b'd', b'e', b'f'], slice_test.arr[2:])
    assert_equal([b'a', b'b'], slice_test.arr[:2])
    assert_equal([b'f', b'e', b'd', b'c', b'b', b'a'], slice_test.arr[::-1])
    assert_equal([b'c', b'd', b'e'], slice_test.arr[2:5])
    assert_equal([b'f', b'e', b'd'], slice_test.arr[5:2:-1])
    assert_equal([b'f', b'e', b'd'], slice_test.arr[:2:-1])
コード例 #12
0
ファイル: test.py プロジェクト: alexras/bread
def _test_new(data=None):
    format_spec = [("greeting", b.string(5)),
                   ("age", b.nibble)]

    empty_struct = b.new(format_spec, data=data)

    assert len(empty_struct) == 8 * 5 + 4

    assert empty_struct.greeting == b'\x00\x00\x00\x00\x00'.decode('utf-8')
    assert empty_struct.age == 0

    empty_struct.greeting = 'hello'
    empty_struct.age = 0xb

    output_bytes = b.write(empty_struct)
    assert output_bytes == bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xb0])
コード例 #13
0
ファイル: test.py プロジェクト: trb116/pythonanalyzer
def test_str_unicode():
    str_test = [("msg", b.string(5))]

    data = bytearray([104, 101, 108, 108, 111])
    result = b.parse(data, str_test)

    assert_equal(result.msg.decode('utf-8'), "hello")
    assert_equal(b.write(result, str_test), data)

    result.msg = "abate"

    output_data = b.write(result, str_test)

    edited_result = b.parse(output_data, str_test)

    assert_equal(result.msg, "abate")
コード例 #14
0
ファイル: test.py プロジェクト: yurtaev/bread
def test_str_unicode():
    str_test = [("msg", b.string(5))]

    data = bytearray([104, 101, 108, 108, 111])
    result = b.parse(data, str_test)

    assert result.msg == "hello"
    assert b.write(result, str_test) == data

    result.msg = "abate"

    output_data = b.write(result, str_test)

    edited_result = b.parse(output_data, str_test)

    assert result.msg == "abate"
コード例 #15
0
def test_str_unicode():
    str_test = [("msg", b.string(5))]

    data = bytearray([104, 101, 108, 108, 111])
    result = b.parse(data, str_test)

    assert_equal(result.msg.decode('utf-8'), "hello")
    assert_equal(b.write(result, str_test), data)

    result.msg = "abate"

    output_data = b.write(result, str_test)

    edited_result = b.parse(output_data, str_test)

    assert_equal(result.msg, "abate")
コード例 #16
0
def test_new():
    format_spec = [("greeting", b.string(5)),
                   ("age", b.nibble)]

    empty_struct = b.new(format_spec)

    assert_equal(len(empty_struct), 8 * 5 + 4)

    assert_equal(empty_struct.greeting, b'\x00\x00\x00\x00\x00')
    assert_equal(empty_struct.age, 0)

    empty_struct.greeting = 'hello'
    empty_struct.age = 0xb

    output_bytes = b.write(empty_struct)
    assert_equal(output_bytes, bytearray([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xb0]))
コード例 #17
0
def test_read_and_write_prefix():
    lsdsng_preamble = [
        ("name", b.string(8)),
        ("version", b.byte)
    ]

    data = 'hellomon'.encode('utf-8')

    data += bytearray([10, 20, 30, 40, 50])

    parsed = b.parse(data, lsdsng_preamble)

    assert_equal(len(parsed), 9 * 8)

    output_bytes = b.write(parsed)

    assert_equal(len(output_bytes), 9)
コード例 #18
0
ファイル: read_nsf_header.py プロジェクト: alexras/nsf-tools
import bread as b
import sys

def hex_array(x):
    return str(map(hex, x))

nsf_header = [
    ('magic_number', b.array(5, b.byte),
     {"str_format": hex_array}),
    ('version', b.byte),
    ('total_songs', b.byte),
    ('starting_song', b.byte),
    ('load_addr', b.uint16, {"str_format": hex}),
    ('init_addr', b.uint16, {"str_format": hex}),
    ('play_addr', b.uint16, {"str_format": hex}),
    ('title', b.string(32)),
    ('artist', b.string(32)),
    ('copyright', b.string(32)),
    ('ntsc_speed', b.uint16),
    ('bankswitch_init', b.array(8, b.byte), {"str_format": hex_array}),
    ('pal_speed', b.uint16),
    ('ntsc', b.boolean),
    ('pal', b.boolean),
    ('ntsc_and_pal', b.boolean),
    (b.padding(6)),
    ('vrc6', b.boolean),
    ('vrc7', b.boolean),
    ('fds', b.boolean),
    ('mmc5', b.boolean),
    ('namco_106', b.boolean),
    ('fme07', b.boolean),
コード例 #19
0
        'offset': -7
    })  # Range from -7 to 7
]

raw_voice = [('operators', b.array(6, raw_operator)),
             ('pitch_eg_rates', b.array(4, b.uint8)),
             ('pitch_eg_levels', b.array(4, b.uint8)),
             ('algorithm', b.uint8, {
                 'offset': 1
             }), ('feedback', b.uint8), ('oscillator_sync', b.uint8),
             ('lfo_speed', b.uint8), ('lfo_delay', b.uint8),
             ('lfo_pitch_mod_depth', b.uint8), ('lfo_amp_mod_depth', b.uint8),
             ('lfo_sync', b.uint8),
             ('lfo_waveform', b.enum(8, enums['waveforms'])),
             ('pitch_mod_sensitivity', b.uint8), ('transpose', b.uint8),
             ('name', b.string(10, NAME_ENCODING))]

compressed_operator = [
    ('eg_rates', b.array(4, b.uint8)),
    ('eg_levels', b.array(4, b.uint8)),
    ('keyboard_level_scaling_break_point', b.uint8),  # C3 = 0x27
    ('keyboard_level_scaling_left_depth', b.uint8),
    ('keyboard_level_scaling_right_depth', b.uint8),
    b.padding(4),
    # Byte 11
    ('keyboard_level_scaling_right_curve', b.enum(2, enums['curves'])),
    ('keyboard_level_scaling_left_curve', b.enum(2, enums['curves'])),
    # Byte 12
    b.padding(1),
    ('osc_detune', b.intX(4), {
        'offset': -7
コード例 #20
0
import bread as b
import sys


def hex_array(x):
    return str(map(hex, x))


nsf_header = [('magic_number', b.array(5, b.byte), {
    "str_format": hex_array
}), ('version', b.byte), ('total_songs', b.byte), ('starting_song', b.byte),
              ('load_addr', b.uint16, {
                  "str_format": hex
              }), ('init_addr', b.uint16, {
                  "str_format": hex
              }), ('play_addr', b.uint16, {
                  "str_format": hex
              }), ('title', b.string(32)), ('artist', b.string(32)),
              ('copyright', b.string(32)), ('ntsc_speed', b.uint16),
              ('bankswitch_init', b.array(8, b.byte), {
                  "str_format": hex_array
              }), ('pal_speed', b.uint16), ('ntsc', b.boolean),
              ('pal', b.boolean), ('ntsc_and_pal', b.boolean), (b.padding(6)),
              ('vrc6', b.boolean), ('vrc7', b.boolean), ('fds', b.boolean),
              ('mmc5', b.boolean), ('namco_106', b.boolean),
              ('fme07', b.boolean), (b.padding(2)), (b.padding(32))]

with open(sys.argv[1], 'r') as fp:
    header = b.parse(fp, nsf_header)
    print header
コード例 #21
0
ファイル: bread_spec.py プロジェクト: alexras/pylsdj
import bread as b

from .vendor.six.moves import range

def padded_hex(pad_count):
    return lambda x: ("0x%%0%dx" % (pad_count)) % (x)

EMPTY_BLOCK = 0xff

# File management structure (starts at 0x8000)
compressed_sav_file = [
    # Up to 32 files (songs) can be saved to one cartridge
    ("filenames", b.array(32, b.string(8))),
    # Each file has a monotonically increasing version number
    ("file_versions", b.array(32, b.byte)),
    b.padding(30 * 8),
    ("sram_init_check", b.string(2)),  # set to 'jk' on init
    # The file that is currently active
    ("active_file", b.byte),
    # Table mapping blocks to files.
    ("block_alloc_table", b.array(191, b.byte))
]

# Should be 0x4000 bytes long
sample_kit = [
    ("magic_number", b.string(2)),  # should be 0x60, 0x40
    # The address of the first byte after each sample, or 0 if the sample is
    # unused
    ("sample_end_addresses", b.array(15, b.string(2))),
    b.padding(2 * 8),
    # For samples with names less than three characters long, sample names are
コード例 #22
0
        with open(path, 'w') as f:
            f.write(x)


def hex_array(x):
    return str(map(hex, x))

nsf_head_spec = \
  [ ('magic_number', b.array(5, b.byte), {"str_format": hex_array})
      , ('version', b.byte)
      , ('total_songs', b.byte)
      , ('starting_song', b.byte)
      , ('load_addr', b.uint16, {"str_format": hex})
      , ('init_addr', b.uint16, {"str_format": hex})
      , ('play_addr', b.uint16, {"str_format": hex})
      , ('title', b.string(32))
      , ('artist', b.string(32))
      , ('copyright', b.string(32))
      , ('ntsc_speed', b.uint16)
      , ('bankswitch_init', b.array(8, b.byte), {"str_format": hex_array})
      , ('pal_speed', b.uint16)
      , ('tv_std', b.boolean, {"str_format": lambda x: "PAL" if x else "NTSC"})
      , ('ntsc_and_pal', b.boolean)
      , (b.padding(6))
      , ('vrc6', b.boolean)
      , ('vrc7', b.boolean)
      , ('fds', b.boolean)
      , ('mmc5', b.boolean)
      , ('namco_106', b.boolean)
      , ('fme07', b.boolean)
      , (b.padding(2))
コード例 #23
0
ファイル: bread_spec.py プロジェクト: alexras/pylsdj
import bread as b

from .vendor.six.moves import range


def padded_hex(pad_count):
    return lambda x: ("0x%%0%dx" % (pad_count)) % (x)


EMPTY_BLOCK = 0xff

# File management structure (starts at 0x8000)
compressed_sav_file = [
    # Up to 32 files (songs) can be saved to one cartridge
    ("filenames", b.array(32, b.string(8))),
    # Each file has a monotonically increasing version number
    ("file_versions", b.array(32, b.byte)),
    b.padding(30 * 8),
    ("sram_init_check", b.string(2)),  # set to 'jk' on init
    # The file that is currently active
    ("active_file", b.byte),
    # Table mapping blocks to files.
    ("block_alloc_table", b.array(191, b.byte))
]

# Should be 0x4000 bytes long
sample_kit = [
    ("magic_number", b.string(2)),  # should be 0x60, 0x40
    # The address of the first byte after each sample, or 0 if the sample is
    # unused
    ("sample_end_addresses", b.array(15, b.string(2))),
コード例 #24
0
ファイル: bread_spec.py プロジェクト: exilefaker/LSDJ_NN
import bread as b

from .vendor.six.moves import range

def padded_hex(pad_count):
    return lambda x: ("0x%%0%dx" % (pad_count)) % (x)

EMPTY_BLOCK = 0xff

# File management structure (starts at 0x8000)
compressed_sav_file = [
    # Up to 32 files (songs) can be saved to one cartridge
    ("filenames", b.array(32, b.string(8))),
    # Each file has a monotonically increasing version number
    ("file_versions", b.array(32, b.byte)),
    b.padding(30 * 8),
    ("sram_init_check", b.string(2)),  # set to 'jk' on init
    # The file that is currently active
    ("active_file", b.byte),
    # Table mapping blocks to files.
    ("block_alloc_table", b.array(191, b.byte))
]

# Should be 0x4000 bytes long
sample_kit = [
    ("magic_number", b.string(2)),  # should be 0x60, 0x40
    # The address of the first byte after each sample, or 0 if the sample is
    # unused
    ("sample_end_addresses", b.array(15, b.string(2))),
    b.padding(2 * 8),
    # For samples with names less than three characters long, sample names are