def send_bundle(self, messages, ip_address, port, timetag=None, sock=None, safer=False): """Shortcut to the client's `send_bundle` method. Use the `default_socket` of the server by default. See `client.send_bundle` for more info about the parameters. """ if not sock and self.default_socket: sock = self.default_socket elif not sock: raise RuntimeError('no default socket yet and no socket provided') stats = send_bundle(messages, ip_address, port, sock=sock, safer=safer, encoding=self.encoding, encoding_errors=self.encoding_errors) self.stats_sent += stats return stats
def test_send_bundle(): osc = OSCThreadServer() sock = osc.listen() port = sock.getsockname()[1] acc = [] def success(*values): acc.append(values[0]) osc.bind(b'/success', success, sock) timeout = time() + 5 while len(acc) < 100: if time() > timeout: raise OSError('timeout while waiting for success message.') send_bundle([(b'/success', [i]) for i in range(10)], 'localhost', port)
def test_advanced_matching(): osc = OSCThreadServer(advanced_matching=True) osc.listen(default=True) port = osc.getaddress()[1] result = {} def save_result(f): name = f.__name__ def wrapped(*args): r = result.get(name, []) r.append(args) result[name] = r return f(*args) return wrapped @osc.address(b'/?') @save_result def singlechar(*values): pass @osc.address(b'/??') @save_result def twochars(*values): pass @osc.address(b'/prefix*') @save_result def prefix(*values): pass @osc.address(b'/*suffix') @save_result def suffix(*values): pass @osc.address(b'/[abcd]') @save_result def somechars(*values): pass @osc.address(b'/{string1,string2}') @save_result def somestrings(*values): pass @osc.address(b'/part1/part2') @save_result def parts(*values): pass @osc.address(b'/part1/*/part3') @save_result def parts_star(*values): pass @osc.address(b'/part1/part2/?') @save_result def parts_prefix(*values): pass @osc.address(b'/part1/[abcd]/part3') @save_result def parts_somechars(*values): pass @osc.address(b'/part1/[c-f]/part3') @save_result def parts_somecharsrange(*values): pass @osc.address(b'/part1/[!abcd]/part3') @save_result def parts_notsomechars(*values): pass @osc.address(b'/part1/[!c-f]/part3') @save_result def parts_notsomecharsrange(*values): pass @osc.address(b'/part1/{string1,string2}/part3') @save_result def parts_somestrings(*values): pass @osc.address(b'/part1/part2/{string1,string2}') @save_result def parts_somestrings2(*values): pass @osc.address(b'/part1/part2/prefix-{string1,string2}') @save_result def parts_somestrings3(*values): pass send_bundle(( (b'/a', [1]), (b'/b', [2]), (b'/z', [3]), (b'/1', [3]), (b'/?', [4]), (b'/ab', [5]), (b'/bb', [6]), (b'/z?', [7]), (b'/??', [8]), (b'/?*', [9]), (b'/prefixab', [10]), (b'/prefixbb', [11]), (b'/prefixz?', [12]), (b'/prefix??', [13]), (b'/prefix?*', [14]), (b'/absuffix', [15]), (b'/bbsuffix', [16]), (b'/z?suffix', [17]), (b'/??suffix', [18]), (b'/?*suffix', [19]), (b'/string1', [20]), (b'/string2', [21]), (b'/string1aa', [22]), (b'/string1b', [23]), (b'/string1?', [24]), (b'/astring1?', [25]), (b'/part1', [26]), (b'/part1/part', [27]), (b'/part1/part2', [28]), (b'/part1/part3/part2', [29]), (b'/part1/part2/part3', [30]), (b'/part1/part?/part2', [31]), (b'/part1', [32]), (b'/part1/a/part', [33]), (b'/part1/b/part2', [34]), (b'/part1/c/part3/part2', [35]), (b'/part1/d/part2/part3', [36]), (b'/part1/e/part?/part2', [37]), (b'/part1/test/part2', [38]), (b'/part1/a/part2', [39]), (b'/part1/b/part2', [40]), (b'/part1/c/part2/part2', [41]), (b'/part1/d/part2/part3', [42]), (b'/part1/0/part2', [43]), (b'/part1/string1/part', [45]), (b'/part1/string2/part3', [46]), (b'/part1/part2/string1', [47]), (b'/part1/part2/string2', [48]), (b'/part1/part2/prefix-string1', [49]), (b'/part1/part2/sprefix-tring2', [50]), ), 'localhost', port) expected = { 'singlechar': [(1, ), (2, ), (3, ), (3, ), (4, )], 'twochars': [(5, ), (6, ), (7, ), (8, ), (9, )], 'prefix': [(10, ), (11, ), (12, ), (13, ), (14, )], 'suffix': [(15, ), (16, ), (17, ), (18, ), (19, )], 'somechars': [(1, ), (2, )], 'somestrings': [(20, ), (21, )], 'parts': [(28, )], 'parts_star': [(30, ), (46, )], 'parts_somestrings': [(46, )], 'parts_somestrings2': [(47, ), (48, )], 'parts_somestrings3': [(49, )] } timeout = time() + 5 while result != expected: if time() > timeout: print("expected: {}\n result: {}\n".format(expected, result)) raise OSError('timeout while waiting for expected result.') sleep(10e-9)