
    e!h}                     R    d dl mZ d dlmZ d dlZd dlmZ d dlmZ  G d de      Z	y)    )Iterable)update_wrapperN)watchers)ConditionalElementc                   P     e Zd ZdZdd fd
Zd Zd Zd Zd Z fd	Z	d
 Z
 xZS )Rulea  
    Base ``CE``, all ``CE`` are to derive from this class.

    This class is used as a decorator, thus provoking __call__
    to be called twice:

    #. The first call is when the decorator is been created. At this
       point we assign the function decorated to ``self._wrapped`` and
       return ``self`` to be called the second time.

    #. The second call is to execute the decorated function, se we
       pass all the arguments along.
    r   )saliencec                h    t        t        | 
  | g| }d |_        g |_        d |_        ||_        |S N)superr   __new___wrapped_wrapped_args_wrapped_selfr	   )clsr	   argsobj	__class__s       T/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/experta/rule.pyr   zRule.__new__   s<    D#&s2T2 
    c                 z     | j                   |d| j                  i}| j                  r || j                        }|S )zf
        Generate a new rule with the same attributes but with the given
        conditions.

        r	   )r   r	   r   )selfr   r   s      r   new_conditionszRule.new_conditions"   s7     dnnd;T]];==dmm$C
r   c                 r    t        t        |       | j                  | j                  | j                  fz         S r   )hashtupler   r   r	   )r   s    r   __hash__zRule.__hash__/   s5    E$K}}d&8&8$--HI J 	Jr   c                     t        || j                        rct        |       | j                  | j                  | j
                  fz   }t        |      |j                  |j                  |j
                  fz   }||k(  S y)NF)
isinstancer   r   r   r   r	   )r   other	self_data
other_datas       r   __eq__zRule.__eq__3   st    eT^^,dt}}'+'9'9'+}}'6 6I u).)<)<).)9 9J 
**r   c                 X   | j                   |st        d      |d   | _         t        j                  | j                         }t	        d |j
                  j                         D              s(t        |j
                  j                               | _	        t        | | j                         S | j                  r1|j                         D ci c]  \  }}|| j                  v r|| }}}| j                   | j                   |i |S  | j                   | j                  g|i |S c c}}w )zs
        Make method checks if it's the first call, and update wrapper.
        Othersise execute the RHS.
        z Mandatory function not provided.r   c              3   j   K   | ]+  }|j                   t        j                  j                  k(   - y wr   )kindinspect	ParameterVAR_KEYWORD).0ps     r   	<genexpr>z Rule.__call__.<locals>.<genexpr>K   s/      C  66W%6%6%B%BB Cs   13)r   AttributeErrorr'   	signatureany
parametersvaluessetkeysr   r   itemsr   )r   r   kwargsr.   kvs         r   __call__zRule.__call__?   s   
 == $%GHH $Q#--dmm<	 C$-$8$8$?$?$AC C *-Y-A-A-F-F-H)ID&%dDMM::!!+1<<> 641a$"4"44 Q$ 6 6!!)$t}}d5f55$t}}T%7%7I$I&II6s   
D&c                 >    t         |          d| j                  S )Nz => )r   __repr__r   )r   r   s    r   r:   zRule.__repr__[   s    "W-/??r   c                     || _         | S r   )r   )r   instanceowners      r   __get__zRule.__get__^   s    %r   )__name__
__module____qualname____doc__r   r   r   r#   r8   r:   r>   __classcell__)r   s   @r   r   r   	   s3     &' J
J8@r   r   )
collections.abcr   	functoolsr   r'   expertar   experta.conditionalelementr   r    r   r   <module>rI      s#    $ $   9W Wr   