Skip to content

Commit

Permalink
Merge pull request #160 from ideoforms/master
Browse files Browse the repository at this point in the history
Add support for arguments with Nil type
  • Loading branch information
attwad committed Nov 18, 2022
2 parents c032ca8 + 092596c commit 4b40a71
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pythonosc/osc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def _parse_datagram(self) -> None:
val = True
elif param == "F": # False.
val = False
elif param == "N": # Nil.
val = None
elif param == "[": # Array start.
array = [] # type: List[Any]
param_stack[-1].append(array)
Expand Down
3 changes: 0 additions & 3 deletions pythonosc/osc_message_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@

from typing import List, Tuple, Union, Any, Optional


ArgValue = Union[str, bytes, bool, int, float, osc_types.MidiPacket, list]


class BuildError(Exception):
"""Error raised when an incomplete message is trying to be built."""


class OscMessageBuilder(object):
"""Builds arbitrary OscMessage instances."""

Expand Down
14 changes: 8 additions & 6 deletions pythonosc/test/test_osc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
b"/SYNC\x00\x00\x00"
b"T" # True
b"F" # False
b"[]th\x00\x00" # Empty array
b"N" # Nil
b"[]th\x00" # Empty array
b"\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\xe8\xd4\xa5\x10\x00" # 1000000000000
)
Expand Down Expand Up @@ -100,13 +101,14 @@ def test_all_non_standard_params(self):
msg = osc_message.OscMessage(_DGRAM_ALL_NON_STANDARD_TYPES_OF_PARAMS)

self.assertEqual("/SYNC", msg.address)
self.assertEqual(5, len(msg.params))
self.assertEqual(6, len(msg.params))
self.assertEqual(True, msg.params[0])
self.assertEqual(False, msg.params[1])
self.assertEqual([], msg.params[2])
self.assertEqual((datetime(1900, 1, 1, 0, 0, 0), 0), msg.params[3])
self.assertEqual(1000000000000, msg.params[4])
self.assertEqual(5, len(list(msg)))
self.assertEqual(None, msg.params[2])
self.assertEqual([], msg.params[3])
self.assertEqual((datetime(1900, 1, 1, 0, 0, 0), 0), msg.params[4])
self.assertEqual(1000000000000, msg.params[5])
self.assertEqual(6, len(list(msg)))

def test_complex_array_params(self):
msg = osc_message.OscMessage(_DGRAM_COMPLEX_ARRAY_PARAMS)
Expand Down
2 changes: 1 addition & 1 deletion pythonosc/test/test_osc_message_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_all_param_types(self):
msg = builder.build()
self.assertEqual("/SEEK", msg.address)
self.assertSequenceEqual(
[4.0, 2, 1099511627776, "value", True, False, b"\x01\x02\x03", [1, ["abc"]]] * 2 +
[4.0, 2, 1099511627776, "value", True, False, b"\x01\x02\x03", [1, ["abc"]], None] * 2 +
[4278255360, (1, 145, 36, 125), 1e-9],
msg.params)

Expand Down

0 comments on commit 4b40a71

Please sign in to comment.