def __init__(self, x=None): if x is None: _broker.Data.__init__(self) elif isinstance(x, zeek.Event): _broker.Data.__init__(self, x.as_data()) elif isinstance(x, _broker.Data): _broker.Data.__init__(self, x) elif isinstance( x, (bool, int, float, str, bytes, Address, Count, Enum, Port, Set, Subnet, Table, Timespan, Timestamp, Vector)): _broker.Data.__init__(self, x) elif isinstance(x, datetime.timedelta): us = x.microseconds + (x.seconds + x.days * 24 * 3600) * 10**6 ns = us * 10**3 _broker.Data.__init__(self, _broker.Timespan(ns)) elif isinstance(x, datetime.datetime): secs = x.timestamp() _broker.Data.__init__(self, _broker.Timestamp(secs)) elif isinstance(x, ipaddress.IPv4Address): _broker.Data.__init__(self, _broker.Address(x.packed, 4)) elif isinstance(x, ipaddress.IPv6Address): _broker.Data.__init__(self, _broker.Address(x.packed, 6)) elif isinstance(x, ipaddress.IPv4Network): address = _broker.Address(x.network_address.packed, 4) length = x.prefixlen _broker.Data.__init__(self, _broker.Subnet(address, length)) elif isinstance(x, ipaddress.IPv6Network): address = _broker.Address(x.network_address.packed, 6) length = x.prefixlen _broker.Data.__init__(self, _broker.Subnet(address, length)) elif isinstance(x, list) or isinstance(x, tuple): v = _broker.Vector([Data(i) for i in x]) _broker.Data.__init__(self, v) elif isinstance(x, set): s = _broker.Set(([Data(i) for i in x])) _broker.Data.__init__(self, s) elif isinstance(x, dict): t = _broker.Table() for (k, v) in x.items(): t[Data(k)] = Data(v) _broker.Data.__init__(self, t) else: raise TypeError("unsupported data type: " + str(type(x)))
def publish_batch(self, *batch): batch = [Data.from_py(d) for d in batch] return self._publisher.publish_batch(_broker.Vector(batch))