<commit_before>from django import forms
from django.conf import settings
from django.views import i18n
from django.utils import safestring
from django.utils.translation import ugettext_lazy as _, get_language
from django.contrib.staticfiles.storage import staticfiles_storage

try:
    from django import urls
except ImportError:
    from django.core import urlresolvers as urls

import recurrence
from recurrence import exceptions

# Django 1.5+ compatibility
try:
    import json
except ImportError:
    import django.utils.simplejson as json


class RecurrenceWidget(forms.Textarea):
    def __init__(self, attrs=None, **kwargs):
        self.js_widget_options = kwargs
        defaults = {'class': 'recurrence-widget'}
        if attrs is not None:
            defaults.update(attrs)
        super(RecurrenceWidget, self).__init__(defaults)

    def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        elif isinstance(value, recurrence.Recurrence):
            value = recurrence.serialize(value)

        widget_init_js = (
            '<script type="text/javascript">'
            'recurrence.language_code =\'%s\';'
            'new recurrence.widget.Widget(\'%s\', %s);'
            '</script>'<commit_msg>Django 2.1 compatibility fix for widget render method<commit_after>from django import forms
from django.conf import settings
from django.views import i18n
from django.utils import safestring
from django.utils.translation import ugettext_lazy as _, get_language
from django.contrib.staticfiles.storage import staticfiles_storage

try:
    from django import urls
except ImportError:
    from django.core import urlresolvers as urls

import recurrence
from recurrence import exceptions

# Django 1.5+ compatibility
try:
    import json
except ImportError:
    import django.utils.simplejson as json


class RecurrenceWidget(forms.Textarea):
    def __init__(self, attrs=None, **kwargs):
        self.js_widget_options = kwargs
        defaults = {'class': 'recurrence-widget'}
        if attrs is not None:
            defaults.update(attrs)
        super(RecurrenceWidget, self).__init__(defaults)

    def render(self, name, value, attrs=None, renderer=None):
        if value is None:
            value = ''
        elif isinstance(value, recurrence.Recurrence):
            value = recurrence.serialize(value)

        widget_init_js = (
            '<script type="text/javascript">'
            'recurrence.language_code =\'%s\';'
            'new recurrence.widget.Widget(\'%s\', %s);'
            '</script>'
{'fraction_non_alphanumeric': 0.08984830805134189, 'fraction_numerical': 0.0038895371450797353, 'mean_word_length': 3.121794871794872, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '725147', 'n_tokens_mistral': 715, 'n_tokens_neox': 701, 'n_words': 207}