<commit_before>#!/usr/bin/env python

from __future__ import print_function


import sys
from threading import Thread


from docker import Client


from circuits import handler, Event, Component
from circuits.web import Server, Controller, Logger


class docker_event(Event):
    """Docker Event"""


class container_created(docker_event):
    """Container Created Event"""


class container_destroyed(docker_event):
    """Container Destroyed Event"""


class container_started(docker_event):
    """Container Started Event"""


class container_stopped(docker_event):
    """Container Stopped Event"""


class container_killed(docker_event):
    """Container Killed Event"""


class container_died(docker_event):
    """Container Died Event"""


DOCKER_EVENTS = {
    u"create": container_created,
    u"destroy": container_destroyed,
    u"start": container_started,
    u"stop": container_stopped,
    u"kill": container_killed,
    u"die": container_died,
}


class DockerEventManager(Thread):

    def __init__(self, manager, url):
        super(DockerEventManager, self).__init__()

        self.manager = manager
        self.url = url

        self.daemon = True

        self.client = Client(self.url)

    def run(self):
        for event in self.client.events():
            status = event.pop("status")
            docker_event = DOCKER_EVENTS.get(status)
            if docker_event is not None:
                self.manager.fire(docker_event(**event), "docker")
            else:
                print("WARNING: Unknown Docker Event <{0:s}({1:s})>".format(status, repr(event)), file=sys.tderr)

    def stop(self):
        self.client.close()


class DockerEventLogger(Component):

    channel = "docker"

    @handler("*")
    def log_docker_event(self, event, *args, **kwargs):<commit_msg>Apprently the payload is a byte string whereas before it as json?<commit_after>#!/usr/bin/env python

from __future__ import print_function


import sys
from json import loads
from threading import Thread


from docker import Client


from circuits import handler, Event, Component
from circuits.web import Server, Controller, Logger


class docker_event(Event):
    """Docker Event"""


class container_created(docker_event):
    """Container Created Event"""


class container_destroyed(docker_event):
    """Container Destroyed Event"""


class container_started(docker_event):
    """Container Started Event"""


class container_stopped(docker_event):
    """Container Stopped Event"""


class container_killed(docker_event):
    """Container Killed Event"""


class container_died(docker_event):
    """Container Died Event"""


DOCKER_EVENTS = {
    u"create": container_created,
    u"destroy": container_destroyed,
    u"start": container_started,
    u"stop": container_stopped,
    u"kill": container_killed,
    u"die": container_died,
}


class DockerEventManager(Thread):

    def __init__(self, manager, url):
        super(DockerEventManager, self).__init__()

        self.manager = manager
        self.url = url

        self.daemon = True

        self.client = Client(self.url)

    def run(self):
        for payload in self.client.events():
            event = loads(payload)
            status = event.pop("status")
            docker_event = DOCKER_EVENTS.get(status)
            if docker_event is not None:
                self.manager.fire(docker_event(**event), "docker")
            else:
                print("WARNING: Unknown Docker Event <{0:s}({1:s})>".format(status, repr(event)), file=sys.tderr)

    def stop(self):
        self.client.close()


class DockerEventLogger(Component):

    channel = "docker"

    @handler("*")
    def log_docker_event(self, event, *args, **kwargs):
{'fraction_non_alphanumeric': 0.11445459430413756, 'fraction_numerical': 0.0010746910263299302, 'mean_word_length': 3.426872770511296, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2435361', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1047, 'n_words': 274}