a
    Ad'                     @   s0   d dl mZ dd Zdd Zdd ZeeZdS )	    )defaultdictc                 C   sJ   ||f}|t |  v r$td| dt||}|t |  |< t||| |S )a#  Replaces a function in a module or a class.

    Also stores the original function in this module, possible to be retrieved via original(key, obj, field).
    If the function is already replaced by this caller (key), an exception is raised -- use undo() before that.

    Arguments:
        key: identifying information for who is doing the replacement. You can use __name__.
        obj: the module or the class
        field: name of the function as a string
        replacement: the new function

    Returns:
        the original function
    z
patch for z is already applied)	originalsRuntimeErrorgetattrsetattr)keyobjfieldreplacement	patch_keyoriginal_func r   7/var/www/html/stable-diffusion-webui/modules/patches.pypatch   s    
r   c                 C   sB   ||f}|t |  vr$td| dt |  |}t||| dS )aJ  Undoes the peplacement by the patch().

    If the function is not replaced, raises an exception.

    Arguments:
        key: identifying information for who is doing the replacement. You can use __name__.
        obj: the module or the class
        field: name of the function as a string

    Returns:
        Always None
    zthere is no patch for z to undoN)r   r   popr   )r   r   r	   r   r   r   r   r   undo    s    r   c                 C   s   ||f}t |  |dS )zKReturns the original function for the patch created by the patch() functionN)r   get)r   r   r	   r   r   r   r   original9   s    r   N)collectionsr   r   r   r   dictr   r   r   r   r   <module>   s   