a
    »ÏOcE  ã                   @   sÈ   d dl mZ d dl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 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 )é    )Úunicode_literalsN)Úcopy)ÚAny)ÚOptional)ÚTuple)ÚTypeé   )ÚPY2)Úunicode)Ú
ParseError)ÚUnexpectedCharError)ÚUnexpectedEofError©ÚTOMLCharc                   @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
Ú_StateFc                 C   s   || _ || _|| _d S ©N)Ú_sourceÚ_save_markerÚrestore)ÚselfÚsourceZsave_markerr   © r   úE/var/www/html/gsl.tools/lib/python3.9/site-packages/tomlkit/source.pyÚ__init__   s    z_State.__init__c                 C   sN   t rt | jj¡\| j_| _nt| jjƒ| _| jj| _| jj| _| jj| _| S r   )	r	   Ú	itertoolsÚteer   Ú_charsr   Ú_idxÚ_currentÚ_marker©r   r   r   r   Ú	__enter__   s    


z_State.__enter__c                 C   s<   | j s
|r8| j| j_| j| j_| j| j_| jr8| j| j_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)Ú__name__Ú
__module__Ú__qualname__r   r!   r%   r   r   r   r   r      s    ÿ
r   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú_StateHandlerz)
    State preserver for the Parser.
    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__>   s    z_StateHandler.__call__c                 C   s   | ƒ }| j  |¡ | ¡ S r   )r*   Úappendr!   )r   Ústater   r   r   r!   A   s    z_StateHandler.__enter__c                 C   s   | j  ¡ }| |||¡S r   )r*   Úpopr%   )r   r"   r#   r$   r/   r   r   r   r%   F   s    
z_StateHandler.__exit__N)r&   r'   r(   Ú__doc__r   r-   r!   r%   r   r   r   r   r)   5   s
   r)   c                       s¦   e Zd ZedƒZ‡ fdd„Zd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d„Zdd„ Zdd„ Zefdd„Zdd „ Z‡  ZS )$ÚSourceú c                    sR   t 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>R   ó    z#Source.__init__.<locals>.<listcomp>r   Ú )Úsuperr2   r   ÚiterÚ	enumerater   r   r   r   r   r)   Ú_stateÚinc)r   Ú_©Ú	__class__r   r   r   N   s    

zSource.__init__c                 C   s   |   ¡  |  ¡  d S r   )r>   Úmarkr    r   r   r   Úreset\   s    zSource.resetc                 C   s   | j S r   )r=   r    r   r   r   r/   c   s    zSource.statec                 C   s   | j S r   )r   r    r   r   r   Úidxg   s    z
Source.idxc                 C   s   | j S r   )r   r    r   r   r   Úcurrentk   s    zSource.currentc                 C   s   | j S r   )r   r    r   r   r   Úmarkero   s    zSource.markerc                 C   s   | | j | j… S )z=
        Extracts the value between marker and index
        )r   r   r    r   r   r   Úextracts   s    zSource.extractNc                 C   sR   zt | jƒ\| _| _W dS  tyL   t| ƒ| _| j| _|rF|  |¡‚Y dS 0 dS )zŒ
        Increments the parser if the end of the input has not been reached.
        Returns whether or not it was able to advance.
        TFN)Únextr   r   r   ÚStopIterationÚlenÚEOFÚparse_error)r   Ú	exceptionr   r   r   r>   y   s    

z
Source.incc                 C   s$   t |ƒD ]}| j|d�s dS qdS )zm
        Increments the parser by n characters
        if the end of the input has not been reached.
        )rM   FT)Úranger>   )r   ÚnrM   r?   r   r   r   Úinc_nŠ   s    zSource.inc_nr   éÿÿÿÿc                 C   sD   | j |v r.|dkr.|d8 }|d8 }|  ¡ s q.q |dkr@|  t¡ dS )zD
        Consume chars until min/max is satisfied is valid.
        r   r   N)rE   r>   rL   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   rK   r    r   r   r   Úend£   s    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   rB   ©   s    zSource.markc                 G   s   |   ¡ \}}|||g|¢R Ž S )zJ
        Creates a generic "parse error" at the current position.
        )Ú_to_linecol)r   rM   r+   ÚlineÚcolr   r   r   rL   ¯   s    zSource.parse_errorc                 C   sf   d}t |  ¡ ƒD ]D\}}|t|ƒ d | jkrD|d | j| f  S |t|ƒd 7 }qt|  ¡ ƒdfS )Nr   r   )r<   Ú
splitlinesrJ   rD   )r   Úcurr5   rX   r   r   r   rW   ¹   s    zSource._to_linecol)N)N)r   rQ   )r&   r'   r(   r   rK   r   rC   Úpropertyr/   rD   rE   rF   rG   r>   rP   rU   rV   rB   r   rL   rW   Ú__classcell__r   r   r@   r   r2   K   s(   






ÿ

r2   )Ú
__future__r   r   r   Útypingr   r   r   r   Ú_compatr	   r
   Ú
exceptionsr   r   r   Z	toml_charr   r   r)   r2   r   r   r   r   Ú<module>   s   !