
    gi                        d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZmZ erd dlmZ d dlmZ ddZ G d d          ZdS )    )annotationsN)contextmanager)TYPE_CHECKING	GeneratorMatchPatterncastoverload)BlockElementDocument)Literal)Parsertextstrreturnc                .    |                      dd          S )Nz

)replace)r   s    d/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/marko/source.py_preprocess_textr      s    <<%%%    c                  N   e Zd ZU dZded<   d-dZed.d
            Zed/d            Zd0dZ	d.dZ
ed1d            Zed2d            Zed3d            Zd4dZeej        d5d                        Zd6dZed7d8d"            Zed7d9d%            Zd:d;d'Zd<d(Zd<d)Zd<d*Zd<d+Zd,S )=Sourcez%Wrapper class on content to be parsedr   parserr   r   r   Nonec                    t          |          | _        d| _        d| _        g | _        d | _        t          j                    | _        d S )Nr   )	r   _bufferpos_anchor_statesmatchtypesSimpleNamespacecontext)selfr   s     r   __init__zSource.__init__   sA    '--+-(,
,..r   r   c                H    | j         st          d          | j         d         S )z"Returns the current element state.Need to push a state first.)r    RuntimeErrorr%   s    r   statezSource.state#   s*     | 	><===|Br   r   c                n    | j         st          d          t          t          | j         d                   S )zAReturns the root element, which is at the bottom of self._states.r(   r   )r    r*   r	   r   r+   s    r   rootzSource.root*   s3     | 	><===Hdl1o...r   elementc                :    | j                             |           dS )z$Push a new state to the state stack.N)r    appendr%   r/   s     r   
push_statezSource.push_state1   s    G$$$$$r   c                4    | j                                         S )zPop the top most state.)r    popr+   s    r   	pop_statezSource.pop_state5   s    |!!!r   Generator[Source, None, None]c              #  d   K   |                      |           | V  |                                  dS )z4A context manager to enable a new state temporarily.N)r3   r6   r2   s     r   under_statezSource.under_state9   s9       	   


r   boolc                <    | j         t          | j                  k    S )z-Indicates whether the source reaches the end.)r   lenr   r+   s    r   	exhaustedzSource.exhausted@   s     x3t|,,,,r   c                J    d                     d | j        D                       S )z%The prefix of each line when parsing. c              3  $   K   | ]}|j         V  d S N)_prefix).0ss     r   	<genexpr>z Source.prefix.<locals>.<genexpr>H   s$      77Qqy777777r   )joinr    r+   s    r   prefixzSource.prefixE   s'     ww77$,777777r   regexpPattern[str] | strr   intMatch[str] | Nonec                    t          |t                    rt          j        |          }|                    | j        |          S rA   )
isinstancer   recompiler!   r   )r%   rH   r   s      r   
_expect_rezSource._expect_reJ   s9    fc"" 	(Z''F||DL#...r   rG   linec                   t          j        | |                    d                    }|sPt          j        | |                    d                              dd                    rt	          |          dz
  S dS |                                }|dk    rdS t          dt	          |          dz             D ]4}t	          |d|                             d                    |k    r|c S 5dS )zCheck if the line starts with given prefix and
        return the position of the end of prefix.
        If the prefix is not matched, return -1.
           r   zd                                                                                                   
   r)   r   N)rN   r!   
expandtabsr   r<   endrange)rG   rQ   mr   is        r   match_prefixzSource.match_prefixO   s     HVT__Q//00 	x 2 2 : :4 Q QRR %4yy1}$2eegg!881q#d))a-(( 	 	A48&&q))**c11 2rr   c                    |                      | j        |                     d                    }|dk    r'|                     || j        |z             }|| _        |S dS )zTest against the given regular expression and returns the match object.
        :param regexp: the expression to be tested.
        :returns: the match object.
        F)require_prefixr   N)rZ   rG   	next_linerP   r   r!   )r%   rH   
prefix_lenr!   s       r   	expect_rezSource.expect_rec   sd    
 &&Ku==
 

 ??OOFDHz,ABBEDJL4r   .r\   Literal[False]c                    d S rA    r%   r\   s     r   r]   zSource.next_liner   s    FIcr   Literal[True]
str | Nonec                    d S rA   rb   rc   s     r   r]   zSource.next_lineu   s    LOCr   Tc                    |r|                      d          }n|                     d| j                  }|| _        |r|                                S dS )zReturn the next line in the source.

        :param require_prefix:  if False, the whole line will be returned.
            otherwise, return the line with prefix stripped or None if the prefix
            is not matched.
        z(?m)[^\n]*?$\n?z(?m)[^\n]*$\n?N)r_   rP   r   r!   group)r%   r\   rX   s      r   r]   zSource.next_linex   sX      	=122AA 148<<A
 	7799tr   c                    | j         r`| j                                         | _        | j                                         dd         dk    r|                                  d| _         dS dS )z6Consume the body of source. ``pos`` will move forward.r)   Nr   )r!   rV   r   rh   _update_prefixr+   s    r   consumezSource.consume   sh    : 	z~~''DHz!!"##&$..##%%%DJJJ		 	r   c                    | j         | _        dS )z!Pin the current parsing position.N)r   r   r+   s    r   anchorzSource.anchor   s    xr   c                    | j         | _        dS )z&Reset the position to the last anchor.N)r   r   r+   s    r   resetzSource.reset   s    <r   c                R    | j         D ]}t          |d          r|j        |_        d S )N_second_prefix)r    hasattrrq   rB   )r%   rD   s     r   rj   zSource._update_prefix   s;     	- 	-Aq*++ -,		- 	-r   N)r   r   r   r   )r   r   )r   r   )r/   r   r   r   )r/   r   r   r7   )r   r:   )r   r   )rH   rI   r   rJ   r   rK   )rG   r   rQ   r   r   rJ   )rH   rI   r   rK   ).)r\   r`   r   r   )r\   rd   r   re   )T)r\   r:   r   re   )r   r   )__name__
__module____qualname____doc____annotations__r&   propertyr,   r.   r3   r6   r   r9   r=   rG   rP   staticmethod	functools	lru_cacherZ   r_   r
   r]   rk   rm   ro   rj   rb   r   r   r   r      s        //NNN/ / / /       X  / / / X/% % % %" " " "    ^ - - - X- 8 8 8 X8/ / / /
     \$    IIII XIOOOO XO                      - - - - - -r   r   )r   r   r   r   )
__future__r   rz   rN   r"   
contextlibr   typingr   r   r   r   r	   r
   marko.blockr   r   r   marko.parserr   r   r   rb   r   r   <module>r      s   " " " " " "     				  % % % % % % K K K K K K K K K K K K K K K K . . . . . . . . $######& & & &F- F- F- F- F- F- F- F- F- F-r   