<commit_before>from django.conf.urls.defaults import url
from rest_framework.settings import api_settings


def format_suffix_patterns(urlpatterns, suffix_required=False, suffix_kwarg=None):
    """
    Supplement existing urlpatterns with corrosponding patterns that also
    include a '.format' suffix.  Retains urlpattern ordering.
    """
    suffix_kwarg = suffix_kwarg or api_settings.FORMAT_SUFFIX_KWARG
    suffix_pattern = '\.(?P<%s>[a-z]+)$' % suffix_kwarg

    ret = []
    for urlpattern in urlpatterns:
        # Form our complementing '.format' urlpattern
        regex = urlpattern.regex.pattern.rstrip('$') + suffix_pattern
        view = urlpattern._callback or urlpattern._callback_str
        kwargs = urlpattern.default_args
        name = urlpattern.name
        # Add in both the existing and the new urlpattern
        if not suffix_required:
            ret.append(urlpattern)
        ret.append(url(regex, view, kwargs, name))
    return ret<commit_msg>Fix bug in format suffix patterns<commit_after>from django.conf.urls.defaults import url
from rest_framework.settings import api_settings


def format_suffix_patterns(urlpatterns, suffix_required=False, suffix_kwarg=None):
    """
    Supplement existing urlpatterns with corrosponding patterns that also
    include a '.format' suffix.  Retains urlpattern ordering.
    """
    suffix_kwarg = suffix_kwarg or api_settings.FORMAT_SUFFIX_KWARG
    suffix_pattern = r'\.(?P<%s>[a-z]+)$' % suffix_kwarg

    ret = []
    for urlpattern in urlpatterns:
        # Form our complementing '.format' urlpattern
        regex = urlpattern.regex.pattern.rstrip('$') + suffix_pattern
        view = urlpattern._callback or urlpattern._callback_str
        kwargs = urlpattern.default_args
        name = urlpattern.name
        # Add in both the existing and the new urlpattern
        if not suffix_required:
            ret.append(urlpattern)
        ret.append(url(regex, view, kwargs, name))
    return ret
{'fraction_non_alphanumeric': 0.08295397066262013, 'fraction_numerical': 0.0, 'mean_word_length': 3.356828193832599, 'pattern_counts': {'":': 0, '<': 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': '2242424', 'n_tokens_mistral': 563, 'n_tokens_neox': 556, 'n_words': 152}