def find_template(self, name, context, peeking=False):
        """
        Replacement for Django's ``find_template`` that uses the current
        template context to keep track of which template directories it
        has used when finding a template. This allows multiple templates
        with the same relative name/path to be discovered, so that
        circular template inheritance can occur.
        """

        # These imports want settings, which aren't available when this
        # module is imported to ``add_to_builtins``, so do them here.
        from django.conf import settings

        # Find the app_template_dirs (moved in Django 1.8)
        import django.template.loaders.app_directories as app_directories
        try:
            # Django >= 1.8
            get_app_template_dirs = app_directories.get_app_template_dirs
            app_template_dirs = get_app_template_dirs('templates')
        except AttributeError:
            # Django <= 1.7
            app_template_dirs = app_directories.app_template_dirs
        
        # Find the find_template_loader function, and appropriate template
        # settings (changed in Django 1.8)
        try:
            # Django >= 1.8
            find_template_loader = context.template.engine.find_template_loader
            template_dirs = context.template.engine.dirs
            template_loaders = context.template.engine.loaders
        except __HOLE__:
            # Django <= 1.7
            from django.template.loader import find_template_loader
            template_dirs = list(settings.TEMPLATE_DIRS)
            template_loaders = settings.TEMPLATE_LOADERS
        
        # Store a dictionary in the template context mapping template
        # names to the lists of template directories available to
        # search for that template. Each time a template is loaded, its
        # origin directory is removed from its directories list.
        context_name = "OVEREXTENDS_DIRS"
        if context_name not in context:
            context[context_name] = {}
        if name not in context[context_name]:
            all_dirs = template_dirs + list(app_template_dirs)
            # os.path.abspath is needed under uWSGI, and also ensures we
            # have consistent path separators across different OSes.
            context[context_name][name] = list(map(os.path.abspath, all_dirs))

        # Build a list of template loaders to use. For loaders that wrap
        # other loaders like the ``cached`` template loader, unwind its
        # internal loaders and add those instead.
        loaders = []
        for loader_name in template_loaders:
            loader = find_template_loader(loader_name)
            loaders.extend(getattr(loader, "loaders", [loader]))

        # Go through the loaders and try to find the template. When
        # found, removed its absolute path from the context dict so
        # that it won't be used again when the same relative name/path
        # is requested.
        for loader in loaders:
            dirs = context[context_name][name]
            if not dirs:
                break
            try:
                source, path = loader.load_template_source(name, dirs)
            except TemplateDoesNotExist:
                pass
            else:
                # Only remove the absolute path for the initial call in
                # get_parent, and not when we're peeking during the
                # second call.
                if not peeking:
                    remove_path = os.path.abspath(path[:-len(name) - 1])
                    context[context_name][name].remove(remove_path)
                return Template(source)
        raise TemplateDoesNotExist(name)
dataset/ETHPy150Open stephenmcd/django-overextends/overextends/templatetags/overextends_tags.py/OverExtendsNode.find_template