o
    ȷe
                     @   sz   d gZ zddlmZmZ eefZW n ey   eZdZY nw dd  Zdd Ze	dkr;ddl
Z
e
 Zee  dS dS )generic    )	ClassTypeInstanceTypeNc                    s   t  fdd}t t|ijfdd}i   j fdd}fdd}j|_j |_j|_j|_||_||_	|_
 fd	d
|_fdd
|_|S )z Create a simple generic functionc                     sV   | d j }t|j|tfi jD ]} |}|ur#|| i |  S q| i |S )Nr   )	__class__type__name__object__mro__)argskwclstf)_gbt	_sentinelfunc D/var/www/ideatree/venv/lib/python3.10/site-packages/simplegeneric.py	_by_class   s   

zgeneric.<locals>._by_classc                     s6    D ]}t |tstd|f q fdd}|S )zADecorator to add a method that will be called for the given typesz%r is not a type or classc                    s.   D ]}  || | urtd|f q| S )Nz!%r already has method for type %r)
setdefault	TypeError)r   r   )_by_typer   typesr   r   decorate!   s   
z,generic.<locals>.when_type.<locals>.decorate)
isinstance
classtypesr   )r   r   r   )r   r   )r   r   	when_type   s   
zgeneric.<locals>.when_typec                     s    fdd}|S )z>Decorator to add a method to be called for the given object(s)c                    s:   D ]}  t||| fd | urtd|f q| S )N   z#%r already has method for object %r)r   idr   )r   o)
_by_objectr   obsr   r   r   /   s   
z.generic.<locals>.when_object.<locals>.decorater   )r!   r   )r    r   )r!   r   when_object-   s   zgeneric.<locals>.when_objectc                     sr    t | d }|u r0t| d jD ]}|}|ur(|| i |  S q| i |S |d | i |S )Nr   r   )r   r   r	   )r
   r   r   r   )_gbor   r   r   r   r   dispatch9   s   
zgeneric.<locals>.dispatchc                    s   t |  v S N)r   )r   )r    r   r   <lambda>M   s    zgeneric.<locals>.<lambda>c                    s   |  v S r%   r   )r   )r   r   r   r&   N   s    )r   r   getr   __dict__copy__doc__
__module__r   r"   default
has_objecthas_type)r   r   r   r"   r$   r   )r    r   r#   r   r   r   r   r   	   s&   	c                  C   s   dd l } | jd| j| jB dS )Nr   z
README.txt)optionflags)doctestDocFileSuiteELLIPSISREPORT_ONLY_FIRST_FAILURE)r0   r   r   r   
test_suiteS   s
   
r4   __main__)__all__r   r   r   r   r   ImportErrorr   r4   r   unittestTextTestRunnerrrunr   r   r   r   <module>   s    J