Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, calls=0, bytes=0, params=0, types=None, **kwargs):
self.calls = calls
self.bytes = bytes
self.params = params
self.types = types or Counter()
super(Stats, self).__init__(**kwargs)
def __init__(
self, address, port, sock=None, encoding='', encoding_errors='strict'
):
"""Create an OSCClient.
`address` and `port` are the destination of messages sent
by this client. See `send_message` and `send_bundle` documentation
for more information.
"""
self.address = address
self.port = port
self.sock = sock or SOCK
self.encoding = encoding
self.encoding_errors = encoding_errors
self.stats = Stats()
message = pack(
fmt,
address,
tags,
*(
(
encode_cache.get(v) + NULL if isinstance(v, UNICODE) and encoding
else (v + NULL) if t in (b's', b'b')
else format_midi(v) if isinstance(v, MidiTuple)
else v
)
for t, v in
izip(tags[1:], values)
)
)
return message, Stats(1, len(message), lv, count)
def format_bundle(data, timetag=None, encoding='', encoding_errors='strict'):
"""Create a bundle from a list of (address, values) tuples.
String values will be encoded using `encoding` or must be provided
as bytes.
`encoding_errors` will be used to manage encoding errors.
"""
timetag = time_to_timetag(timetag)
bundle = [pack('8s', b'#bundle\0')]
bundle.append(TIME_TAG.pack(*timetag))
stats = Stats()
for address, values in data:
msg, st = format_message(
address, values, encoding='',
encoding_errors=encoding_errors
)
bundle.append(pack('>i', len(msg)))
bundle.append(msg)
stats += st
return b''.join(bundle), stats
def _send(options):
def _parse(s):
try:
return literal_eval(s)
except:
return s
stats = Stats()
for i in range(options.repeat):
stats += send_message(
options.address,
[_parse(x) for x in options.message],
options.host,
options.port,
safer=options.safer,
encoding=options.encoding,
encoding_errors=options.encoding_errors
)
print(stats)
def __add__(self, other):
assert isinstance(other, Stats)
return Stats(
calls=self.calls + other.calls,
bytes=self.bytes + other.bytes,
params=self.params + other.params,
types=self.types + other.types
)
def __eq__(self, other):
return other is self or (
isinstance(other, Stats)
and self.calls == self.calls
and self.bytes == self.bytes
and self.params == self.params
and self.types == other.types
)