<commit_before>"""
    gorilla.extension
    ~~~~~~~~~~~~~~~~~
    
    Main logic behind the patching process.
    
    :copyright: Copyright 2014 by <NAME>.
    :license: MIT, see LICENSE for details.
"""

import gorilla._constants
import gorilla._objecttype
import gorilla._utils
import gorilla.settings


_VALID_OBJECT_TYPES = (
    gorilla._objecttype.CLASS,
    gorilla._objecttype.DESCRIPTOR
)
_VALID_TARGET_TYPES = (
    gorilla._objecttype.MODULE,
    gorilla._objecttype.CLASS
)


class Extension(object):
    
    """Core of the patching process.
    
    It knows which code to use for patching, where to apply it, and how to
    do it.
    
    Two types of patching operations are permitted:
        
        * module targets can be patched with either functions or classes.
        * class targets can be patcged with either classes or class
          routines (``function``, ``method``, ``classmethod``,
          ``staticmethod``, ``property``).
    
    When an attribute with the same name as the extension is found on the
    target, then the existing attribute is saved under another name and
    becomes callable from within the extension's code through the
    `~gorilla.utils.get_original_attribute` function. This ensures that
    the original behavior of an attribute can be preserved if needed.
    
    One exception is when a class is to be patched in a target that already
    contains a class with the same name. In this case, the operation will
    recursively patch each attribute member.
    
    It is possible to apply callable objects to transform the decorated
    object during the patching process. This can be use for example to
    ensure that a function is applied as a static method in a class.
    
    By default, the bahavior of the patching process is dictated by the
    settings defined in the `~gorilla.settings.Settings` class. It's
    possible to override those by using the `settings` property.
    
    Note
    ----
        This class shouldn't be used directly but in the case where dynamic
        patching is required.
    """
        
    def __init__(self, object, target):
        """Constructor.
        
        Parameters
        ----------
        object : object
            Extension object to use as a patch. Either a class or
            a descriptor.
        target : object
            Target to patch. Either a module or a class.
        
        Note
        ----
            Because of the descriptor protocol [1]_, it is possible that
            the object returned by accessing a method with the ``.``
            delimiter such as ``MyClass.my_method`` might be different than
            if accessed through ``MyClass.__dict__['my_method']``. This is
            because in the former case, any decorator applied to the method
            might return a different object while in the latter case the
            full stack of decorators is returned, as internally stored by<commit_msg>Fix a typo.<commit_after>"""
    gorilla.extension
    ~~~~~~~~~~~~~~~~~
    
    Main logic behind the patching process.
    
    :copyright: Copyright 2014 by <NAME>.
    :license: MIT, see LICENSE for details.
"""

import gorilla._constants
import gorilla._objecttype
import gorilla._utils
import gorilla.settings


_VALID_OBJECT_TYPES = (
    gorilla._objecttype.CLASS,
    gorilla._objecttype.DESCRIPTOR
)
_VALID_TARGET_TYPES = (
    gorilla._objecttype.MODULE,
    gorilla._objecttype.CLASS
)


class Extension(object):
    
    """Core of the patching process.
    
    It knows which code to use for patching, where to apply it, and how to
    do it.
    
    Two types of patching operations are permitted:
        
        * module targets can be patched with either functions or classes.
        * class targets can be patcged with either classes or class
          routines (``function``, ``method``, ``classmethod``,
          ``staticmethod``, ``property``).
    
    When an attribute with the same name as the extension is found on the
    target, then the existing attribute is saved under another name and
    becomes callable from within the extension's code through the
    `~gorilla.utils.get_original_attribute` function. This ensures that
    the original behavior of an attribute can be preserved if needed.
    
    One exception is when a class is to be patched in a target that already
    contains a class with the same name. In this case, the operation will
    recursively patch each attribute member.
    
    It is possible to apply callable objects to transform the decorated
    object during the patching process. This can be use for example to
    ensure that a function is applied as a static method in a class.
    
    By default, the behavior of the patching process is dictated by the
    settings defined in the `~gorilla.settings.Settings` class. It's
    possible to override those by using the `settings` property.
    
    Note
    ----
        This class shouldn't be used directly but in the case where dynamic
        patching is required.
    """
        
    def __init__(self, object, target):
        """Constructor.
        
        Parameters
        ----------
        object : object
            Extension object to use as a patch. Either a class or
            a descriptor.
        target : object
            Target to patch. Either a module or a class.
        
        Note
        ----
            Because of the descriptor protocol [1]_, it is possible that
            the object returned by accessing a method with the ``.``
            delimiter such as ``MyClass.my_method`` might be different than
            if accessed through ``MyClass.__dict__['my_method']``. This is
            because in the former case, any decorator applied to the method
            might return a different object while in the latter case the
            full stack of decorators is returned, as internally stored by
{'fraction_non_alphanumeric': 0.06290050590219225, 'fraction_numerical': 0.0016863406408094434, 'mean_word_length': 2.400802752293578, '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': '6498180', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1442, 'n_words': 703}