# Path: easymode/middleware.py
# USE_SHORT_LANGUAGE_CODES = getattr(settings, 'USE_SHORT_LANGUAGE_CODES', False)
# MATCH_LANGUAGE_CODE = re.compile(
#     r"^/(%s)/.*" % "|".join(map(lambda l: l[0], settings.LANGUAGES)))
# MATCH_SHORT_LANGUAGE_CODE = re.compile(
#     r"^/(%s)/.*" % "|".join(get_short_language_codes()))
#     HREF_REGEX = re.compile(
#         ur'<a([^>]+)href="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l + "/" , get_short_language_codes())), 
#             settings.MEDIA_URL[1:], 
#             settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
#     FORM_REGEX = re.compile(
#         ur'<form([^>]+)action="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l + "/" , get_short_language_codes())),
#              settings.MEDIA_URL[1:],
#              settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
#     HREF_REGEX = re.compile(
#         ur'<a([^>]+)href="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l[0] + "/" , settings.LANGUAGES)), 
#             settings.MEDIA_URL[1:], 
#             settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
#     FORM_REGEX = re.compile(
#         ur'<form([^>]+)action="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l[0] + "/" , settings.LANGUAGES)),
#              settings.MEDIA_URL[1:],
#              settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
# def has_lang_prefix(path):
#     def process_response(self, request, response):
#     def process_request(self, request):
#     def process_response(self, request, response):
#     def process_response(self, request, response):
#     def process_request(self, request):
#     def process_response(self, request, response):
# class NoVaryOnCookieSessionMiddleWare(SessionMiddleware):
# class LocaleFromUrlMiddleWare(LocaleMiddleware):
# class LocaliseUrlsMiddleware(object):
# class ShortLocaleFromUrlMiddleWare(LocaleFromUrlMiddleWare):
# class ShortLocaleLocaliseUrlsMiddleware(LocaliseUrlsMiddleware):
# 
# Path: easymode/utils/languagecode.py
# USE_SHORT_LANGUAGE_CODES = getattr(settings, 'USE_SHORT_LANGUAGE_CODES', False)
#     STRIP_LANGUAGE_CODE_REGEX = re.compile(ur'/(?:%s)/' % "|".join(get_short_language_codes()))
#     STRIP_LANGUAGE_CODE_REGEX = re.compile(ur'/(?:%s)/' % "|".join(get_language_codes()))
# def get_language_codes():
# def get_short_language_codes():
# def get_all_language_codes():
# def get_shorthand_from_language_code(locale):
# def get_language_code_from_shorthand(short_locale):
# def strip_language_code(url):
# def fix_language_code(url, current_language):
# def get_real_fieldname(field, lang):
# def localize_fieldnames(fields, internationalized_fields):
# def get_language_codes_as_disjunction():


