<commit_before>import json

from django.core.cache import cache

from eth_utils import event_abi_to_log_topic, encode_hex

from hexbytes import HexBytes

from web3.utils.datastructures import AttributeDict


def get_event_abi(abi, event_name):
    """Helper function that extracts the event abi from the given abi.

    Args:
        abi (list): the contract abi
        event_name (str): the event name

    Returns:
        dict: the event specific abi
    """
    for entry in abi:
        if 'name' in entry.keys() and entry['name'] == event_name and \
                entry['type'] == "event":
            return entry
    raise ValueError(
        'Event `{0}` not found in the contract abi'.format(event_name))


def event_topic_from_contract_abi(abi, event_name):
    """Returns the event topic from the contract abi.

    Args:
        abi (obj): contract abi
        event_name (str): the desired event
<commit_msg>AttributeDict moved in newer version of web3<commit_after>import json

from django.core.cache import cache

from eth_utils import event_abi_to_log_topic, encode_hex

from hexbytes import HexBytes

try:
    from web3.utils.datastructures import AttributeDict
except ImportError:
    from web3.datastructures import AttributeDict


def get_event_abi(abi, event_name):
    """Helper function that extracts the event abi from the given abi.

    Args:
        abi (list): the contract abi
        event_name (str): the event name

    Returns:
        dict: the event specific abi
    """
    for entry in abi:
        if 'name' in entry.keys() and entry['name'] == event_name and \
                entry['type'] == "event":
            return entry
    raise ValueError(
        'Event `{0}` not found in the contract abi'.format(event_name))


def event_topic_from_contract_abi(abi, event_name):
    """Returns the event topic from the contract abi.

    Args:
        abi (obj): contract abi
        event_name (str): the desired event

{'fraction_non_alphanumeric': 0.07908163265306123, 'fraction_numerical': 0.003061224489795918, 'mean_word_length': 2.9456740442655938, 'pattern_counts': {'":': 2, '<': 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': '4987849', 'n_tokens_mistral': 579, 'n_tokens_neox': 559, 'n_words': 207}