
    j                     v    d dl Z d dlZd dlmZ  G d de j                        Z G d de      Z G d de      Zy)	    N)Callablec                   >    e Zd ZdZej
                  dedefd       Zy)RulezAbstract base class for text anonymization rules.

    Rules define specific patterns or conditions for anonymizing sensitive
    information in text. Subclasses must implement the apply() method to
    define the anonymization logic.
    textreturnc                      y N selfr   s     n/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/anonymizer/rules.pyapplyz
Rule.apply   s        N)__name__
__module____qualname____doc__abcabstractmethodstrr   r
   r   r   r   r      s/     	# #  r   r   c                   0    e Zd ZdZdedefdZdedefdZy)		RegexRulezA rule that uses regular expressions to find and replace patterns in text.

    This rule compiles a regular expression pattern and applies it to input text,
    replacing all matches with a specified replacement string.
    regexreplacementc                 F    t        j                  |      | _        || _        y)zInitialize the regex rule with a pattern and replacement.

        Args:
            regex: Regular expression pattern to match sensitive data.
            replacement: String to replace matched patterns with.
        N)recompilepatternr   )r   r   r   s      r   __init__zRegexRule.__init__   s     zz%(&r   r   r   c                 N    | j                   j                  | j                  |      S r	   )r   subr   r   s     r   r   zRegexRule.apply$   s    || 0 0$77r   N)r   r   r   r   r   r   r   r
   r   r   r   r      s-    'c ' '8# 8# 8r   r   c                   8    e Zd ZdZdeegef   fdZdedefdZy)FunctionRulezA rule that applies a custom function to anonymize text.

    This rule allows for flexible anonymization by accepting any callable
    that takes a string as input and returns an anonymized string.
    funcc                     || _         y)zInitialize the function rule with a custom anonymization function.

        Args:
            func: A callable that takes a string and returns an anonymized version.
        Nr$   )r   r$   s     r   r   zFunctionRule.__init__/   s     	r   r   r   c                 $    | j                  |      S r	   r&   r   s     r   r   zFunctionRule.apply7   s    yyr   N)r   r   r   r   r   r   r   r   r
   r   r   r#   r#   (   s1    XseSj1 # # r   r#   )r   r   typingr   ABCr   r   r#   r
   r   r   <module>r*      s6    
 	 
377 
8 8*4 r   