
    g3fiY              	         U d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZmZmZmZ erddl
mZ  ej                   e      Zeed   eeef   z     Zd	ed
<   dada G d de      ZddZ	 	 	 	 	 	 	 	 d dZ	 	 	 	 	 	 	 	 d!dZd"dZ	 d#	 	 	 	 	 	 	 d$dZd%dZ 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&dZ!d'dZ"i Z#ded<    e	i       Z$ded<   de$e$ddddddf		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZ%y))zDAdapted from https://github.com/noahmorrison/chevron.

MIT License.
    )annotationsN)IteratorMappingSequence)MappingProxyType)TYPE_CHECKINGAnyLiteralcast)	TypeAlias)Fr   r   Scopes   c                      e Zd ZdZy)ChevronErrorz$Custom exception for Chevron errors.N)__name__
__module____qualname____doc__     [/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/utils/mustache.pyr   r       s    .r   r   c                    	 | j                  |d      \  }} t        |j                  d      z  a|| fS # t        $ r | dfcY S w xY w)zParse a literal from the template.

    Args:
        template: The template to parse.
        l_del: The left delimiter.

    Returns:
        The literal and the template.
    r   
 )split_CURRENT_LINEcount
ValueError)templatel_delliterals      r   grab_literalr"   )   sW    $NN5!4t,, X	  "~s   -3 AAc                    |j                  d      dk7  s|r+|j                  dd      d   }|j                         xs | S y)a
  Do a preliminary check to see if a tag could be a standalone.

    Args:
        template: The template. (Not used.)
        literal: The literal.
        is_standalone: Whether the tag is standalone.

    Returns:
        Whether the tag could be a standalone.
    r   r   )maxsplitF)findrsplitisspace)r   r!   is_standalonepaddings       r   
l_sa_checkr+   B   sG      ||DR=...226
  /K/r   c                j    |r1|dvr-| j                  dd      }|d   j                         xs |d    S y)a  Do a final check to see if a tag could be a standalone.

    Args:
        template: The template.
        tag_type: The type of the tag.
        is_standalone: Whether the tag is standalone.

    Returns:
        Whether the tag could be a standalone.
    >   variable	no escaper   r   r   F)r   r(   )r   tag_typer)   
on_newlines       r   
r_sa_checkr1   \   sE      )BB^^D!,
 !}$$&;jm*;; r   c           	        ddddddddd	}	 | j                  |d
      \  }} |j	                         sdt         }t        |      |j                  |d   d      }|dk7  r|d
d }|dk(  r-|j                  d      rd}|dd }n;dt         }t        |      |dk(  r"|dk(  r|dk(  r| j                  d      r| d
d } d}||j	                         f| fS # t        $ r}dt         }t        |      |d}~ww xY w)a:  Parse a tag from a template.

    Args:
        template: The template.
        l_del: The left delimiter.
        r_del: The right delimiter.

    Returns:
        The tag and the template.

    Raises:
        ChevronError: If the tag is unclosed.
        ChevronError: If the set delimiter tag is unclosed.
    commentsectioninverted sectionendpartialset delimiter?z
no escape?r.   )!#^/>={&r   zunclosed tag at line Nzempty tag at line r   r-   r>   set delimiterr$   z#unclosed set delimiter tag
at line {{}}})r   r   r   r   stripgetendswith
startswith)r   r    r_del	tag_typestagemsgr/   s           r   	parse_tagrN   v   sG     	I' ua0X 99;"=/23 }}SVZ0H :!"g ##<<&Hcr(C 9HCs## 	L  TMTM$ AB< syy{#X..Y  '%m_53Q&'s   C 	C5C00C5rB   rC   c              #    K   da dad}g }|}|}| rt        | |      \  }} | sd|f nt        | ||      }t	        | ||      \  }} |\  }	}
|	dk(  r*|
j                         j                  d      }|d   |d   }}nT|	d	v r|j                  |
       t         an8|	d
k(  r3	 |j                         }|
|k7  rd|
 d| dt         dz    }t        |      t        | |	|      }|r+| j                  dd      d   } |	dk7  r|j                  d      }|rd|f |	dvr|	|
f | r|rd|d    dt         }t        |      y# t        $ r }d|
 dt         dz    }t        |      |d}~ww xY ww)ap  Tokenize a mustache template.

    Tokenizes a mustache template in a generator fashion,
    using file-like objects. It also accepts a string containing
    the template.

    Args:
        template: a file-like object, or a string of a mustache template
        def_ldel: The default left delimiter
            ("{{" by default, as in spec compliant mustache)
        def_rdel: The default right delimiter
            ("}}" by default, as in spec compliant mustache)

    Yields:
        Mustache tags in the form of a tuple (tag_type, tag_key)
        where tag_type is one of:

        * literal
        * section
        * inverted section
        * end
        * partial
        * no escape

        and tag_key is either the key or in the case of a literal tag,
        the literal itself.

    Raises:
        ChevronError: If there is a syntax error in the template.
    r   NTr!   rA    r   r$   >   r4   r5   r6   zTrying to close tag "z%"
