# Path: wwwhisper_auth/http.py
# def accepts_html(accept_header):
#     """Checks if the 'Accept' header accepts html response.
# 
#     Args:
#        accept_header: A string, for example 'audio/*, text/plain, text/*'
#     """
#     return (accept_header is not None
#             and _accepts_html_re.search(accept_header) is not None)
# 
# Path: wwwhisper_auth/http.py
# class RestView(View):
#     """A common base class for all REST style views.
# 
#     Disallows all cross origin requests. Disables caching of
#     responses. For POST and PUT methods, deserializes method arguments
#     from a json encoded request body. If a specific method is not
#     implemented in a subclass, or if it does not accept arguments
#     passed in the body, or if some arguments are missing, an
#     appropriate error is returned to the client.
#     """
# 
#     @disallow_cross_site_request
#     @never_ever_cache
#     def dispatch(self, request, *args, **kwargs):
#         """Dispatches a method to a subclass.
# 
#         kwargs contains arguments that are passed as a query string,
#         for PUT and POST arguments passed in a json request body are
#         added to kwargs, conflicting names result in an error.
#         """
#         method = request.method.lower()
#         # Parse body as json object if it is not empty (empty body
#         # contains '--BoUnDaRyStRiNg--')
#         if (method == 'post' or method == 'put') \
#                 and len(request.body) != 0 and request.body[0] != '-':
#             try:
#                 if not _utf8_encoded_json(request):
#                     return HttpResponseBadRequest(
#                         "Invalid Content-Type (only '%s' is acceptable)."
#                         % (JSON_MIME_TYPE))
# 
#                 json_args = json.loads(request.body)
#                 for k in json_args:
#                     if k in kwargs:
#                         return HttpResponseBadRequest(
#                             'Invalid argument passed in the request body.')
#                     else:
#                         kwargs[k] = json_args[k]
#                 kwargs.update()
#             except ValueError as err:
#                 logger.debug(
#                     'Failed to parse the request body a as json object: %s'
#                     % (err))
#                 return HttpResponseBadRequest(
#                     'Failed to parse the request body as a json object.')
#         try:
#             return super(RestView, self).dispatch(request, *args, **kwargs)
#         except TypeError as err:
#             trace = "".join(traceback.format_exc())
#             logger.debug('Invalid arguments, handler not found: %s\n%s'
#                          % (err, trace))
#             return HttpResponseBadRequest('Invalid request arguments')
# 
# Path: wwwhisper_auth/tests/utils.py
# class HttpTestCase(TestCase):
#     def setUp(self):
#         self.client = Client()
#         self.sites = SitesCollection()
#         # For each test case, test site must exist, so it can be set
#         # by SetSiteMiddleware
#         self.site = self.sites.create_item(SINGLE_SITE_ID)
#         self.site.aliases.create_item(TEST_SITE)
# 
#     def post(self, url, args):
#         return self.client.post(
#             url, json.dumps(args), 'application/json; charset=UTF-8',
#             HTTP_SITE_URL=TEST_SITE)
# 
#     """ To be used for views that are not contacted via Ajax. """
#     def post_form(self, url, args):
#         return self.client.post(url, args)
# 
#     def get(self, url, **extra_headers):
#         return self.client.get(url, HTTP_SITE_URL=TEST_SITE, **extra_headers)
# 
#     def put(self, url, args=None):
#         if args is None:
#             return self.client.put(url, HTTP_SITE_URL=TEST_SITE)
#         return self.client.put(
#             url, data=json.dumps(args),
#             content_type='application/json;  charset=UTF-8',
#             HTTP_SITE_URL=TEST_SITE)
# 
# 
#     def delete(self, url):
#         return self.client.delete(url, HTTP_SITE_URL=TEST_SITE)
# 
# Path: wwwhisper_auth/tests/utils.py
# TEST_SITE = 'https://foo.example.org:8080'


from django.conf import settings
from django.conf.urls import url
from django.http import HttpResponse
from django.test import TestCase, override_settings
from django.test.client import Client
from wwwhisper_auth.http import accepts_html
from wwwhisper_auth.http import RestView
from wwwhisper_auth.tests.utils import HttpTestCase
from wwwhisper_auth.tests.utils import TEST_SITE
# wwwhisper - web access control.
# Copyright (C) 2012-2018 Jan Wrobel <jan@mixedbit.org>


class TestView(RestView):
    def get(self, request):
        return HttpResponse(status=267)

    def post(self, request, ping_message):
        return HttpResponse(ping_message, status=277)


