<commit_before>from datetime import date
import random

from django.core.cache import cache
from django.conf import settings
try:
    # Django >= 1.4.3
    from django.utils.http import is_safe_url
except ImportError:
    import urlparse
    def is_safe_url(url, host=None):
        '''
        Copied from Django 1.4.10:
        https://github.com/django/django/blob/1.4.10/django/utils/http.py#L228
        '''
        if not url:
            return False
        url_info = urlparse.urlparse(url)
        return (not url_info[1] or url_info[1] == host) and \
            (not url_info[0] or url_info[0] in ['http', 'https'])

from preferences import preferences


_foundry_utils_cache = {}


def _build_view_names_recurse(url_patterns=None):
    """
    Returns a tuple of url pattern names suitable for use as field choices
    """
    if url_patterns is None:
        urlconf = settings.ROOT_URLCONF
        url_patterns = __import__(settings.ROOT_URLCONF, globals(), locals(), \
                ['urlpatterns', ], -1).urlpatterns

    result = []
    for pattern in url_patterns:
        try:
            # Rules: (1) named patterns (2) may not contain arguments.
            if pattern.name is not None:
                if pattern.regex.pattern.find('<') == -1:
                    result.append((pattern.name, pattern.name))
        except AttributeError:
            # If the pattern itself is an include, recursively fetch its
            # patterns. Ignore admin patterns.
            if not pattern.regex.pattern.startswith('^admin'):
                try:
                    result += _build_view_names_recurse(pattern.url_patterns)
                except AttributeError:
                    pass
    return result

<commit_msg>Make view lookups namespace aware<commit_after>from datetime import date
import random

from django.core.cache import cache
from django.conf import settings
try:
    # Django >= 1.4.3
    from django.utils.http import is_safe_url
except ImportError:
    import urlparse
    def is_safe_url(url, host=None):
        '''
        Copied from Django 1.4.10:
        https://github.com/django/django/blob/1.4.10/django/utils/http.py#L228
        '''
        if not url:
            return False
        url_info = urlparse.urlparse(url)
        return (not url_info[1] or url_info[1] == host) and \
            (not url_info[0] or url_info[0] in ['http', 'https'])

from preferences import preferences


_foundry_utils_cache = {}


def _build_view_names_recurse(url_patterns=None, namespace=None):
    """
    Returns a tuple of url pattern names suitable for use as field choices
    """
    if url_patterns is None:
        urlconf = settings.ROOT_URLCONF
        url_patterns = __import__(settings.ROOT_URLCONF, globals(), locals(), \
                ['urlpatterns', ], -1).urlpatterns

    result = []
    for pattern in url_patterns:
        try:
            # Rules: (1) named patterns (2) may not contain arguments.
            if pattern.name is not None:
                if pattern.regex.pattern.find('<') == -1:
                    key = ""
                    if namespace:
                        key = namespace + ":"
                    key += pattern.name
                    result.append((key, key))
        except AttributeError:
            # If the pattern itself is an include, recursively fetch its
            # patterns. Ignore admin patterns.
            if not pattern.regex.pattern.startswith('^admin'):
                try:
                    result += _build_view_names_recurse(pattern.url_patterns, pattern.namespace)
                except AttributeError:
                    pass
    return result


{'fraction_non_alphanumeric': 0.09269356597600872, 'fraction_numerical': 0.011995637949836423, 'mean_word_length': 2.037251655629139, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, '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': '4070750', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1005, 'n_words': 289}