<commit_before># -*- coding: utf- 8 -*-
from __future__ import absolute_import
from base64 import b64encode
import hmac
from hashlib import sha1
import json

import blinker
from flask import request
from werkzeug.exceptions import BadRequest


class MandrillWebhooks(object):
    def __init__(self, app=None):
        """Init method.
        """
        self.app = app
        if app is not None:
            self.init_app(app)
        self.namespace = blinker.Namespace()

    def init_app(self, app):
        app.before_request(self.validate_signature)
        self.set_defaults()
        prefix = self.app.config['MANDRILL_WEBHOOKS_PREFIX']
        app.add_url_rule(prefix, 'raise_signal', self.raise_signal,
                         methods=['POST', 'HEAD'])

    def set_defaults(self):
        self.app.config.setdefault('MANDRILL_WEBHOOKS_PREFIX', '/mandrill')

    def validate_signature(self):
        if request.path != self.app.config['MANDRILL_WEBHOOKS_PREFIX']:
            return
        if request.method == 'HEAD':
            return
        #if not self.app.debug:<commit_msg>init_app needs to set self.app<commit_after># -*- coding: utf- 8 -*-
from __future__ import absolute_import
from base64 import b64encode
import hmac
from hashlib import sha1
import json

import blinker
from flask import request
from werkzeug.exceptions import BadRequest


class MandrillWebhooks(object):
    def __init__(self, app=None):
        """Init method.
        """
        self.app = app
        if app is not None:
            self.init_app(app)
        self.namespace = blinker.Namespace()

    def init_app(self, app):
        self.app = app
        self.app.before_request(self.validate_signature)
        self.set_defaults()
        prefix = self.app.config['MANDRILL_WEBHOOKS_PREFIX']
        app.add_url_rule(prefix, 'raise_signal', self.raise_signal,
                         methods=['POST', 'HEAD'])

    def set_defaults(self):
        self.app.config.setdefault('MANDRILL_WEBHOOKS_PREFIX', '/mandrill')

    def validate_signature(self):
        if request.path != self.app.config['MANDRILL_WEBHOOKS_PREFIX']:
            return
        if request.method == 'HEAD':
            return
        #if not self.app.debug:
{'fraction_non_alphanumeric': 0.10129986553115194, 'fraction_numerical': 0.005378753922008068, 'mean_word_length': 2.629268292682927, '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': '4611268', 'n_tokens_mistral': 682, 'n_tokens_neox': 663, 'n_words': 157}