<commit_before>from django import forms
from django.utils.safestring import mark_safe

from .backends import detect_backend, UnknownBackendException, \
    VideoDoesntExistException
from .fields import EmbedVideoField


class AdminVideoWidget(forms.TextInput):
    """
    Widget for video input in administration. If empty it works just like
    :py:class:`django.forms.TextInput`. Otherwise it renders embedded video
    together with input field.

    .. todo::

        Django 1.6 provides better parent for this widget -
        :py:class:`django.forms.URLInput`.

    """

    output_format = u'<div style="float:left" class="video">' \
                    u'{video}<br />{input}</div>' \
                    u'<hr style="visibility: hidden; clear:both">'

    def __init__(self, attrs=None):
        """
        :type attrs: dict
        """
        default_attrs = {'size': '40'}

        if attrs:
            default_attrs.update(attrs)

        super(AdminVideoWidget, self).__init__(default_attrs)

    def render(self, name, value='', attrs=None, size=(420, 315)):
        """
        :type name: str
        :type attrs: dict
        """
        output = super(AdminVideoWidget, self).render(name, value, attrs)

        if not value:
            return output

        try:
            backend = detect_backend(value)<commit_msg>Add renderer kwarg to Widget render method to support Python 2.1 and later. (#88)<commit_after>from django import forms, VERSION
from django.utils.safestring import mark_safe

from .backends import detect_backend, UnknownBackendException, \
    VideoDoesntExistException
from .fields import EmbedVideoField


class AdminVideoWidget(forms.TextInput):
    """
    Widget for video input in administration. If empty it works just like
    :py:class:`django.forms.TextInput`. Otherwise it renders embedded video
    together with input field.

    .. todo::

        Django 1.6 provides better parent for this widget -
        :py:class:`django.forms.URLInput`.

    """

    output_format = u'<div style="float:left" class="video">' \
                    u'{video}<br />{input}</div>' \
                    u'<hr style="visibility: hidden; clear:both">'

    def __init__(self, attrs=None):
        """
        :type attrs: dict
        """
        default_attrs = {'size': '40'}

        if attrs:
            default_attrs.update(attrs)

        super(AdminVideoWidget, self).__init__(default_attrs)

    def render(self, name, value='', attrs=None, size=(420, 315), renderer=None):
        """
        :type name: str
        :type attrs: dict
        """

        if VERSION < (1, 11):
            # The renderer argument was added in 1.11.
            # https://docs.djangoproject.com/en/1.11/ref/forms/widgets/#django.forms.Widget.render
            output = super(AdminVideoWidget, self).render(name, value, attrs)
        else:
            # Support for Widget.render() methods without the renderer argument is removed in 2.1
            output = super(AdminVideoWidget, self).render(name, value, attrs, renderer)

        if not value:
            return output

        try:
            backend = detect_backend(value)
{'fraction_non_alphanumeric': 0.11012937835279268, 'fraction_numerical': 0.011044493531082361, 'mean_word_length': 2.438177874186551, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 1, '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': '4399060', 'n_tokens_mistral': 916, 'n_tokens_neox': 871, 'n_words': 249}