Skip to content

Commit 0d910b6

Browse files
committed
Support // matching operator from OSC 1.1
1 parent 92eec04 commit 0d910b6

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

aiosc.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,26 @@ def singleton(cls):
3333
class Impulse:
3434
pass
3535

36+
OSC_ADDR_REGEXP = '[^ #*,/?[\]{}]'
37+
OSC_ADDR_SLASH_REGEXP = '[^ #*,?[\]{}]'
38+
3639
# translate osc address pattern to regexp for use in message handlers
3740
def translate_pattern(pattern):
3841
result = ''
3942
i = 0
4043
while i < len(pattern):
4144
c = pattern[i]
42-
if c == '?':
43-
result += '.'
45+
if c == '/':
46+
j = i + 1
47+
if pattern[j] == '/':
48+
result += OSC_ADDR_SLASH_REGEXP + '*\/'
49+
i = j
50+
else:
51+
result += re.escape(c)
52+
elif c == '?':
53+
result += OSC_ADDR_REGEXP
4454
elif c == '*':
45-
result += '.*'
55+
result += OSC_ADDR_REGEXP + '*'
4656
elif c == '[':
4757
j = pattern.index(']', i)
4858
sub = pattern[i+1:j]
@@ -63,7 +73,7 @@ def translate_pattern(pattern):
6373
else:
6474
result += re.escape(c)
6575
i += 1
66-
return result
76+
return "^" + result + "$"
6777

6878
# read padded string from the beginning of a packet and return (value, tail)
6979
def read_string(packet):

examples/echo_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class EchoServer(aiosc.OSCProtocol):
77
def __init__(self):
88
super().__init__(handlers={
99
'/sys/exit': self.exit,
10-
'*': self.echo
10+
'//*': self.echo,
1111
})
1212

1313
def exit(self, *args):

examples/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def protocol_factory():
77
osc = aiosc.OSCProtocol({
8-
'*': lambda addr, path, *args: print(addr, path, args)
8+
'//*': lambda addr, path, *args: print(addr, path, args)
99
})
1010
return osc
1111

0 commit comments

Comments
 (0)