
    j                     .    d dl mZ  G d de          ZdS )    )CoreEnforcerc                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )InternalEnforcerz9
    InternalEnforcer = CoreEnforcer + Internal API.
    c                 p   | j                             |||          }|s|S | j        r| j        r| j                            |||          du rdS | j        r`| j        rYt          t          | j        dd                    r| j                            |||           n| j        	                                 |S )z"adds a rule to the current policy.Fupdate_for_add_policyN)
model
add_policyadapter	auto_savewatcherauto_notify_watchercallablegetattrr   update)selfsecptyperule
rule_addeds        b/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/casbin/internal_enforcer.py_add_policyzInternalEnforcer._add_policy   s    Z**3t<<
 	< 	*DN 	*|&&sE488EAAu| * 8 *GDL2I4PPQQ *L66sE4HHHHL'')))    c                    | j                             |||          }|s|S | j        r| j        rt	          | j        d          du rdS | j                            |||          du rdS | j        r`| j        rYt          t          | j        dd                    r| j        	                    |||           n| j        
                                 |S )z!adds rules to the current policy.add_policiesFupdate_for_add_policiesN)r   r   r
   r   hasattrr   r   r   r   r   r   )r   r   r   rulesrules_addeds        r   _add_policieszInternalEnforcer._add_policies)   s    j--c5%@@ 	< 	*DN 	*t|^44==u|((eU;;uDDu| * 8 *GDL2KTRRSS *L88eUKKKKL'')))r   c                     | j                             ||||          }|s|S | j        rO| j        rH| j                            ||||          du rdS | j        r | j        r| j                                         |S )z'updates a rule from the current policy.F)r   update_policyr
   r   r   r   r   )r   r   r   old_rulenew_rulerule_updateds         r   _update_policyzInternalEnforcer._update_policy>   s    z//UHhOO 	 < 	&DN 	&|))#uhIIURRu| & 8 &##%%%r   c                     | j                             ||||          }|s|S | j        rO| j        rH| j                            ||||          du rdS | j        r | j        r| j                                         |S )z&updates rules from the current policy.F)r   update_policiesr
   r   r   r   r   )r   r   r   	old_rules	new_rulesrules_updateds         r   _update_policiesz!InternalEnforcer._update_policiesN   s    
223y)TT 	!  < 	&DN 	&|++C	9MMQVVVu| & 8 &##%%%r   c                     | j         j        |||g|R  }| j        r&| j        r	  | j        j        ||||g|R  }n#  Y nxY w|sdS | j                             |||          }| j                             |||           |ot          |          dk    }|s|S |dk    r|                                  | j	        r | j
        r| j	                                         |S )z?_update_filtered_policies deletes old rules and adds new rules.Fr   g)r   get_filtered_policyr
   r   update_filtered_policiesremove_policiesr   lenbuild_role_linksr   r   r   )r   r   r   r)   field_indexfield_valuesr(   is_rule_changeds           r   _update_filtered_policiesz*InternalEnforcer._update_filtered_policies^   s    3DJ23{Z\ZZZ	< 	DN 	ADLA#uiYdtgsttt		 	5*44S%KK
UI666)Ac)nn.A 	#""#::!!###< 	"D4 	"L!!!s	   < A c                 p   | j                             |||          }|s|S | j        r| j        r| j                            |||          du rdS | j        r`| j        rYt          t          | j        dd                    r| j                            |||           n| j        	                                 |S )z'removes a rule from the current policy.Fupdate_for_remove_policyN)
r   remove_policyr
   r   r   r   r   r   r8   r   )r   r   r   r   rule_removeds        r   _remove_policyzInternalEnforcer._remove_policyw   s    z//UDAA 	 < 	*DN 	*|))#ud;;uDDu| * 8 *GDL2LdSSTT *L99#udKKKKL'')))r   c                    | j                             |||          }|s|S | j        r| j        rt	          | j        d          du rdS | j                            |||          du rdS | j        r`| j        rYt          t          | j        dd                    r| j        	                    |||           n| j        
                                 |S )z3RemovePolicies removes policy rules from the model.r0   Fupdate_for_remove_policiesN)r   r0   r
   r   r   r   r   r   r   r=   r   )r   r   r   r   rules_removeds        r   _remove_policiesz!InternalEnforcer._remove_policies   s    
223uEE 	!  < 	*DN 	*t|%6775@@u|++C>>%GGu| * 8 *GDL2NPTUUVV *L;;CNNNNL'')))r   c                 F    | j         j        |||g|R  }|s|S | j        r| j        ry | j        j        |||g|R  du rdS | j        rY| j        rRt          t          | j        dd                    r | j        j        |||g|R   n| j        	                                 |S )=removes rules based on field filters from the current policy.F!update_for_remove_filtered_policyN)
r   remove_filtered_policyr
   r   r   r   r   r   rB   r   r   r   r   r3   r4   r:   s         r   _remove_filtered_policyz(InternalEnforcer._remove_filtered_policy   s    8tz8e[`S_``` 	 < 	*DN 	*2t|23{Z\ZZZ^cccu| * 8 *GDL2UW[\\]] *BDLB3{j]ijjjjjL'')))r   c                      | j         j        |||g|R  }t          |          dk    r|S | j        rG| j        r@ | j        j        |||g|R  du rdS | j        r | j        r| j                                         |S )rA   r   F)	r   &remove_filtered_policy_returns_effectsr1   r
   r   rC   r   r   r   rD   s         r   '_remove_filtered_policy_returns_effectsz8InternalEnforcer._remove_filtered_policy_returns_effects   s    HtzHeU`pcoppp|!!< 	&DN 	&2t|23{Z\ZZZ^cccu| & 8 &##%%%r   c                 8    | j                             ||          S )z!gets the index of the field name.)r   get_field_index)r   r   fields      r   rJ   z InternalEnforcer.get_field_index   s    z))%777r   c                 @    | j         d         |         }||j        |<   dS )z!sets the index of the field name.pN)r   field_index_map)r   r   rK   index	assertions        r   set_field_indexz InternalEnforcer.set_field_index   s%    JsOE*	+0	!%(((r   N)__name__
__module____qualname____doc__r   r   r%   r+   r6   r;   r?   rE   rH   rJ   rQ    r   r   r   r      s           $  *        2  $  *  $  8 8 81 1 1 1 1r   r   N)casbin.core_enforcerr   r   rV   r   r   <module>rX      sW    . - - - - -t1 t1 t1 t1 t1| t1 t1 t1 t1 t1r   