def parse(self, prefix, command, params): field_rex = r"([^\s=]+)='([^']*)'" data_rex = r"^([^\s>]+)>\s*(("+ field_rex +"\s*,?\s*)*)\s*$" match = re.match(data_rex, util.guess_encoding(params[-1])) if not match: return None event = events.Event() event.add("type", match.group(1)) fields = re.findall(field_rex, match.group(2) or "") for key, value in fields: event.add(key, value) return event
def __init__(self, data, **formatters): self.data = guess_encoding(data) self.formatters = formatters