"""
sentry.web.views
~~~~~~~~~~~~~~~~

:copyright: (c) 2010 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods

from sentry.coreapi import (parse_auth_header, project_from_auth_vars, project_from_api_key_and_id,
                            project_from_id, decode_and_decompress_data, safely_load_json_string,
                            ensure_valid_project_id, insert_data_to_database, APIError, APIUnauthorized)


def extract_auth_vars(request):
    if request.META.get('HTTP_X_SENTRY_AUTH', '').startswith('Sentry'):
        # Auth version 3.0 (same as 2.0, diff header)
        return parse_auth_header(request.META['HTTP_X_SENTRY_AUTH'])
    elif request.META.get('HTTP_AUTHORIZATION', '').startswith('Sentry'):
        # Auth version 2.0
        return parse_auth_header(request.META['HTTP_AUTHORIZATION'])
    else:
        return None


@csrf_exempt
@require_http_methods(['POST'])
def store(request):
    try:
        auth_vars = extract_auth_vars(request)
        data = request.raw_post_data

        if auth_vars:
            project = project_from_auth_vars(auth_vars, data)
        elif request.GET.get('api_key') and request.GET.get('project_id') and request.is_secure():
            # ssl requests dont have to have signature verification
            project = project_from_api_key_and_id(request.GET['api_key'], request.GET['project_id'])
        elif request.GET.get('project_id') and request.user.is_authenticated():
            # authenticated users are simply trusted to provide the right id
            project = project_from_id(request)
        else:
            raise APIUnauthorized()

        if not data.startswith('{'):
            data = decode_and_decompress_data(data)
        data = safely_load_json_string(data)

        ensure_valid_project_id(project, data)

        insert_data_to_database(data)
    except APIError, error:
        return HttpResponse(error.msg, status=error.http_status)
    return HttpResponse('')


@@ -336,28 +336,8 @@
 port
- (parse_auth_header,
  pro
@@ -389,35 +389,11 @@
 _id,
-%0A                          
+ %5C%0A
   pr
@@ -463,35 +463,11 @@
 ing,
-%0A                          
+ %5C%0A
   en
@@ -543,15 +543,13 @@
 ized
-)%0A%0A%0Adef
+, %5C%0A 
  ext
@@ -566,413 +566,8 @@
 vars
-(request):%0A    if request.META.get('HTTP_X_SENTRY_AUTH', '').startswith('Sentry'):%0A        # Auth version 3.0 (same as 2.0, diff header)%0A        return parse_auth_header(request.META%5B'HTTP_X_SENTRY_AUTH'%5D)%0A    elif request.META.get('HTTP_AUTHORIZATION', '').startswith('Sentry'):%0A        # Auth version 2.0%0A        return parse_auth_header(request.META%5B'HTTP_AUTHORIZATION'%5D)%0A    else:%0A        return None
 %0A%0A%0A@

Remove duplciated extract_auth_vars code