How to use the oscpy.parser.padded function in oscpy

To help you get started, we’ve selected a few oscpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kivy / oscpy / tests / test_parser.py View on Github external
def test_parse_string():
    assert parse(b's', struct.pack('%is' % padded(len('t')), b't'))[0] == b't'
    s = b'test'
    # XXX should we need to add the null byte ourselves?
    assert parse(
        b's', struct.pack('%is' % padded(len(s) + 1), s + b'\0')
    )[0] == s
github kivy / oscpy / tests / test_parser.py View on Github external
def test_parse_blob():
    length = 10
    data = tuple(range(length))
    pad = padded(length, 8)
    fmt = '>i%iQ' % pad
    s = struct.pack(fmt, length, *(data + (pad - length) * (0, )))
    result = parse(b'b', s)[0]
    assert result == data
github kivy / oscpy / tests / test_parser.py View on Github external
def test_parse_string_encoded():
    assert parse(
        b's', struct.pack('%is' % padded(len('t')), u'é'.encode('utf8')),
        encoding='utf8'
    )[0] == u'é'

    s = u'aééééààààa'
    s_ = s.encode('utf8')
    assert parse(
        b's',
        struct.pack('%is' % padded(len(s_) + 1), s_ + b'\0'),
        encoding='utf8'
    )[0] == s

    with raises(UnicodeDecodeError):
        parse(
            b's',
            struct.pack('%is' % padded(len(s_) + 1), s_ + b'\0'),
            encoding='ascii'
github kivy / oscpy / tests / test_parser.py View on Github external
def test_parse_string():
    assert parse(b's', struct.pack('%is' % padded(len('t')), b't'))[0] == b't'
    s = b'test'
    # XXX should we need to add the null byte ourselves?
    assert parse(
        b's', struct.pack('%is' % padded(len(s) + 1), s + b'\0')
    )[0] == s
github kivy / oscpy / tests / test_parser.py View on Github external
assert parse(
        b's',
        struct.pack('%is' % padded(len(s_) + 1), s_ + b'\0'),
        encoding='utf8'
    )[0] == s

    with raises(UnicodeDecodeError):
        parse(
            b's',
            struct.pack('%is' % padded(len(s_) + 1), s_ + b'\0'),
            encoding='ascii'
        )[0] == s

    assert parse(
        b's',
        struct.pack('%is' % padded(len(s_) + 1), s_ + b'\0'),
        encoding='ascii',
        encoding_errors='replace'
    )[0] == u'a����������������a'

    assert parse(
        b's',
        struct.pack('%is' % padded(len(s_) + 1), s_ + b'\0'),
        encoding='ascii',
        encoding_errors='ignore'
    )[0] == 'aa'
github kivy / oscpy / tests / test_parser.py View on Github external
def test_read_bundle():
    pad = padded(len('#bundle'))
    data = struct.pack('>%isQ' % pad, b'#bundle', 1)

    tests = (
        message_1,
        message_2,
        message_1,
        message_2,
    )

    for source, msg, result in tests:
        msg = struct.pack('>%iB' % len(msg), *msg)
        assert read_message(msg)[::2] == result
        data += struct.pack('>i', len(msg)) + msg

    timetag, messages = read_bundle(data)
    for test, r in zip(tests, messages):
github kivy / oscpy / tests / test_parser.py View on Github external
def test_padd_string():
    for i in range(8):
        length = padded(i)
        assert length % 4 == 0
        assert length >= i