o
    Uh                     @  sx   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 dZ
G d	d
 d
ZG dd deZdS )    )annotations)copy)Any)
ParseError)UnexpectedCharErrorTOMLCharc                   @  s.   e Zd Z		ddd	d
ZdddZdd ZdS )_StateFsourceSourcesave_markerbool | NonerestorereturnNonec                 C  s   || _ || _|| _d S N)_source_save_markerr   )selfr
   r   r    r   b/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/tomlkit/source.py__init__   s   
z_State.__init__c                 C  s0   t | jj| _| jj| _| jj| _| jj| _| S r   )r   r   _chars_idx_current_markerr   r   r   r   	__enter__   s
   


z_State.__enter__c                 C  sD   | j s|r | j| j_| j| j_| j| j_| jr| j| j_d S d S d S r   )r   r   r   r   r   r   r   )r   exception_typeexception_valtracer   r   r   __exit__   s   



z_State.__exit__N)FF)r
   r   r   r   r   r   r   r   r   r	   )__name__
__module____qualname__r   r   r!   r   r   r   r   r	      s    

	r	   c                   @  s4   e Zd ZdZdddZdd	 ZdddZdd ZdS )_StateHandlerz)
    State preserver for the Parser.
    r
   r   r   r   c                 C  s   || _ g | _d S r   )r   _states)r   r
   r   r   r   r   .   s   
z_StateHandler.__init__c                 O  s   t | jg|R i |S r   )r	   r   )r   argskwargsr   r   r   __call__2   s   z_StateHandler.__call__r	   c                 C  s   |  }| j | | S r   )r'   appendr   )r   stater   r   r   r   5   s   z_StateHandler.__enter__c                 C  s   | j  }||||S r   )r'   popr!   )r   r   r   r    r,   r   r   r   r!   :   s   
z_StateHandler.__exit__N)r
   r   r   r   r"   )r#   r$   r%   __doc__r   r*   r   r!   r   r   r   r   r&   )   s    

r&   c                      s   e Zd ZedZd2 fddZdd	 Zed3ddZed4ddZ	ed5ddZ
ed4ddZd6ddZd7d8ddZd7d9ddZd:d"d#Zd;d$d%Zd<d&d'Zefd=d-d.Zd>d0d1Z  ZS )?r    _strr   r   c                   sN   t    tdd t| D | _d| _d| _td| _t	| | _
|   d S )Nc                 S  s   g | ]
\}}|t |fqS r   r   ).0icr   r   r   
<listcomp>F   s    z#Source.__init__.<locals>.<listcomp>r    )superr   iter	enumerater   r   r   r   r   r&   _stateinc)r   r0   	__class__r   r   r   B   s   


zSource.__init__c                 C  s   |    |   d S r   )r;   markr   r   r   r   resetP   s   zSource.resetr&   c                 C     | j S r   )r:   r   r   r   r   r,   W      zSource.stateintc                 C  r@   r   )r   r   r   r   r   idx[   rA   z
Source.idxr   c                 C  r@   r   )r   r   r   r   r   current_   rA   zSource.currentc                 C  r@   r   )r   r   r   r   r   markerc   rA   zSource.markerc                 C  s   | | j | j S )z=
        Extracts the value between marker and index
        )r   r   r   r   r   r   extractg   s   zSource.extractN	exceptiontype[ParseError] | Noneboolc                 C  sP   zt | j\| _| _W dS  ty'   t| | _| j| _|r$| |dY dS 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   rG   r   r   r   r;   m   s   
z
Source.incnc                   s   t  fddt|D S )zm
        Increments the parser by n characters
        if the end of the input has not been reached.
        c                 3  s    | ]	}j  d V  qdS ))rG   N)r;   )r2   r0   rG   r   r   r   	<genexpr>   s    zSource.inc_n.<locals>.<genexpr>)allrange)r   rO   rG   r   rP   r   inc_n~   s   zSource.inc_nr   c                 C  sX   | j |v r|dkr|d8 }|d8 }|  sn	| j |v r|dks	|dkr*| t| j dS )zD
        Consume chars until min/max is satisfied is valid.
        r      N)rD   r;   rN   r   )r   charsminmaxr   r   r   consume   s   zSource.consumec                 C  s   | j | ju S )zN
        Returns True if the parser has reached the end of the input.
        )r   rM   r   r   r   r   end      z
Source.endc                 C  s   | j | _dS )zA
        Sets the marker to the index's current position
        N)r   r   r   r   r   r   r>      r\   zSource.marktype[ParseError]r(   r   r)   r   c                 O  s$   |   \}}|||g|R i |S )zJ
        Creates a generic "parse error" at the current position.
        )_to_linecol)r   rG   r(   r)   linecolr   r   r   rN      s   	zSource.parse_errortuple[int, int]c                 C  sf   d}t |  D ]"\}}|t| d | jkr"|d | j| f  S |t|d 7 }qt|  dfS )Nr   rV   )r9   
splitlinesrL   rC   )r   curr3   r_   r   r   r   r^      s   zSource._to_linecol)r0   r1   r   r   )r   r&   )r   rB   )r   r   )r   r1   r   )rG   rH   r   rI   )rO   rB   rG   rH   r   rI   )r   rU   )r   rI   )r   r   )rG   r]   r(   r   r)   r   r   r   )r   ra   )r#   r$   r%   r   rM   r   r?   propertyr,   rC   rD   rE   rF   r;   rT   rZ   r[   r>   r   rN   r^   __classcell__r   r   r<   r   r   ?   s*    



r   N)
__future__r   r   typingr   tomlkit.exceptionsr   r   tomlkit.toml_charr   r	   r&   r1   r   r   r   r   r   <module>   s    