<commit_before>import json
from tornado import gen, httpclient as hc

from . import AbstractHandler, LOGGER


class HipChatHandler(AbstractHandler):

    name = 'hipchat'

    # Default options
    defaults = {
        'url': 'https://api.hipchat.com',
        'room': None,
        'key': None,
    }

    colors = {
        'critical': 'red',
        'warning': 'yellow',
        'normal': 'green',
    }

    def init_handler(self):
        self.room = self.options.get('room')
        self.key = self.options.get('key')
        assert self.room, 'Hipchat room is not defined.'
        assert self.key, 'Hipchat key is not defined.'
        self.client = hc.AsyncHTTPClient()

    @gen.coroutine
    def notify(self, level, *args, **kwargs):
        LOGGER.debug("Handler (%s) %s", self.name, level)

        data = {
            'message': self.get_short(level, *args, **kwargs).decode('UTF-8'),
            'notify': True,
            'color': self.colors.get(level, 'gray'),
            'message_format': 'text',
        }

        yield self.client.fetch('{url}/v2/room/{room}/notification?auth_token={token}'.format(
            url=self.options.url, room=self.room, token=self.key),
            headers={'Content-Type': 'application/json'}, method='POST', body=json.dumps(data))<commit_msg>Update hipchat.py<commit_after>import json
from tornado import gen, httpclient as hc

from . import AbstractHandler, LOGGER


class HipChatHandler(AbstractHandler):

    name = 'hipchat'

    # Default options
    defaults = {
        'url': 'https://api.hipchat.com',
        'room': None,
        'key': None,
    }

    colors = {
        'critical': 'red',
        'warning': 'yellow',
        'normal': 'green',
    }

    def init_handler(self):
        self.room = self.options.get('room')
        self.key = self.options.get('key')
        assert self.room, 'Hipchat room is not defined.'
        assert self.key, 'Hipchat key is not defined.'
        self.client = hc.AsyncHTTPClient()

    @gen.coroutine
    def notify(self, level, *args, **kwargs):
        LOGGER.debug("Handler (%s) %s", self.name, level)

        data = {
            'message': self.get_short(level, *args, **kwargs).decode('UTF-8'),
            'notify': True,
            'color': self.colors.get(level, 'gray'),
            'message_format': 'text',
        }

        yield self.client.fetch('{url}/v2/room/{room}/notification?auth_token={token}'.format(
            url=self.options.get('url'), room=self.room, token=self.key),
            headers={'Content-Type': 'application/json'}, method='POST', body=json.dumps(data))
{'fraction_non_alphanumeric': 0.15906477577615946, 'fraction_numerical': 0.0015331544653123803, 'mean_word_length': 2.438735177865613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4105280', 'n_tokens_mistral': 813, 'n_tokens_neox': 796, 'n_words': 174}