Skip to content

Commit

Permalink
Support // matching operator from OSC 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
artfwo committed Jul 26, 2014
1 parent 92eec04 commit 0d910b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions aiosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ def singleton(cls):
class Impulse:
pass

OSC_ADDR_REGEXP = '[^ #*,/?[\]{}]'
OSC_ADDR_SLASH_REGEXP = '[^ #*,?[\]{}]'

# translate osc address pattern to regexp for use in message handlers
def translate_pattern(pattern):
result = ''
i = 0
while i < len(pattern):
c = pattern[i]
if c == '?':
result += '.'
if c == '/':
j = i + 1
if pattern[j] == '/':
result += OSC_ADDR_SLASH_REGEXP + '*\/'
i = j
else:
result += re.escape(c)
elif c == '?':
result += OSC_ADDR_REGEXP
elif c == '*':
result += '.*'
result += OSC_ADDR_REGEXP + '*'
elif c == '[':
j = pattern.index(']', i)
sub = pattern[i+1:j]
Expand All @@ -63,7 +73,7 @@ def translate_pattern(pattern):
else:
result += re.escape(c)
i += 1
return result
return "^" + result + "$"

# read padded string from the beginning of a packet and return (value, tail)
def read_string(packet):
Expand Down
2 changes: 1 addition & 1 deletion examples/echo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EchoServer(aiosc.OSCProtocol):
def __init__(self):
super().__init__(handlers={
'/sys/exit': self.exit,
'*': self.echo
'//*': self.echo,
})

def exit(self, *args):
Expand Down
2 changes: 1 addition & 1 deletion examples/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def protocol_factory():
osc = aiosc.OSCProtocol({
'*': lambda addr, path, *args: print(addr, path, args)
'//*': lambda addr, path, *args: print(addr, path, args)
})
return osc

Expand Down

0 comments on commit 0d910b6

Please sign in to comment.