
    j                     0   d dl mZmZmZmZmZ ddlmZmZm	Z	 eeee
e
f      eee
e
f      eee
ge
f      eeee
e
f   ee
e
f   ee
ge
f   f      ee
e
f   ee
e
f   ee
ge
f   f   Z	 ddededej                  fdZdee
e
f   dd	fd
Zdee
e
f   dd	fdZy	)    )UnionListDictCallableTuple   )
anonymizerrules_anonymizerrulesanonymizer_rules	max_depthreturnc                    g }t        |       r&|j                  t        j                  |              nt	        | t
              r8t        |        |j                  t        j                  | d   | d                n_t	        | t              r7t        |        | \  }}|j                  t        j                  ||             nt	        | t              r| D ]  }t        |      r;t	        |t
        t        f      s%|j                  t        j                  |             It	        |t
              r7t        |       |j                  t        j                  |d   |d                t	        |t              r6t        |       |\  }}|j                  t        j                  ||             t        dt        |              nt        dt        |              t        j                  ||      S )av  Create an anonymizer with the specified rules.

    Args:
        anonymizer_rules: Anonymizer rules specification in various formats:
            - Dict with "regex" and "replace" keys for a single regex rule
            - Tuple with (regex, replacement) for a single regex rule
            - Callable that takes a string and returns anonymized string
            - List of any of the above for multiple rules
        max_depth: Maximum recursion depth for nested data structures.

    Returns:
        An Anonymizer instance configured with the specified rules.

    Raises:
        ValueError: If a rule format is invalid.
    regexreplacezUnsupported rule type in list: zUnsupported rules type: )r   )callableappendr   FunctionRule
isinstancedict_check_dictionary_rule	RegexRuletuple_check_tuple_rulelist
ValueErrortyper
   RulesAnonymizer)r   r   rule_objectsregex_patternreplacementrules         p/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/anonymizer/factory.pycreate_anonymizerr$      s   & &(L !E../?@A	$d	+/0OO,W57G	7RS	
 
$e	,*+%5"{EOOM;GH	$d	+$D~je}&E##E$6$6t$<=D$'&t,##EOODM4	?$STD%(!$'-1*{##EOOM;$OP #B4:,!OPP % 3D9I4J3KLMM++LINN    r"   Nc                 *    d| vsd| vrt        d      y )Nr   r   z4Dictionary rule must have 'regex' and 'replace' keys)r   r"   s    r#   r   r   G   s"    dit3OPP 4r%   c                 6    t        |       dk7  rt        d      y )N   z=Tuple rule must have exactly 2 elements: (regex, replacement))lenr   r'   s    r#   r   r   L   s"    
4yA~K
 	
 r%   )
   )typingr   r   r   r   r    r	   r
   r   str	RulesTypeint
Anonymizerr$   r   r    r%   r#   <module>r3      s   5 5 1 1c3hsCx3%*	tCH~uS#X#0DD	EFcN	#s(OcUCZ	 354O4O,/4O4OnQc3h QD Q

E#s(O 
 
r%   