def extract_views_from_urlpatterns(urlpatterns, base='', namespace=None, ignored_modules=None):
    """
    Return a list of views from a list of urlpatterns.

    Each object in the returned list is a tuple: (view_func, regex, name)
    """
    ignored_modules = ignored_modules if ignored_modules else []
    views = []
    for p in urlpatterns:
        if isinstance(p, RegexURLPattern):
            # Handle correct single URL patterns
            try:
                if namespace:
                    name = '{0}:{1}'.format(namespace, p.name)
                else:
                    name = p.name
                if hasattr(p.callback, '__module__'):
                    if p.callback.__module__.split('.')[0] not in ignored_modules:
                        views.append((p.callback, base + p.regex.pattern, name))
                else:
                    views.append((p.callback, base + p.regex.pattern, name))
            except ViewDoesNotExist:
                continue

        elif isinstance(p, RegexURLResolver):
            # Handle include() definitions
            try:
                patterns = p.url_patterns
            except ImportError:
                continue
            views.extend(extract_views_from_urlpatterns(patterns, base + p.regex.pattern,
                namespace=(namespace or p.namespace), ignored_modules=ignored_modules))

        elif hasattr(p, '_get_callback'):
            # Handle string like 'foo.views.view_name' or just function view
            try:
                views.append((p._get_callback(), base + p.regex.pattern, p.name))
            except ViewDoesNotExist:
                continue

        elif hasattr(p, 'url_patterns') or hasattr(p, '_get_url_patterns'):
            # Handle url_patterns objects
            try:
                patterns = p.url_patterns
            except __HOLE__:
                continue
            views.extend(extract_views_from_urlpatterns(patterns, base + p.regex.pattern,
                namespace=namespace, ignored_modules=ignored_modules))
        else:
            raise TypeError("%s does not appear to be a urlpattern object" % p)
    return views
dataset/ETHPy150Open potatolondon/djangae/djangae/contrib/security/commands_utils.py/extract_views_from_urlpatterns