from django.conf import settings
from django.http import HttpResponse
from django.test import TestCase
from django.utils.decorators import decorator_from_middleware
from easymode import middleware
from easymode.tests.testcases import initdb
from easymode.utils import languagecode
        The LocaliseUrlsMiddleware should insert a short version of the
        languagecode as a slug in all anchor tags that do not yet have a
        langugage
        """
        
        self.settingsManager.set(USE_SHORT_LANGUAGE_CODES=True)
        reload(languagecode)

        result = localise_urls_middleware_view(type('RequestMock', tuple(), {'path':'koek', 'LANGUAGE_CODE':'en-us'}))
            
        self.assertContains(result,'href="/en/example/modifyme.html')
        self.assertContains(result, 'href="/en/example/staysthesame.html')
        self.assertContains(result, 'href="/en/xx/notareallangugaecode.html')
        self.assertContains(result, 'href="/de/reallanguagecode.html"')


@decorator_from_middleware(middleware.LocaleFromUrlMiddleWare)
def locale_from_url_middle_ware_view(request):
    return HttpResponse(request.LANGUAGE_CODE)

@initdb
class TestLocaleFromUrlMiddleWare(TestCase):
    "Test the LocaleFromUrlMiddleWare"
    
    def setUp(self):
        self.RequestMockShort = type('RequestMockShort', tuple(), {'path_info':'/en/hi.html', 'set_cookie':lambda x, y, z: x})
        self.RequestMockLong = type('RequestMockLong', tuple(), {'path_info':'/en-us/hi.html', 'set_cookie':lambda x, y, z: x})
    
    def tearDown(self):
        self.settingsManager.revert()

# Path: easymode/middleware.py
# USE_SHORT_LANGUAGE_CODES = getattr(settings, 'USE_SHORT_LANGUAGE_CODES', False)
# MATCH_LANGUAGE_CODE = re.compile(
#     r"^/(%s)/.*" % "|".join(map(lambda l: l[0], settings.LANGUAGES)))
# MATCH_SHORT_LANGUAGE_CODE = re.compile(
#     r"^/(%s)/.*" % "|".join(get_short_language_codes()))
#     HREF_REGEX = re.compile(
#         ur'<a([^>]+)href="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l + "/" , get_short_language_codes())), 
#             settings.MEDIA_URL[1:], 
#             settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
#     FORM_REGEX = re.compile(
#         ur'<form([^>]+)action="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l + "/" , get_short_language_codes())),
#              settings.MEDIA_URL[1:],
#              settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
#     HREF_REGEX = re.compile(
#         ur'<a([^>]+)href="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l[0] + "/" , settings.LANGUAGES)), 
#             settings.MEDIA_URL[1:], 
#             settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
#     FORM_REGEX = re.compile(
#         ur'<form([^>]+)action="/(?!(%s|%s|%s))([^"]*)"([^>]*)>' % (
#             "|".join(map(lambda l: l[0] + "/" , settings.LANGUAGES)),
#              settings.MEDIA_URL[1:],
#              settings.ADMIN_MEDIA_PREFIX[1:]
#         )
#     )
# def has_lang_prefix(path):
#     def process_response(self, request, response):
#     def process_request(self, request):
#     def process_response(self, request, response):
#     def process_response(self, request, response):
#     def process_request(self, request):
#     def process_response(self, request, response):
# class NoVaryOnCookieSessionMiddleWare(SessionMiddleware):
# class LocaleFromUrlMiddleWare(LocaleMiddleware):
# class LocaliseUrlsMiddleware(object):
# class ShortLocaleFromUrlMiddleWare(LocaleFromUrlMiddleWare):
# class ShortLocaleLocaliseUrlsMiddleware(LocaliseUrlsMiddleware):
# 
# Path: easymode/utils/languagecode.py
# USE_SHORT_LANGUAGE_CODES = getattr(settings, 'USE_SHORT_LANGUAGE_CODES', False)
#     STRIP_LANGUAGE_CODE_REGEX = re.compile(ur'/(?:%s)/' % "|".join(get_short_language_codes()))
#     STRIP_LANGUAGE_CODE_REGEX = re.compile(ur'/(?:%s)/' % "|".join(get_language_codes()))
# def get_language_codes():
# def get_short_language_codes():
# def get_all_language_codes():
# def get_shorthand_from_language_code(locale):
# def get_language_code_from_shorthand(short_locale):
# def strip_language_code(url):
# def fix_language_code(url, current_language):
# def get_real_fieldname(field, lang):
# def localize_fieldnames(fields, internationalized_fields):
# def get_language_codes_as_disjunction():


# Path: easymode/tests/testcases/testmiddleware.py
from django.conf import settings
from django.http import HttpResponse
from django.test import TestCase
from django.utils.decorators import decorator_from_middleware
from easymode import middleware
from easymode.tests.testcases import initdb
from easymode.utils import languagecode

        The LocaliseUrlsMiddleware should insert a short version of the
        languagecode as a slug in all anchor tags that do not yet have a
        langugage
        """
        
        self.settingsManager.set(USE_SHORT_LANGUAGE_CODES=True)
        reload(languagecode)

        result = localise_urls_middleware_view(type('RequestMock', tuple(), {'path':'koek', 'LANGUAGE_CODE':'en-us'}))
            
        self.assertContains(result,'href="/en/example/modifyme.html')
        self.assertContains(result, 'href="/en/example/staysthesame.html')
        self.assertContains(result, 'href="/en/xx/notareallangugaecode.html')
        self.assertContains(result, 'href="/de/reallanguagecode.html"')


@decorator_from_middleware(middleware.LocaleFromUrlMiddleWare)
def locale_from_url_middle_ware_view(request):
    return HttpResponse(request.LANGUAGE_CODE)

@initdb
class TestLocaleFromUrlMiddleWare(TestCase):
    "Test the LocaleFromUrlMiddleWare"
    
    def setUp(self):
        self.RequestMockShort = type('RequestMockShort', tuple(), {'path_info':'/en/hi.html', 'set_cookie':lambda x, y, z: x})
        self.RequestMockLong = type('RequestMockLong', tuple(), {'path_info':'/en-us/hi.html', 'set_cookie':lambda x, y, z: x})
    
    def tearDown(self):
        self.settingsManager.revert()

        reload(languagecode)