<commit_before>from importlib import import_module
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
from django.contrib.admindocs.views import simplify_regex

from rest_framework.views import APIView


class UrlParser(object):

    def __init__(self, config, request):
        self.urlconf = getattr(request, "urlconf", None)
        self.exclude_namespaces = config.get('exclude_namespaces', [])
        self.exclude_module_paths = config.get('exclude_module_paths', [])
        self.include_module_paths = config.get('include_module_paths', [])
        self.exclude_url_patterns = config.get('exclude_url_patterns', [])

    def get_apis(self):
        """
        Returns all the DRF APIViews found in the project URLs
        """
        urls = import_module(self.urlconf)
        return self.__flatten_patterns_tree__(urls.urlpatterns)

    def __assemble_endpoint_data__(self, pattern, prefix=''):
        """
        Creates a dictionary for matched API urls

        pattern -- the pattern to parse
        prefix -- the API path prefix (used by recursion)<commit_msg>Modify UrlParser to default urlconf to ROOT_URLCONF if not in request<commit_after>from importlib import import_module
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
from django.contrib.admindocs.views import simplify_regex

from rest_framework.views import APIView
from django.conf import settings

class UrlParser(object):

    def __init__(self, config, request):
        self.urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
        self.exclude_namespaces = config.get('exclude_namespaces', [])
        self.exclude_module_paths = config.get('exclude_module_paths', [])
        self.include_module_paths = config.get('include_module_paths', [])
        self.exclude_url_patterns = config.get('exclude_url_patterns', [])

    def get_apis(self):
        """
        Returns all the DRF APIViews found in the project URLs
        """
        urls = import_module(self.urlconf)
        return self.__flatten_patterns_tree__(urls.urlpatterns)

    def __assemble_endpoint_data__(self, pattern, prefix=''):
        """
        Creates a dictionary for matched API urls

        pattern -- the pattern to parse
        prefix -- the API path prefix (used by recursion)
{'fraction_non_alphanumeric': 0.08778791829639288, 'fraction_numerical': 0.0, 'mean_word_length': 3.604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5537121', 'n_tokens_mistral': 664, 'n_tokens_neox': 637, 'n_words': 163}