How to use the s2protocol.s2_cli.EventFilter function in s2protocol

To help you get started, we’ve selected a few s2protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blizzard / s2protocol / s2protocol / s2_cli.py View on Github external
def process(self, event):
        print(json_dump(event), file=self._output)
        return event


class PrettyPrintFilter(EventFilter):
    """ Add as a filter will send objects to stdout """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        pprint.pprint(event, stream=self._output)
        return event


class TypeDumpFilter(EventFilter):
    """ Add as a filter to convert events into type information """
    def process(self, event):
        def recurse_into(value):
            if type(value) is list:
                decoded = []
                for item in value:
                    decoded.append(recurse_into(item))
                return decoded
            elif type(value) is dict:
                decoded = {}
                for key, inner_value in value.items():
                    decoded[key] = recurse_into(inner_value)
                return decoded
            return (type(value).__name__, value)
        return recurse_into(event)
github Blizzard / s2protocol / s2protocol / s2_cli.py View on Github external
def recurse_into(value):
            if type(value) is list:
                decoded = []
                for item in value:
                    decoded.append(recurse_into(item))
                return decoded
            elif type(value) is dict:
                decoded = {}
                for key, inner_value in value.items():
                    decoded[key] = recurse_into(inner_value)
                return decoded
            return (type(value).__name__, value)
        return recurse_into(event)
    

class StatCollectionFilter(EventFilter):
    """ Add as a filter to collect stats on events """
    def __init__(self):
        self._event_stats = {}

    def process(self, event):
        # update stats
        if '_event' in event and '_bits' in event:
            stat = self._event_stats.get(event['_event'], [0, 0])
            stat[0] += 1  # count of events
            stat[1] += event['_bits']  # count of bits
            self._event_stats[event['_event']] = stat
        return event

    def finish(self):
        print('Name, Count, Bits')
        for name, stat in sorted(self._event_stats.items(), key=lambda x: x[1][1]):
github Blizzard / s2protocol / s2protocol / s2_cli.py View on Github external
return o

    return json.dumps(dispatch(obj), indent=indent)


class EventFilter(object):
    def process(self, event):
        """ Called for each event in the replay stream """
        return event

    def finish(self):
        """ Called when the stream has finished """
        pass


class JSONOutputFilter(EventFilter):
    """ Added as a filter will format the event into JSON """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        print(json_dump(event, indent=4), file=self._output)
        return event


class NDJSONOutputFilter(EventFilter):
    """ Added as a filter will format the event into NDJSON """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        print(json_dump(event), file=self._output)
github Blizzard / s2protocol / s2protocol / s2_cli.py View on Github external
def finish(self):
        """ Called when the stream has finished """
        pass


class JSONOutputFilter(EventFilter):
    """ Added as a filter will format the event into JSON """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        print(json_dump(event, indent=4), file=self._output)
        return event


class NDJSONOutputFilter(EventFilter):
    """ Added as a filter will format the event into NDJSON """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        print(json_dump(event), file=self._output)
        return event


class PrettyPrintFilter(EventFilter):
    """ Add as a filter will send objects to stdout """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        pprint.pprint(event, stream=self._output)
github Blizzard / s2protocol / s2protocol / s2_cli.py View on Github external
def process(self, event):
        print(json_dump(event, indent=4), file=self._output)
        return event


class NDJSONOutputFilter(EventFilter):
    """ Added as a filter will format the event into NDJSON """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        print(json_dump(event), file=self._output)
        return event


class PrettyPrintFilter(EventFilter):
    """ Add as a filter will send objects to stdout """
    def __init__(self, output):
        self._output = output

    def process(self, event):
        pprint.pprint(event, stream=self._output)
        return event


class TypeDumpFilter(EventFilter):
    """ Add as a filter to convert events into type information """
    def process(self, event):
        def recurse_into(value):
            if type(value) is list:
                decoded = []
                for item in value: