<commit_before>"""
raven.contrib.flask
~~~~~~~~~~~~~~~~~~~

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

from __future__ import absolute_import

from flask import request
from flask.signals import got_request_exception
from raven.base import Client
from raven.contrib.flask.utils import get_data_from_request


class Sentry(object):
    def __init__(self, app=None, client=None, client_cls=Client):
        self.app = app
        self.client = client
        self.client_cls = client_cls

        if app:
            self.init_app(app)

    def handle_exception(self, client):
        def _handle_exception(sender, **kwargs):
            client.capture('Exception', exc_info=kwargs.get('exc_info'),
                data=get_data_from_request(request),
                extra={
                    'app': sender.name,
                },
            )
        return _handle_exception

    def init_app(self, app):
        if not self.client:
            if not app.config.get('SENTRY_SERVERS'):
                raise TypeError('The SENTRY_SERVERS config variable is required.')
            client = self.client_cls(
                include_paths=set(app.config.get('SENTRY_INCLUDE_PATHS', [])) | set([app.import_name]),
                exclude_paths=app.config.get('SENTRY_EXCLUDE_PATHS'),
                servers=app.config.get('SENTRY_SERVERS'),
                name=app.config.get('SENTRY_NAME'),
                key=app.config.get('SENTRY_KEY'),
                public_key=app.config.get('SENTRY_PUBLIC_KEY'),
                secret_key=app.config.get('SENTRY_SECRET_KEY'),
                project=app.config.get('SENTRY_PROJECT'),
                site=app.config.get('SENTRY_SITE_NAME'),
            )
        else:
            client = self.client

        self.client = client

        got_request_exception.connect(self.handle_exception(client), sender=app, weak=False)<commit_msg>Ensure we bind self.client *correctly*<commit_after>"""
raven.contrib.flask
~~~~~~~~~~~~~~~~~~~

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

from __future__ import absolute_import

from flask import request
from flask.signals import got_request_exception
from raven.base import Client
from raven.contrib.flask.utils import get_data_from_request


class Sentry(object):
    def __init__(self, app=None, client=None, client_cls=Client):
        self.app = app
        self.client = client
        self.client_cls = client_cls

        if app:
            self.init_app(app)

    def handle_exception(self, client):
        def _handle_exception(sender, **kwargs):
            client.capture('Exception', exc_info=kwargs.get('exc_info'),
                data=get_data_from_request(request),
                extra={
                    'app': sender.name,
                },
            )
        return _handle_exception

    def init_app(self, app):
        if not self.client:
            if not app.config.get('SENTRY_SERVERS'):
                raise TypeError('The SENTRY_SERVERS config variable is required.')
            client = self.client_cls(
                include_paths=set(app.config.get('SENTRY_INCLUDE_PATHS', [])) | set([app.import_name]),
                exclude_paths=app.config.get('SENTRY_EXCLUDE_PATHS'),
                servers=app.config.get('SENTRY_SERVERS'),
                name=app.config.get('SENTRY_NAME'),
                key=app.config.get('SENTRY_KEY'),
                public_key=app.config.get('SENTRY_PUBLIC_KEY'),
                secret_key=app.config.get('SENTRY_SECRET_KEY'),
                project=app.config.get('SENTRY_PROJECT'),
                site=app.config.get('SENTRY_SITE_NAME'),
            )
            self.client = client
        else:
            client = self.client

        got_request_exception.connect(self.handle_exception(client), sender=app, weak=False)
{'fraction_non_alphanumeric': 0.1135558927668184, 'fraction_numerical': 0.0020232675771370764, 'mean_word_length': 2.400687876182287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1859349', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1112, 'n_words': 217}