<commit_before>import json
import uuid
from datetime import datetime

from flask import current_app
from flask_hookserver import Hooks

from .db import redis
from .members.models import User
from .projects.tasks import update_project_by_hook
from .tasks import spinach

hooks = Hooks()


@hooks.hook("ping")
def ping(data, guid):
    return "pong"


@hooks.hook("membership")
def membership(data, guid):
    if data["scope"] != "team":
        return "Scope wasn't team."

    member_id = data["member"]["id"]
    member = User.query.filter_by(id=member_id).first()
    if member is None:
        return f"No member found with id {member_id}."

    # only remove the user if they are member of the main members team
    # not if they are removed from project teams
    if data["team"]["slug"] != current_app.config["GITHUB_MEMBERS_TEAM_SLUG"]:<commit_msg>Fix compat with werkzeug.<commit_after>import hmac
import json
import uuid
from datetime import datetime

from flask import current_app
from flask_hookserver import Hooks
import werkzeug.security

from .db import redis
from .members.models import User
from .projects.tasks import update_project_by_hook
from .tasks import spinach

hooks = Hooks()


def safe_str_cmp(a: str, b: str) -> bool:
    """This function compares strings in somewhat constant time. This
    requires that the length of at least one string is known in advance.

    Returns `True` if the two strings are equal, or `False` if they are not.
    """

    if isinstance(a, str):
        a = a.encode("utf-8")  # type: ignore

    if isinstance(b, str):
        b = b.encode("utf-8")  # type: ignore

    return hmac.compare_digest(a, b)


# Monkeypatch hookserver to fix werkzeug compatibility.
werkzeug.security.safe_str_cmp = safe_str_cmp


@hooks.hook("ping")
def ping(data, guid):
    return "pong"


@hooks.hook("membership")
def membership(data, guid):
    if data["scope"] != "team":
        return "Scope wasn't team."

    member_id = data["member"]["id"]
    member = User.query.filter_by(id=member_id).first()
    if member is None:
        return f"No member found with id {member_id}."

    # only remove the user if they are member of the main members team
    # not if they are removed from project teams
    if data["team"]["slug"] != current_app.config["GITHUB_MEMBERS_TEAM_SLUG"]:
{'fraction_non_alphanumeric': 0.1020671834625323, 'fraction_numerical': 0.0008613264427217916, 'mean_word_length': 3.7896907216494844, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, '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': '2593848', 'n_tokens_mistral': 722, 'n_tokens_neox': 717, 'n_words': 253}