
    Q
i                     8    d dl Z d dlmZmZ  G d d          ZdS )    N)OptionalPatternc                   J    e Zd ZdZdZdZddee         fdZdde	d	e
d
e	fdZdS )TokenEscaperzQEscape punctuation within an input string.

    Adapted from RedisOM Python.
    z([,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ \?]z%[,.<>{}\[\]\\\"\':;!@#$%^&()\-+=~\/ ]Nescape_chars_rec                     |r|| _         nt          j        | j                  | _         t          j        | j                  | _        d S N)escaped_chars_rerecompileDEFAULT_ESCAPED_CHARSESCAPED_CHARS_NO_WILDCARDescaped_chars_no_wildcard_re)selfr   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\redisvl/utils/token_escaper.py__init__zTokenEscaper.__init__   sF     	K$3D!!$&Jt/I$J$JD!,.Jt7U,V,V)))    Fvaluepreserve_wildcardsreturnc                     t          |t                    st          dt          |                     d }|r| j                            ||          S | j                            ||          S )at  Escape special characters in a string for use in Redis queries.

        Args:
            value: The string value to escape.
            preserve_wildcards: If True, preserves * characters for wildcard
                matching. Defaults to False.

        Returns:
            The escaped string.

        Raises:
            TypeError: If value is not a string.
        z;Value must be a string object for token escaping, got type c                 6    |                      d          }d| S )Nr   \)group)matchr   s     r   escape_symbolz*TokenEscaper.escape.<locals>.escape_symbol,   s    KKNNE<<r   )
isinstancestr	TypeErrortyper   subr
   )r   r   r   r   s       r   escapezTokenEscaper.escape   s     %%% 	[dSXkk[[  	  	  	   	O488NNN$((>>>r   r	   )F)__name__
__module____qualname____doc__r   r   r   r   r   r   boolr"    r   r   r   r      s          H !IW W(9 W W W W? ?C ?T ?c ? ? ? ? ? ?r   r   )r   typingr   r   r   r(   r   r   <module>r*      sX    				 $ $ $ $ $ $ $ $-? -? -? -? -? -? -? -? -? -?r   