def get_mapper():
    """Returns the mapper."""
    global _CACHED_MAPPER
    if not _CACHED_MAPPER:
        name = getattr(settings, 'MULTITENANT_MAPPER_CLASS', None)
        if not name:
            raise ImproperlyConfigured("You must specify MULTITENANT_MAPPER_CLASS in settings.")

        try:
            module_path, member_name = name.rsplit(".", 1)
            module = import_module(module_path)
            cls = getattr(module, member_name)
        except (ValueError, __HOLE__, AttributeError), e:
            raise ImportError("Could not import mapper: %s: %s" % (name, e))

        if not issubclass(cls, TenantMapper):
            raise ImproperlyConfigured('%s does not subclass db_multitenant.mapper.TenantMapper', name)

        _CACHED_MAPPER = cls()

    return _CACHED_MAPPER
dataset/ETHPy150Open mik3y/django-db-multitenant/db_multitenant/utils.py/get_mapper