<commit_before>import urllib
import urllib2

from django.template import Context
from django.template.loader import render_to_string

from . import app_settings

def hipchat_message(template, context=None, fail_silently=False):
    """

     * Add ``django_hipchat`` to ``INSTALLED_APPS``

     * Ensure ``django.template.loaders.app_directories.Loader`` is in your
       ``TEMPLATE_LOADERS``.

    >>> from django_hipchat.api import message
    >>> message("path/to/my_message.hipchat", {
        'foo': Foo.objects.get(pk=17),
    })

    path/to/my_message.hipchat::

        {% extends django_hipchat %}

        {% block room_id %}
        Room to spam
        {% endblock %}

        {% block message %}
        Message text here: {{ foo.bar|urlize }}
        {% endblock %}

        {% block color %}
        red
        {% endblock %}

    Required blocks:

     * message

    Required blocks which can be defaulted globally and overriden:

     * auth_token
     * room_id
     * from

    Optional blocks:

     * color
    """

    if not app_settings.ENABLED:
        return

    context = Context(context or {})

    def render(component):
        component_template = 'django_hipchat/%s' % component

        return render_to_string(template, {
            'django_hipchat': component_template,
        }, context).strip().encode('utf8', 'ignore')

    data = {
        'from': app_settings.MESSAGE_FROM,
        'color': 'yellow',
        'message': '',
        'room_id': app_settings.MESSAGE_ROOM,
        'auth_token': app_settings.AUTH_TOKEN,
        'message_format': 'html',
    }

    for part in ('auth_token', 'room_id', 'message', 'color', 'from'):
        try:<commit_msg>Allow us to see django.conf.settings in our messages.<commit_after>import urllib
import urllib2

from django.conf import settings
from django.template import Context
from django.template.loader import render_to_string

from . import app_settings

def hipchat_message(template, context=None, fail_silently=False):
    """

     * Add ``django_hipchat`` to ``INSTALLED_APPS``

     * Ensure ``django.template.loaders.app_directories.Loader`` is in your
       ``TEMPLATE_LOADERS``.

    >>> from django_hipchat.api import message
    >>> message("path/to/my_message.hipchat", {
        'foo': Foo.objects.get(pk=17),
    })

    path/to/my_message.hipchat::

        {% extends django_hipchat %}

        {% block room_id %}
        Room to spam
        {% endblock %}

        {% block message %}
        Message text here: {{ foo.bar|urlize }}
        {% endblock %}

        {% block color %}
        red
        {% endblock %}

    Required blocks:

     * message

    Required blocks which can be defaulted globally and overriden:

     * auth_token
     * room_id
     * from

    Optional blocks:

     * color
    """

    if not app_settings.ENABLED:
        return

    context = Context(context or {})

    context['settings'] = settings

    def render(component):
        component_template = 'django_hipchat/%s' % component

        return render_to_string(template, {
            'django_hipchat': component_template,
        }, context).strip().encode('utf8', 'ignore')

    data = {
        'from': app_settings.MESSAGE_FROM,
        'color': 'yellow',
        'message': '',
        'room_id': app_settings.MESSAGE_ROOM,
        'auth_token': app_settings.AUTH_TOKEN,
        'message_format': 'html',
    }

    for part in ('auth_token', 'room_id', 'message', 'color', 'from'):
        try:
{'fraction_non_alphanumeric': 0.12111712738671987, 'fraction_numerical': 0.002279851809632374, 'mean_word_length': 2.489065606361829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5963989', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1018, 'n_words': 238}