
    w;3h                        d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d d      Z
 G d	 d
      Z G d de      Zy)    )annotations)copy)Any)
ParseError)UnexpectedCharError)TOMLCharc                  6    e Zd Z	 	 d	 	 	 	 	 	 	 ddZddZd Zy)_Statec                .    || _         || _        || _        y N)_source_save_markerrestore)selfsourcesave_markerr   s       N/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/tomlkit/source.py__init__z_State.__init__   s     '    c                    t        | j                  j                        | _        | j                  j                  | _        | j                  j                  | _        | j                  j
                  | _        | S r   )r   r   _chars_idx_current_markerr   s    r   	__enter__z_State.__enter__   sP    4<<../LL%%	--||++r   c                   | j                   s|rz| j                  | j                  _        | j                  | j                  _        | j                  | j                  _        | j
                  r| j                  | j                  _        y y y r   )r   r   r   r   r   r   r   )r   exception_typeexception_valtraces       r   __exit__z_State.__exit__   s^    <<>"&++DLL $		DLL$(MMDLL!  '+||$ !	 *r   N)FF)r   Sourcer   bool | Noner   r#   returnNoner$   r
   )__name__
__module____qualname__r   r   r!    r   r   r
   r
      s?     $)$	 ! 	
 
4r   r
   c                  ,    e Zd ZdZddZd ZddZd Zy)	_StateHandlerz)
    State preserver for the Parser.
    c                     || _         g | _        y r   )r   _states)r   r   s     r   r   z_StateHandler.__init__.   s    r   c                4    t        | j                  g|i |S r   )r
   r   )r   argskwargss      r   __call__z_StateHandler.__call__2   s    dll4T4V44r   c                f     |        }| j                   j                  |       |j                         S r   )r.   appendr   )r   states     r   r   z_StateHandler.__enter__5   s(    E"  r   c                \    | j                   j                         }|j                  |||      S r   )r.   popr!   )r   r   r   r    r5   s        r   r!   z_StateHandler.__exit__:   s'      "~~nmUCCr   N)r   r"   r$   r%   r&   )r'   r(   r)   __doc__r   r2   r   r!   r*   r   r   r,   r,   )   s    5!
Dr   r,   c                       e Zd Z ed      Zd fdZd Zedd       Zedd       Z	edd       Z
edd       ZddZddd	Zddd
ZddZddZddZef	 	 	 	 	 	 	 ddZddZ xZS )r"    c           
        t         |           t        t        |       D cg c]  \  }}|t	        |      f c}}      | _        d| _        d| _        t	        d      | _        t        |       | _
        | j                          y c c}}w )Nr    )superr   iter	enumerater   r   r   r   r   r,   _stateinc)r   _ic	__class__s       r   r   zSource.__init__B   sl     4IAQ,IJ	 #D)
 Js   B
c                D    | j                          | j                          y r   )rA   markr   s    r   resetzSource.resetP   s    
 			r   c                    | j                   S r   )r@   r   s    r   r5   zSource.stateW   s    {{r   c                    | j                   S r   )r   r   s    r   idxz
Source.idx[   s    yyr   c                    | j                   S r   )r   r   s    r   currentzSource.current_   s    }}r   c                    | j                   S r   )r   r   s    r   markerzSource.markerc   s    ||r   c                4    | | j                   | j                   S )z=
        Extracts the value between marker and index
        )r   r   r   s    r   extractzSource.extractg   s     DLL499--r   c                    	 t        | j                        \  | _        | _        y# t        $ r8 t        |       | _        | j                  | _        |r| j                  |      dY yw xY w)z
        Increments the parser if the end of the input has not been reached.
        Returns whether or not it was able to advance.
        TNF)nextr   r   r   StopIterationlenEOFparse_error)r   	exceptions     r   rA   z
Source.incm   s_    

	'+DKK'8$DIt} 	D	DI HHDM&&y1t;	s   "% >A&%A&c                B     t         fdt        |      D              S )zm
        Increments the parser by n characters
        if the end of the input has not been reached.
        c              3  B   K   | ]  }j                           yw))rX   N)rA   ).0rB   rX   r   s     r   	<genexpr>zSource.inc_n.<locals>.<genexpr>   s     CQ488i80Cs   )allrange)r   nrX   s   ` `r   inc_nzSource.inc_n~   s    
 C%(CCCr   c                    | j                   |v r4|dk7  r/|dz  }|dz  }| j                         sn| j                   |v r|dk7  r/|dkD  r | j                  t        | j                         y)zD
        Consume chars until min/max is satisfied is valid.
        r      N)rM   rA   rW   r   )r   charsminmaxs       r   consumezSource.consume   sn     lle#q1HC1HC88:	 lle#q 7""#6EE r   c                2    | j                   | j                  u S )zN
        Returns True if the parser has reached the end of the input.
        )r   rV   r   s    r   endz
Source.end   s     }}((r   c                &    | j                   | _        y)zA
        Sets the marker to the index's current position
        N)r   r   r   s    r   rG   zSource.mark   s     yyr   c                B    | j                         \  }} |||g|i |S )zJ
        Creates a generic "parse error" at the current position.
        )_to_linecol)r   rX   r0   r1   linecols         r   rW   zSource.parse_error   s-     $$&	cs4T4V44r   c                   d}t        | j                               D ]J  \  }}|t        |      z   dz   | j                  kD  r|dz   | j                  |z
  fc S |t        |      dz   z  }L t        | j                               dfS )Nr   rb   )r?   
splitlinesrU   rK   )r   currC   rl   s       r   rk   zSource._to_linecol   s     !23 	!GAtSY"TXX-Atxx#~..3t9q= C		! 4??$%q((r   )rB   strr$   r%   )r$   r,   )r$   int)r$   r   )r$   rq   r   )rX   type[ParseError] | Noner$   bool)r_   rr   rX   rs   r$   rt   )r   )r$   rt   )r$   r%   )rX   ztype[ParseError]r0   r   r1   r   r$   r   )r$   ztuple[int, int])r'   r(   r)   r   rV   r   rH   propertyr5   rK   rM   rO   rQ   rA   r`   rf   rh   rG   r   rW   rk   __classcell__)rE   s   @r   r"   r"   ?   s    
4.C        ."DF)! '15#5 5 	5
 
5)r   r"   N)
__future__r   r   typingr   tomlkit.exceptionsr   r   tomlkit.toml_charr   r
   r,   rq   r"   r*   r   r   <module>r|      s;    "   ) 2 &4 4<D D,u)S u)r   