# Path: wwwhisper_auth/http.py
# TEXT_MIME_TYPE = 'text/plain; charset=utf-8'
# HTML_MIME_TYPE = 'text/html; charset=utf-8'
# JSON_MIME_TYPE = 'application/json; charset=utf-8'
# JS_MIME_TYPE = 'text/javascript; charset=UTF-8'
# def accepts_html(accept_header):
#     def __init__(self, message):
#     def __init__(self, attributes_dict):
#     def __init__(self, body):
#     def __init__(self, body):
#     def __init__(self):
#     def __init__(self, attributes_dict):
#     def __init__(self, location):
#     def __init__(self, html_response=None):
#     def __init__(self, html_response=None):
#     def __init__(self, message):
#     def __init__(self, message):
#     def __init__(self, message):
#     def __init__(self, message):
#     def __init__(self, message):
# def disallow_cross_site_request(decorated_method):
#     def wrapper(self, request, *args, **kwargs):
# def never_ever_cache(decorated_method):
#     def wrapper(*args, **kwargs):
#     def dispatch(self, request, *args, **kwargs):
# def _csrf_token_valid(request):
# def _utf8_encoded_json(request):
# class HttpResponseOK(HttpResponse):
# class HttpResponseOKJson(HttpResponse):
# class HttpResponseOKHtml(HttpResponse):
# class HttpResponseOKJs(HttpResponse):
# class HttpResponseNoContent(HttpResponse):
# class HttpResponseCreated(HttpResponse):
# class HttpResponseRedirect(HttpResponse):
# class HttpResponseNotAuthenticated(HttpResponse):
# class HttpResponseNotAuthorized(HttpResponse):
# class HttpResponseBadRequest(HttpResponse):
# class HttpResponseLimitExceeded(HttpResponse):
# class HttpResponseNotFound(HttpResponse):
# class HttpResponseServiceUnavailable(HttpResponse):
# class HttpResponseInternalError(HttpResponse):
# class RestView(View):
# 
# Path: wwwhisper_auth/models.py
# SINGLE_SITE_ID = 'theone'
# 
# Path: wwwhisper_auth/url_utils.py
# def strip_query(path):
# def decode(path):
# def collapse_slashes(path):
# def is_canonical(path):
# def contains_fragment(path):
# def contains_query(path):
# def contains_params(path):
# def validate_redirection_target(path):
# def validate_site_url(url):
# def remove_default_port(url):
# REDIRECTION_PATH_LIMIT = 200


from django.conf import settings
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from wwwhisper_auth import http
from wwwhisper_auth.models import SINGLE_SITE_ID
from wwwhisper_auth import url_utils
import wwwhisper_auth.site_cache
import logging

    Sets X-Forwarded-Host to match Site-Url. X-Forwarded-Host is used
    by Django to generate redirects.
    """

    def _alias_defined(self, site, url):
        return site.aliases.find_item_by_url(url) is not None

    def _get_full_path(self, request):
        full_path = request.get_full_path()
        auth_request_prefix = reverse('auth-request') + '?path='
        if full_path.startswith(auth_request_prefix):
            full_path = full_path[len(auth_request_prefix):]
        return full_path

    def _needs_https_redirect(self, site, scheme, host):
        return scheme == 'http' and self._alias_defined(site, 'https://' + host)

    def _site_url_invalid(self, request, scheme, host):
        if self._needs_https_redirect(request.site, scheme, host):
            logger.debug('Request over http, redirecting to https')
            return redirect('https://' + host + self._get_full_path(request))
        msg = 'Invalid request URL, you can use wwwhisper admin to allow ' \
            'requests from this address.'
        logger.warning(msg)
        return http.HttpResponseBadRequest(msg)

    def process_request(self, request):
        url = request.META.get('HTTP_SITE_URL', None)
        if url is None:

# Path: wwwhisper_auth/http.py
# TEXT_MIME_TYPE = 'text/plain; charset=utf-8'
# HTML_MIME_TYPE = 'text/html; charset=utf-8'
# JSON_MIME_TYPE = 'application/json; charset=utf-8'
# JS_MIME_TYPE = 'text/javascript; charset=UTF-8'
# def accepts_html(accept_header):
#     def __init__(self, message):
#     def __init__(self, attributes_dict):
#     def __init__(self, body):
#     def __init__(self, body):
#     def __init__(self):
#     def __init__(self, attributes_dict):
#     def __init__(self, location):
#     def __init__(self, html_response=None):
#     def __init__(self, html_response=None):
#     def __init__(self, message):
#     def __init__(self, message):
#     def __init__(self, message):
#     def __init__(self, message):
#     def __init__(self, message):
# def disallow_cross_site_request(decorated_method):
#     def wrapper(self, request, *args, **kwargs):
# def never_ever_cache(decorated_method):
#     def wrapper(*args, **kwargs):
#     def dispatch(self, request, *args, **kwargs):
# def _csrf_token_valid(request):
# def _utf8_encoded_json(request):
# class HttpResponseOK(HttpResponse):
# class HttpResponseOKJson(HttpResponse):
# class HttpResponseOKHtml(HttpResponse):
# class HttpResponseOKJs(HttpResponse):
# class HttpResponseNoContent(HttpResponse):
# class HttpResponseCreated(HttpResponse):
# class HttpResponseRedirect(HttpResponse):
# class HttpResponseNotAuthenticated(HttpResponse):
# class HttpResponseNotAuthorized(HttpResponse):
# class HttpResponseBadRequest(HttpResponse):
# class HttpResponseLimitExceeded(HttpResponse):
# class HttpResponseNotFound(HttpResponse):
# class HttpResponseServiceUnavailable(HttpResponse):
# class HttpResponseInternalError(HttpResponse):
# class RestView(View):
# 
# Path: wwwhisper_auth/models.py
# SINGLE_SITE_ID = 'theone'
# 
# Path: wwwhisper_auth/url_utils.py
# def strip_query(path):
# def decode(path):
# def collapse_slashes(path):
# def is_canonical(path):
# def contains_fragment(path):
# def contains_query(path):
# def contains_params(path):
# def validate_redirection_target(path):
# def validate_site_url(url):
# def remove_default_port(url):
# REDIRECTION_PATH_LIMIT = 200


# Path: wwwhisper_auth/middleware.py
from django.conf import settings
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from wwwhisper_auth import http
from wwwhisper_auth.models import SINGLE_SITE_ID
from wwwhisper_auth import url_utils
import wwwhisper_auth.site_cache
import logging


    Sets X-Forwarded-Host to match Site-Url. X-Forwarded-Host is used
    by Django to generate redirects.
    """

    def _alias_defined(self, site, url):
        return site.aliases.find_item_by_url(url) is not None

    def _get_full_path(self, request):
        full_path = request.get_full_path()
        auth_request_prefix = reverse('auth-request') + '?path='
        if full_path.startswith(auth_request_prefix):
            full_path = full_path[len(auth_request_prefix):]
        return full_path

    def _needs_https_redirect(self, site, scheme, host):
        return scheme == 'http' and self._alias_defined(site, 'https://' + host)

    def _site_url_invalid(self, request, scheme, host):
        if self._needs_https_redirect(request.site, scheme, host):
            logger.debug('Request over http, redirecting to https')
            return redirect('https://' + host + self._get_full_path(request))
        msg = 'Invalid request URL, you can use wwwhisper admin to allow ' \
            'requests from this address.'
        logger.warning(msg)
        return http.HttpResponseBadRequest(msg)

    def process_request(self, request):
        url = request.META.get('HTTP_SITE_URL', None)
        if url is None:

            return http.HttpResponseBadRequest('Missing Site-Url header')