<commit_before>#
# Copyright (c) 2010 rPath, Inc.
#
# All Rights Reserved
#

import logging
import sys
import traceback

import libxml2
import libxslt

from django.contrib.auth import authenticate
from django.http import HttpResponseBadRequest, HttpResponse

from mint import config
from mint.django_rest.rbuilder import auth
from mint.django_rest.rbuilder.inventory import models
from mint.lib import mintutils

log = logging.getLogger(__name__)

class ExceptionLoggerMiddleware(object):

    def process_request(self, request):
        mintutils.setupLogging(consoleLevel=logging.INFO,
                consoleFormat='apache')
        return None

    def process_exception(self, request, exception):
        ei = sys.exc_info()
        tb = ''.join(traceback.format_tb(ei[2]))
        msg = str(ei[1])

        log.exception("Unhandled error in django handler:\n")
        log.exception(msg)
        log.exception(tb)

        code = 500
        fault = models.Fault(code=code, message=msg, traceback=tb)
        response = HttpResponse(status=code, content_type='text/xml')
        response.content = fault.to_xml(request)

        return response

class SetMethodRequestMiddleware(object):
    
    def process_request(self, request):
        # Was a '_method' directive in the query request
        if request.REQUEST.has_key('_method'):
            request_method = request.REQUEST['_method'].upper()
            allowable_methods = ['GET','POST','PUT','DELETE',]
                
            if request_method in allowable_methods:
                try:<commit_msg>Fix quadruple logging of django stack traces<commit_after>#
# Copyright (c) 2010 rPath, Inc.
#
# All Rights Reserved
#

import logging
import sys
import traceback

import libxml2
import libxslt

from django.contrib.auth import authenticate
from django.http import HttpResponseBadRequest, HttpResponse

from mint import config
from mint.django_rest.rbuilder import auth
from mint.django_rest.rbuilder.inventory import models
from mint.lib import mintutils

log = logging.getLogger(__name__)

class ExceptionLoggerMiddleware(object):

    def process_request(self, request):
        mintutils.setupLogging(consoleLevel=logging.INFO,
                consoleFormat='apache')
        return None

    def process_exception(self, request, exception):
        ei = sys.exc_info()
        tb = ''.join(traceback.format_tb(ei[2]))
        msg = str(ei[1])

        log.error("Unhandled error in django handler:", exc_info=ei)

        code = 500
        fault = models.Fault(code=code, message=msg, traceback=tb)
        response = HttpResponse(status=code, content_type='text/xml')
        response.content = fault.to_xml(request)

        return response

class SetMethodRequestMiddleware(object):
    
    def process_request(self, request):
        # Was a '_method' directive in the query request
        if request.REQUEST.has_key('_method'):
            request_method = request.REQUEST['_method'].upper()
            allowable_methods = ['GET','POST','PUT','DELETE',]
                
            if request_method in allowable_methods:
                try:
{'fraction_non_alphanumeric': 0.09242085065558042, 'fraction_numerical': 0.0063959066197633516, 'mean_word_length': 3.132100396301189, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '220045', 'n_tokens_mistral': 879, 'n_tokens_neox': 847, 'n_words': 222}