<commit_before>import sys, traceback
import urllib2
import yaml
from django.core.exceptions import MiddlewareNotUsed
from django.views.debug import get_safe_settings
from django.conf import settings

class HoptoadNotifierMiddleware(object):
    def __init__(self):
        all_settings = settings.get_all_members()
        if 'HOPTOAD_API_KEY' not in all_settings:
            raise MiddlewareNotUsed
        if settings.DEBUG == True and (
            not 'HOPTOAD_NOTIFY_WHILE_DEBUG' in all_settings
            or not settings.HOPTOAD_NOTIFY_WHILE_DEBUG ):
            raise MiddlewareNotUsed
    
    def process_exception(self, request, exc):
        excc, _, tb = sys.exc_info()
        
        message = '%s: %s' % (excc.__name__, str(exc))
        trace = [ "%s:%d:in `%s'" % (filename, lineno, funcname) 
                  for filename, lineno, funcname, _
                  in traceback.extract_tb(tb) ]
        trace.reverse()
        environment = dict( (str(k), str(v)) for (k, v) in get_safe_settings().items() )
        request_get = dict( (str(k), str(v)) for (k, v) in request.GET.items() )
        request_post = dict( (str(k), str(v)) for (k, v) in request.POST.items() )
        session = dict( (str(k), str(v)) for (k, v) in request.session.items() )
        
        headers = { 'Content-Type': 'application/x-yaml', 
                    'Accept': 'text/xml, application/xml', }
        data = yaml.dump({ 'notice': {
            'api_key':       settings.HOPTOAD_API_KEY,
            'error_class':   excc.__name__,
            'error_message': "%s: %s" % (excc.__name__, message),
            'backtrace':     trace,
            'request':       { 'url': request.build_absolute_uri(),
                               'params': request_post if request_post else request_get },
            'session':       { 'key': '', 'data': session },
            'environment':   environment,
        }}, default_flow_style=False)<commit_msg>Remove an unnecessary comparison.<commit_after>import sys, traceback
import urllib2
import yaml
from django.core.exceptions import MiddlewareNotUsed
from django.views.debug import get_safe_settings
from django.conf import settings

class HoptoadNotifierMiddleware(object):
    def __init__(self):
        all_settings = settings.get_all_members()
        if 'HOPTOAD_API_KEY' not in all_settings:
            raise MiddlewareNotUsed
        if settings.DEBUG and (
            not 'HOPTOAD_NOTIFY_WHILE_DEBUG' in all_settings
            or not settings.HOPTOAD_NOTIFY_WHILE_DEBUG ):
            raise MiddlewareNotUsed
    
    def process_exception(self, request, exc):
        excc, _, tb = sys.exc_info()
        
        message = '%s: %s' % (excc.__name__, str(exc))
        trace = [ "%s:%d:in `%s'" % (filename, lineno, funcname) 
                  for filename, lineno, funcname, _
                  in traceback.extract_tb(tb) ]
        trace.reverse()
        environment = dict( (str(k), str(v)) for (k, v) in get_safe_settings().items() )
        request_get = dict( (str(k), str(v)) for (k, v) in request.GET.items() )
        request_post = dict( (str(k), str(v)) for (k, v) in request.POST.items() )
        session = dict( (str(k), str(v)) for (k, v) in request.session.items() )
        
        headers = { 'Content-Type': 'application/x-yaml', 
                    'Accept': 'text/xml, application/xml', }
        data = yaml.dump({ 'notice': {
            'api_key':       settings.HOPTOAD_API_KEY,
            'error_class':   excc.__name__,
            'error_message': "%s: %s" % (excc.__name__, message),
            'backtrace':     trace,
            'request':       { 'url': request.build_absolute_uri(),
                               'params': request_post if request_post else request_get },
            'session':       { 'key': '', 'data': session },
            'environment':   environment,
        }}, default_flow_style=False)
{'fraction_non_alphanumeric': 0.1258937691521961, 'fraction_numerical': 0.0005107252298263534, 'mean_word_length': 2.288832913518052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5278726', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1166, 'n_words': 285}