# Path: tenant_schemas/utils.py
# def get_public_schema_name():
#     return getattr(settings, 'PUBLIC_SCHEMA_NAME', 'public')
# 
# def get_tenant_model():
#     return get_model(*settings.TENANT_MODEL.split("."))
# 
# def remove_www(hostname):
#     """
#     Removes www. from the beginning of the address. Only for
#     routing purposes. www.test.com/login/ and test.com/login/ should
#     find the same tenant.
#     """
#     if hostname.startswith("www."):
#         return hostname[4:]
# 
#     return hostname


import django
from django.conf import settings
from django.core.exceptions import DisallowedHost
from django.db import connection
from django.http import Http404
from tenant_schemas.utils import (
    get_public_schema_name,
    get_tenant_model,
    remove_www,
)
        """
        return remove_www(request.get_host().split(":")[0]).lower()

    def process_request(self, request):
        # Connection needs first to be at the public schema, as this is where
        # the tenant metadata is stored.
        connection.set_schema_to_public()

        hostname = self.hostname_from_request(request)
        TenantModel = get_tenant_model()

        try:
            # get_tenant must be implemented by extending this class.
            tenant = self.get_tenant(TenantModel, hostname, request)
            assert isinstance(tenant, TenantModel)
        except TenantModel.DoesNotExist:
            raise self.TENANT_NOT_FOUND_EXCEPTION(
                "No tenant for {!r}".format(request.get_host())
            )
        except AssertionError:
            raise self.TENANT_NOT_FOUND_EXCEPTION(
                "Invalid tenant {!r}".format(request.tenant)
            )

        request.tenant = tenant
        connection.set_tenant(request.tenant)

        # Do we have a public-specific urlconf?
        if (
            hasattr(settings, "PUBLIC_SCHEMA_URLCONF")

# Path: tenant_schemas/utils.py
# def get_public_schema_name():
#     return getattr(settings, 'PUBLIC_SCHEMA_NAME', 'public')
# 
# def get_tenant_model():
#     return get_model(*settings.TENANT_MODEL.split("."))
# 
# def remove_www(hostname):
#     """
#     Removes www. from the beginning of the address. Only for
#     routing purposes. www.test.com/login/ and test.com/login/ should
#     find the same tenant.
#     """
#     if hostname.startswith("www."):
#         return hostname[4:]
# 
#     return hostname


# Path: tenant_schemas/middleware.py
import django
from django.conf import settings
from django.core.exceptions import DisallowedHost
from django.db import connection
from django.http import Http404
from tenant_schemas.utils import (
    get_public_schema_name,
    get_tenant_model,
    remove_www,
)

        """
        return remove_www(request.get_host().split(":")[0]).lower()

    def process_request(self, request):
        # Connection needs first to be at the public schema, as this is where
        # the tenant metadata is stored.
        connection.set_schema_to_public()

        hostname = self.hostname_from_request(request)
        TenantModel = get_tenant_model()

        try:
            # get_tenant must be implemented by extending this class.
            tenant = self.get_tenant(TenantModel, hostname, request)
            assert isinstance(tenant, TenantModel)
        except TenantModel.DoesNotExist:
            raise self.TENANT_NOT_FOUND_EXCEPTION(
                "No tenant for {!r}".format(request.get_host())
            )
        except AssertionError:
            raise self.TENANT_NOT_FOUND_EXCEPTION(
                "Invalid tenant {!r}".format(request.tenant)
            )

        request.tenant = tenant
        connection.set_tenant(request.tenant)

        # Do we have a public-specific urlconf?
        if (
            hasattr(settings, "PUBLIC_SCHEMA_URLCONF")

            and request.tenant.schema_name == get_public_schema_name()