Looks like it was not opened.
line z"
last open tag is "z"
line r   r7   >   r3   r8   zUnexpected EOF
the tag "z&" was never closed
was opened at line )r   _LAST_TAG_LINEr"   r+   rN   rE   r   appendpop
IndexErrorr   r1   rstrip)r   def_ldeldef_rdelr)   open_sectionsr    rI   r!   rK   r/   tag_keydelslast_sectionrL   rM   s                  r   tokenizer\      s    D MNMMEE
(59 g&& #8WmD "(E59X'
 &==?((-D7DH5E 88  )*N /,002 ,& ,G9 5))5 7)A-.0 
 #3'' #8X}E ~~dA.r2H 9$!..- g&& 88W%%Q V %b)* +""0!13 	
 3 O  /+G9 5)A-.0 
 #3'Q./s1   BE(D< -A0E(E(<	E%E  E%%E(c                    dddd}| j                  dd      } |j                         D ]  \  }}| j                  ||      }  | S )zHReturn the HTML-escaped string with these characters escaped: `" & < >`.z&quot;z&lt;z&gt;)"<r=   r@   z&amp;)replaceitems)string
html_codescharcodes       r   _html_escaperf   K  sW     J ^^C)F &&( ,
dd+,Mr   c                  | dk(  r|d   S |D ]  }	 |dv r|c S |}| j                  d      D ]w  }|dv r|c c S t        |t              r	 ||   }$t        |t
        t        f      r	 |t        |         }Jd	t        |      j                   d
t        |       }	t	        |	       	 |j                  r|c S  |rt        j                  d|        |r
| d|  d| S y# t        t        f$ r d|d}	t        |	      dw xY w# t        t        t        f$ r d|d}	t        |	      dw xY w# t        $ r |dv r|cY c S |xs dcY c S w xY w# t        t        t        t        t        f$ r Y bw xY w)aO  Retrieve a value from the current scope using a dot-separated key path.

    Traverses through nested dictionaries and lists using dot notation.

    Supports special key `'.'` to return the current scope.

    Args:
        key: Dot-separated key path (e.g., `'user.name'` or `'.'` for current scope).
        scopes: List of scope dictionaries to search through.
        warn: Whether to log a warning when a key is not found.
        keep: Whether to return the original template tag when key is not found.
        def_ldel: Left delimiter for template (used when keep is `True`).
        def_rdel: Right delimiter for template (used when keep is `True`).

    Returns:
        The value found at the key path.

            If not found, returns the original template tag when keep is `True`,
            otherwise returns an empty string.
    .r   )r   FzKey z not found in dictNzInvalid index z for list/tuplezCannot traverse into z>. Mustache templates only support dict, list, and tuple. Got: r   zCould not find key '%s'rP   )r   
isinstancedictKeyError	TypeErrorlisttupleintr   rT   typer    _CHEVRON_return_scope_when_falsyAttributeErrorloggerwarning)
keyscopeswarnkeeprV   rW   scoperesolved_scopechildrM   s
             r   _get_keyr|   Z  s   < czay  43	 
""N3 ) "Z/))nd36)7)>
  u>8)7E
)C 0^0D0M0M/N O  $^ 457 
 $C.(9)<, "BB)) CU4p 0#61SE8*--Y %i0 6 $UI-?@&sm56 '
I> 8 .uiG(o478& " ,!Z/))%++, *j)L 	 		su   EEE
CE'D51E'D-"D  E'D**E-E<E EE
EEE0/E0c                ,    	 ||    S # t         $ r Y yw xY w)z7Load a partial.

    Returns:
        The partial.
    r   )rk   )namepartials_dicts     r   _get_partialr     s$    T"" s    	z dict[str, list[tuple[str, str]]]g_token_cachezMappingProxyType[str, str]