# Path: wwwhisper_auth/http.py
# def accepts_html(accept_header):
#     """Checks if the 'Accept' header accepts html response.
# 
#     Args:
#        accept_header: A string, for example 'audio/*, text/plain, text/*'
#     """
#     return (accept_header is not None
#             and _accepts_html_re.search(accept_header) is not None)
# 
# Path: wwwhisper_auth/http.py
# class RestView(View):
#     """A common base class for all REST style views.
# 
#     Disallows all cross origin requests. Disables caching of
#     responses. For POST and PUT methods, deserializes method arguments
#     from a json encoded request body. If a specific method is not
#     implemented in a subclass, or if it does not accept arguments
#     passed in the body, or if some arguments are missing, an
#     appropriate error is returned to the client.
#     """
# 
#     @disallow_cross_site_request
#     @never_ever_cache
#     def dispatch(self, request, *args, **kwargs):
#         """Dispatches a method to a subclass.
# 
#         kwargs contains arguments that are passed as a query string,
#         for PUT and POST arguments passed in a json request body are
#         added to kwargs, conflicting names result in an error.
#         """
#         method = request.method.lower()
#         # Parse body as json object if it is not empty (empty body
#         # contains '--BoUnDaRyStRiNg--')
#         if (method == 'post' or method == 'put') \
#                 and len(request.body) != 0 and request.body[0] != '-':
#             try:
#                 if not _utf8_encoded_json(request):
#                     return HttpResponseBadRequest(
#                         "Invalid Content-Type (only '%s' is acceptable)."
#                         % (JSON_MIME_TYPE))
# 
#                 json_args = json.loads(request.body)
#                 for k in json_args:
#                     if k in kwargs:
#                         return HttpResponseBadRequest(
#                             'Invalid argument passed in the request body.')
#                     else:
#                         kwargs[k] = json_args[k]
#                 kwargs.update()
#             except ValueError as err:
#                 logger.debug(
#                     'Failed to parse the request body a as json object: %s'
#                     % (err))
#                 return HttpResponseBadRequest(
#                     'Failed to parse the request body as a json object.')
#         try:
#             return super(RestView, self).dispatch(request, *args, **kwargs)
#         except TypeError as err:
#             trace = "".join(traceback.format_exc())
#             logger.debug('Invalid arguments, handler not found: %s\n%s'
#                          % (err, trace))
#             return HttpResponseBadRequest('Invalid request arguments')
# 
# Path: wwwhisper_auth/tests/utils.py
# class HttpTestCase(TestCase):
#     def setUp(self):
#         self.client = Client()
#         self.sites = SitesCollection()
#         # For each test case, test site must exist, so it can be set
#         # by SetSiteMiddleware
#         self.site = self.sites.create_item(SINGLE_SITE_ID)
#         self.site.aliases.create_item(TEST_SITE)
# 
#     def post(self, url, args):
#         return self.client.post(
#             url, json.dumps(args), 'application/json; charset=UTF-8',
#             HTTP_SITE_URL=TEST_SITE)
# 
#     """ To be used for views that are not contacted via Ajax. """
#     def post_form(self, url, args):
#         return self.client.post(url, args)
# 
#     def get(self, url, **extra_headers):
#         return self.client.get(url, HTTP_SITE_URL=TEST_SITE, **extra_headers)
# 
#     def put(self, url, args=None):
#         if args is None:
#             return self.client.put(url, HTTP_SITE_URL=TEST_SITE)
#         return self.client.put(
#             url, data=json.dumps(args),
#             content_type='application/json;  charset=UTF-8',
#             HTTP_SITE_URL=TEST_SITE)
# 
# 
#     def delete(self, url):
#         return self.client.delete(url, HTTP_SITE_URL=TEST_SITE)
# 
# Path: wwwhisper_auth/tests/utils.py
# TEST_SITE = 'https://foo.example.org:8080'


# Path: wwwhisper_auth/tests/tests_http.py
from django.conf import settings
from django.conf.urls import url
from django.http import HttpResponse
from django.test import TestCase, override_settings
from django.test.client import Client
from wwwhisper_auth.http import accepts_html
from wwwhisper_auth.http import RestView
from wwwhisper_auth.tests.utils import HttpTestCase
from wwwhisper_auth.tests.utils import TEST_SITE

# wwwhisper - web access control.
# Copyright (C) 2012-2018 Jan Wrobel <jan@mixedbit.org>


class TestView(RestView):
    def get(self, request):
        return HttpResponse(status=267)

    def post(self, request, ping_message):
        return HttpResponse(ping_message, status=277)


class TestView2(RestView):