kivy / oscpy

An efficient OSC implementation compatible with python2.7 and 3.5+
MIT License
109 stars 27 forks source link

Accept malformed messages #66

Closed doug-hoffman closed 2 years ago

doug-hoffman commented 2 years ago

Allows optional acceptance of malformed messages that have an address beginning with something other than '/'. Messages are still required to begin with '/' by default to enforce the OSC specification.

Required to support Midas M32/Behringer X32 OSC implementation that sends messages with an address of 'node' or beginning with 'meters/'.

tshirtman commented 2 years ago

Sorry i didn't see this before. I understand the need for it for non-compliant software, but i find the parameter name accept_malformed_message a bit vague, maybe something like valid_address_prefixes that could be a list of strings, defaulting to ['/'] and that could be replaced with the other forms you expect to receive? In your case ['/', 'node', 'meter']?

So the code instead of checking for the flag, could check if the address startswith any of the valid address prefixes any(address.startswith(prefix) for prefix in self.valid_address_prefixes).

Or maybe more simply define the parameter as validate_message_address=True that could be set to False if the user doesn't want the check.

The docstrings of the method(s) would also need to be updated to document the effect of the new parameter.

doug-hoffman commented 2 years ago

I renamed the parameter to validate_message_address and inverted logic from my previous submission.

Extending to support a flexible list of valid prefixes would have required some additional changes and only seems necessary for implementations that send a mix of messages which both do and don't parse correctly in read_message() or elsewhere and can be easily grouped by address prefix. At that point, they're probably deviating so far from the spec it'd be hard to predict how it could fail.

tshirtman commented 2 years ago

Merged, thanks for the update :)