# Path: microsite/resolvers.py
# class CountryRegexURLResolver(RegexURLResolver):
#     """
#     A URL resolver that always matches the active language code as URL prefix.
# 
#     Rather than taking a regex argument, we just override the ``regex``
#     function to always return the active language-code as regex.
#     """
#     def __init__(
#         self, urlconf_name, default_kwargs=None, app_name=None, namespace=None,
#         prefix_default_country=False,
#     ):
#         super().__init__(None, urlconf_name, default_kwargs, app_name, namespace)
#         self.prefix_default_country = prefix_default_country
# 
#     @property
#     def regex(self):
#         country_code = get_country_from_thread()
#         if country_code not in self._regex_dict:
#             if country_code == settings.COUNTRY_CODE and not self.prefix_default_country:
#                 regex_string = ''
#             else:
#                 regex_string = '^%s/' % country_code
#             self._regex_dict[country_code] = re.compile(regex_string)
#         return self._regex_dict[country_code]


from django.conf import settings
from .resolvers import CountryRegexURLResolver
from django.core.urlresolvers import get_resolver


def country_patterns(*urls, prefix_default_country=True):
    """
    Adds the country code prefix to every URL pattern within this
    function. This may only be used in the root URLconf, not in an included
    URLconf.
    """
    if not settings.USE_COUNTRY_URL:
        return list(urls)
    return [CountryRegexURLResolver(list(urls), prefix_default_country=prefix_default_country)]


def is_country_prefix_patterns_used(urlconf):

    for url_pattern in get_resolver(urlconf).url_patterns:

# Path: microsite/resolvers.py
# class CountryRegexURLResolver(RegexURLResolver):
#     """
#     A URL resolver that always matches the active language code as URL prefix.
# 
#     Rather than taking a regex argument, we just override the ``regex``
#     function to always return the active language-code as regex.
#     """
#     def __init__(
#         self, urlconf_name, default_kwargs=None, app_name=None, namespace=None,
#         prefix_default_country=False,
#     ):
#         super().__init__(None, urlconf_name, default_kwargs, app_name, namespace)
#         self.prefix_default_country = prefix_default_country
# 
#     @property
#     def regex(self):
#         country_code = get_country_from_thread()
#         if country_code not in self._regex_dict:
#             if country_code == settings.COUNTRY_CODE and not self.prefix_default_country:
#                 regex_string = ''
#             else:
#                 regex_string = '^%s/' % country_code
#             self._regex_dict[country_code] = re.compile(regex_string)
#         return self._regex_dict[country_code]


# Path: microsite/country_urls.py
from django.conf import settings
from .resolvers import CountryRegexURLResolver
from django.core.urlresolvers import get_resolver



def country_patterns(*urls, prefix_default_country=True):
    """
    Adds the country code prefix to every URL pattern within this
    function. This may only be used in the root URLconf, not in an included
    URLconf.
    """
    if not settings.USE_COUNTRY_URL:
        return list(urls)
    return [CountryRegexURLResolver(list(urls), prefix_default_country=prefix_default_country)]


def is_country_prefix_patterns_used(urlconf):

    for url_pattern in get_resolver(urlconf).url_patterns:

        if isinstance(url_pattern, CountryRegexURLResolver):