<commit_before>"""
    gorilla._utils
    ~~~~~~~~~~~~~~
    
    Utility functions for internal use.
    
    :copyright: Copyright 2014 by <NAME>.
    :license: MIT, see LICENSE for details.
"""

import inspect

import gorilla._constants
import gorilla._python
from gorilla._objecttype import ObjectType


def class_attribute_iterator(cls):
    """Iterate over the attributes of a class that are suitable for patching.
    
    The search is also done within the base classes.
    
    Parameters
    ----------
    cls : class
        Class to retrieve the attributes from.
    
    Yields
    ------
    tuple of (name, attribute)
        
        name : str
            The name of the attribute found.
        attribute : object
            The attribute found.
    """
    ignore = ('__class__', '__dict__', '__weakref__')
    valid_types = (ObjectType.cls, ObjectType.descriptor)
    bases = (base for base in inspect.getmro(cls)
             if not base in (type, object))
    yielded = set()
    for base in bases:
        for name, attribute in gorilla._python.iteritems(base.__dict__):
            if (name not in ignore and name not in yielded and
                    ObjectType.get(attribute) in valid_types):
                yield (name, attribute)
                yielded.add(name)


def extension_iterator(object):
    """Iterate over the extensions nested under an object.
    
    The object can be a module, a class or a descriptor.
    
    The search is done recursively.
    
    Parameters
    ----------
    object : object
        Object to retrieve the extensions from.
    
    Yields
    ------
    Extension
        The extensions found.
    """
    underlying = get_underlying_object(object)
    if hasattr(underlying, gorilla._constants.DECORATOR_DATA):
        data = getattr(underlying, gorilla._constants.DECORATOR_DATA)
        extensions = data.get('extensions', [])
        for extension in extensions:
            yield extension
    
    if not hasattr(underlying, '__dict__'):
        return
        yield
    
    valid_types = (ObjectType.cls, ObjectType.descriptor)
    for _, attribute in gorilla._python.iteritems(underlying.__dict__):
        if ObjectType.get(attribute) in valid_types:<commit_msg>Call the `values()` method instead of the unnecessary `iteritems()`.<commit_after>"""
    gorilla._utils
    ~~~~~~~~~~~~~~
    
    Utility functions for internal use.
    
    :copyright: Copyright 2014 by <NAME>.
    :license: MIT, see LICENSE for details.
"""

import inspect

import gorilla._constants
import gorilla._python
from gorilla._objecttype import ObjectType


def class_attribute_iterator(cls):
    """Iterate over the attributes of a class that are suitable for patching.
    
    The search is also done within the base classes.
    
    Parameters
    ----------
    cls : class
        Class to retrieve the attributes from.
    
    Yields
    ------
    tuple of (name, attribute)
        
        name : str
            The name of the attribute found.
        attribute : object
            The attribute found.
    """
    ignore = ('__class__', '__dict__', '__weakref__')
    valid_types = (ObjectType.cls, ObjectType.descriptor)
    bases = (base for base in inspect.getmro(cls)
             if not base in (type, object))
    yielded = set()
    for base in bases:
        for name, attribute in gorilla._python.iteritems(base.__dict__):
            if (name not in ignore and name not in yielded and
                    ObjectType.get(attribute) in valid_types):
                yield (name, attribute)
                yielded.add(name)


def extension_iterator(object):
    """Iterate over the extensions nested under an object.
    
    The object can be a module, a class or a descriptor.
    
    The search is done recursively.
    
    Parameters
    ----------
    object : object
        Object to retrieve the extensions from.
    
    Yields
    ------
    Extension
        The extensions found.
    """
    underlying = get_underlying_object(object)
    if hasattr(underlying, gorilla._constants.DECORATOR_DATA):
        data = getattr(underlying, gorilla._constants.DECORATOR_DATA)
        extensions = data.get('extensions', [])
        for extension in extensions:
            yield extension
    
    if not hasattr(underlying, '__dict__'):
        return
        yield
    
    valid_types = (ObjectType.cls, ObjectType.descriptor)
    for attribute in underlying.__dict__.values():
        if ObjectType.get(attribute) in valid_types:
{'fraction_non_alphanumeric': 0.09080866106937693, 'fraction_numerical': 0.0017675651789659744, 'mean_word_length': 2.2015558698727014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6391065', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1197, 'n_words': 405}