#!/usr/bin/python
from . import base

registry = base.LookupRegistry()


def url_autodiscover():
    import copy
    from django.conf import settings
    from django.utils.importlib import import_module
    from django.utils.module_loading import module_has_submodule

    for app in settings.INSTALLED_APPS:
        mod = import_module(app)
        # Attempt to import the app's lookups module.
        try:
            before_import_registry = copy.copy(registry._registry)
            import_module('%s.lookups' % app)
        except:
            registry._registry = before_import_registry

            if module_has_submodule(mod, 'lookups'):
                raise
