def test_repr(self): class GetResponse: def __call__(self): return HttpResponse() def get_response(): return HttpResponse() self.assertEqual( repr(MiddlewareMixin(GetResponse())), '<MiddlewareMixin get_response=GetResponse>', ) self.assertEqual( repr(MiddlewareMixin(get_response)), '<MiddlewareMixin get_response=' 'MiddlewareMixinTests.test_repr.<locals>.get_response>', ) self.assertEqual( repr(CsrfViewMiddleware(GetResponse())), '<CsrfViewMiddleware get_response=GetResponse>', ) self.assertEqual( repr(CsrfViewMiddleware(get_response)), '<CsrfViewMiddleware get_response=' 'MiddlewareMixinTests.test_repr.<locals>.get_response>', )
def __init__(self, get_response=None): """ Instantiates our Middleware """ MiddlewareMixin.__init__(self, get_response) # Update the default config with user defined config self.conf = DEFAULT_CONFIG if hasattr(settings, "ACCESS_LOGS_CONFIG"): self.conf.update(settings.ACCESS_LOGS_CONFIG) # Instantiate our log building facility self.log_builder = AccessLogBuilder(self.conf) # And register our logger self.logger = logging.getLogger("django.advanced_access_logs") # Let's precompile our health check regexes for entry in self.conf["DEBUG_REQUESTS"]: for (k, val) in entry.items(): entry[k] = re.compile(val)
import re from django.conf import settings from django.utils.cache import patch_vary_headers from subdomains.utils import get_domain logger = logging.getLogger(__name__) lower = operator.methodcaller('lower') try: from django.utils.deprecation import MiddlewareMixin except ImportError: MiddlewareMixin = object UNSET = MiddlewareMixin() class SubdomainMiddleware(object): """ A middleware class that adds a ``subdomain`` attribute to the current request. """ def get_domain_for_request(self, request): """ Returns the domain that will be used to identify the subdomain part for this request. """ return get_domain() def process_request(self, request): """
def __init__(self, get_response=None): MiddlewareMixin.__init__(self) self.get_response = get_response