EMPTY_DICTr   Fc	                z   t        | t              rt        | t              s
d | D        }	n&| t        v rd t        |    D        }	nt	        |       }	d}
|g|	D ]  \  }}d   }|dk(  rd= |s&t              dk7  r|dv s*j                  dd       =|d	k(  r|
|j                  d
d
z         z  }
[|dk(  rIt        |      }|du r
|dk(  rd   }t        |t              st        |      }|
t        |      z  }
|dk(  r2t        |      }t        |t              st        |      }|
|z  }
|dk(  rEt        |      }t        |      rd}g }|	D ]b  }|d|fk(  r nY|j                  |       |\  }}|d	k(  r||z  }-|dk(  r| d| d z  }@|dj                  ddddddddd|   |      z  }d |t        |<    ||d$fd	      }|
|z  }
t        |t        t        f      rqt        |t              sag }d}|	D ]2  }|d|fk(  r|dz  }|d|fk(  r|dz  }|dk  r n|j                  |       4 |D ]  }|g}t        ||      }|
|z  }
! j                  d|       +|dk(  r0t        |      }j                  dt        d|              `|d k(  sgt!        |      }|
j#                  d
      d!   }}|j%                         r||z  }t        ||"      }|j%                         r|j'                  d#      }|
|z  }
 |
S )%au  Render a mustache template.

    Renders a mustache template with a data scope and inline partial capability.

    Args:
        template: A file-like object or a string containing the template.
        data: A python dictionary with your data scope.
        partials_path: The path to where your partials are stored.
             If set to None, then partials won't be loaded from the file system
             (defaults to '.').
        partials_ext: The extension that you want the parser to look for
            (defaults to 'mustache').
        partials_dict: A python dictionary which will be search for partials
             before the filesystem is. {'include': 'foo'} is the same
             as a file called include.mustache
             (defaults to {}).
        padding: This is for padding partials, and shouldn't be used
            (but can be if you really want to).
        def_ldel: The default left delimiter
             ("{{" by default, as in spec compliant mustache).
        def_rdel: The default right delimiter
             ("}}" by default, as in spec compliant mustache).
        scopes: The list of scopes that get_key will look through.
        warn: Log a warning when a template substitution isn't found in the data
        keep: Keep unreplaced tags when a substitution isn't found in the data.

    Returns:
        A string containing the rendered template.
    c              3      K   | ]  }|  y wNr   .0tokens     r   	<genexpr>zrender.<locals>.<genexpr>  s     ,IuU,I   c              3      K   | ]  }|  y wr   r   r   s     r   r   zrender.<locals>.<genexpr>  s     =E%=r   r   r   r6   r   >   r4   r5   Fr!   r   r-   )rw   rx   rV   rW   Trh   r.   r4   z& rP   z	{}{} {}{}r9   r:   r;   r<   r=   r>   r@   )r3   r4   r5   r6   r7   rA   r.   r-   c                B    t        | i |xr |gxs 	      S )N)datar   r*   rV   rW   rv   rw   rx   )render)	r   r   rV   rW   rx   r*   r   rv   rw   s	     r   <lambda>zrender.<locals>.<lambda>e  s7     &3 '!)!) $ 8$CV!!
1 r   )r   rv   r*   r   rV   rW   rw   rx   r5   zLiteral[False]r7      )r   r   rV   rW   r*   rv   rw   rx   z 	r   )ri   r   strr   r\   leninsertr`   r|   rf   callablerR   formatr   r   r   r   
rpartitionr(   rU   )r   r   r   r*   rV   rW   rv   rw   rx   tokensoutputrK   ru   current_scopethingry   texttagsr   r/   rY   rendtags_with_same_key	new_scoper7   leftpart_paddingpart_outs     ```````                   r   r   r     s2   R (H%j3.G -J,I	]	"=]8%<= (Hh7F~  uSq	 %<q	 3v;!#355a' Ickk$w77F JV$THxE } q	eS)E
l5))F KV$THxE eS)E
eOF IV$THxE .0# E,KK&(-%Hg9,![08*Bwiq
 CC 2 2$+.+.47'*+.14-0,.	 '	( $$! 6 '+d#
 
 $ EHh#78ESVAW %&"# 'EC 00*a/*,*a/*-1!KK&' # #E!& 0 0I!!%( '&3!)!)!!	D dNF#$ a' &&V$THxE MM!T"2I>? I"36G $$T*1-D"L||~$  +!!$	H ||~#??51 hFkun Mr   )r   r   r    r   returnztuple[str, str])r   r   r!   r   r)   boolr   r   )r   r   r/   r   r)   r   r   r   )r   r   r    r   rI   r   r   ztuple[tuple[str, str], str])rB   rC   )r   r   rV   r   rW   r   r   zIterator[tuple[str, str]])rb   r   r   r   )ru   r   rv   r   rw   r   rx   r   rV   r   rW   r   r   r	   )r~   r   r   Mapping[str, str]r   r   )r   zstr | list[tuple[str, str]]r   zMapping[str, Any]r   r   r*   r   rV   r   rW   r   rv   zScopes | Nonerw   r   rx   r   r   r   )&r   
__future__r   loggingcollections.abcr   r   r   typesr   typingr   r	   r
   r   r   	getLoggerr   rs   rm   r   r   __annotations__r   rQ   SyntaxErrorr   r"   r+   r1   rN   r\   rf   r|   r   r   r   r   r   r   r   <module>r      s  
 #  7 7 "   			8	$ *WS#X->>?	 ? /; /2  
	4  
	4I/d :>| |  | 36| | Ha	aa 	a
 a a a 	aH
  35/ 4)9")=
& = -/('1 p)p
p %p 	p
 p p p p p 	pr   