o
    h                     @   s>  d dl 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	 e
dZG dd dZeddd	ed
edefddZeddd	ed
edefddZeddd	ed
edefddZG dd dZG dd dZG dd dZG dd deZdedefddZ	d$deee	e f dedefdd Zd!edefd"d#ZdS )%    N)	lru_cache)ListUnionIterable\   c                   @   sZ   e Zd ZU dZg Zee ed< g Zee ed< dZ	e
dd Ze
dd Ze
d	d Zd
S )__config_flagsz=Internal class for defining compatibility and debugging flags
_all_names_fixed_namesconfigurationc                 C   sb   || j v rtd| j|| jtt| |  d S || j	v r(t
| || d S td| j|)Nz'{}.{} {} is {} and cannot be overriddenzno such {} {!r})r	   warningswarnformat__name__
_type_descstrgetattrupperr   setattr
ValueError)clsZdnamevalue r   V/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/pyparsing/util.py_set   s   

z__config_flags._setc                 C      |  |dS )NTr   r   namer   r   r   <lambda>$       z__config_flags.<lambda>c                 C   r   )NFr   r   r   r   r   r   %   r   N)r   
__module____qualname____doc__r   r   r   __annotations__r	   r   classmethodr   enabledisabler   r   r   r   r      s   
 
r      )maxsizelocstrgreturnc                 C   sF   |}d|   k rt |k rn n
|| d  dkrdS | |dd|  S )a  
    Returns current column within a string, counting newlines as line separators.
    The first column is number 1.

    Note: the default parsing behavior is to expand tabs in the input string
    before starting the parsing process.  See
    :class:`ParserElement.parseString` for more
    information on parsing strings containing ``<TAB>`` s, and suggested
    methods to maintain a consistent view of the parsed string, the parse
    location, and line and column positions within the parsed string.
    r      
)lenrfind)r)   r*   sr   r   r   col(   s   Br1   c                 C   s   | dd| d S )a  Returns current line number within a string, counting newlines as line separators.
    The first line is number 1.

    Note - the default parsing behavior is to expand tabs in the input string
    before starting the parsing process.  See :class:`ParserElement.parseString`
    for more information on parsing strings containing ``<TAB>`` s, and
    suggested methods to maintain a consistent view of the parsed string, the
    parse location, and line and column positions within the parsed string.
    r-   r   r,   )count)r)   r*   r   r   r   lineno9   s   r3   c                 C   sB   | dd| }|d| }|dkr||d | S ||d d S )zh
    Returns the line of text containing loc within a string, counting newlines as line separators.
    r-   r   r,   N)r/   find)r)   r*   Zlast_crZnext_crr   r   r   lineG   s   (r5   c                   @      e Zd Zdd ZdS )_UnboundedCachec                    sp   i   j t  | _fdd} fdd} fdd}d | _t|| | _ t|| | _t|| | _d S )Nc                    
    |S Nr   _key	cache_getnot_in_cacher   r   getW      
z%_UnboundedCache.__init__.<locals>.getc                    s   | |< d S r9   r   r;   r<   r   cacher   r   set_Z      z&_UnboundedCache.__init__.<locals>.set_c                           d S r9   clearr;   rC   r   r   rI   ]   rF   z'_UnboundedCache.__init__.<locals>.clear)r@   objectr?   sizetypes
MethodTypesetrI   )selfr@   rE   rI   r   )rD   r>   r?   r   __init__R   s   z_UnboundedCache.__init__Nr   r    r!   rQ   r   r   r   r   r7   Q       r7   c                   @   r6   )
_FifoCachec                    sv   t   | _t   jfdd} fdd} fdd}| _t|| | _t|| | _t|| | _	d S )Nc                    r8   r9   r   r:   r=   r   r   r@   l   rA   z _FifoCache.__init__.<locals>.getc                    s4   | |< t  kr jdd t  ks
d S d S NF)last)r.   popitemrB   )rD   rL   r   r   rE   o   s   z!_FifoCache.__init__.<locals>.set_c                    rG   r9   rH   rJ   rC   r   r   rI   t   rF   z"_FifoCache.__init__.<locals>.clear)
rK   r?   collectionsOrderedDictr@   rL   rM   rN   rO   rI   )rP   rL   r@   rE   rI   r   )rD   r>   r?   rL   r   rQ   g   s   z_FifoCache.__init__NrR   r   r   r   r   rT   f   rS   rT   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )LRUMemoz
    A memoizing mapping that retains `capacity` deleted items

    The memo tracks retained items by their access order; once `capacity` items
    are retained, the least recently used item is discarded.
    c                 C   s   || _ i | _t | _d S r9   )	_capacity_activerX   rY   _memory)rP   capacityr   r   r   rQ      s   zLRUMemo.__init__c                 C   s6   z| j | W S  ty   | j| | j|  Y S w r9   )r\   KeyErrorr]   move_to_endrP   r<   r   r   r   __getitem__   s   zLRUMemo.__getitem__c                 C   s   | j |d  || j|< d S r9   )r]   popr\   rP   r<   r   r   r   r   __setitem__   s   zLRUMemo.__setitem__c                 C   sb   z| j |}W n
 ty   Y d S w t| j| jkr*| jjdd t| j| jks|| j|< d S rU   )r\   rc   r_   r.   r]   r[   rW   rd   r   r   r   __delitem__   s   zLRUMemo.__delitem__c                 C   s   | j   | j  d S r9   )r\   rI   r]   )rP   r   r   r   rI      s   
zLRUMemo.clearN)	r   r    r!   r"   rQ   rb   re   rf   rI   r   r   r   r   rZ   }   s    
rZ   c                   @   s   e Zd ZdZdd ZdS )UnboundedMemoz<
    A memoizing mapping that retains all deleted items
    c                 C   s   d S r9   r   ra   r   r   r   rf         zUnboundedMemo.__delitem__N)r   r    r!   r"   rf   r   r   r   r   rg      s    rg   r0   c                 C   s:   dD ]
}|  |t| } q|  dd} |  dd} t| S )Nz\^-[]r-   z\n	z\t)replace_bslashr   )r0   cr   r   r   _escape_regex_range_chars   s
   rm   T	re_escapec           	   	      s  fddd_ t _d_dd  dd }|s| g }d	tt| } t| d
krytj	| dD ]B\}}t
| }}tjtt|g|dd }||kr[| | q5t|t|d krgd	nd}|d || | q5n	 fdd| D }d	|S )Nc                    s4   t | }| j _}|| dkrt j _ jS )Nr,   )ordprevnextcounterr   )rl   Zc_intrp   )is_consecutiver   r   rs      s
   z2_collapse_string_to_ranges.<locals>.is_consecutiver   c                 S   s   | dv rd|  S | S )Nz\^-][\r   rl   r   r   r   escape_re_range_char   s   z8_collapse_string_to_ranges.<locals>.escape_re_range_charc                 S   s   | S r9   r   rv   r   r   r   no_escape_re_range_char   rh   z;_collapse_string_to_ranges.<locals>.no_escape_re_range_char    )r<   r,   )maxlen-z{}{}{}c                    s   g | ]} |qS r   r   ).0rl   )rw   r   r   
<listcomp>   s    z._collapse_string_to_ranges.<locals>.<listcomp>)rp   	itertoolsr2   rr   r   joinsortedrO   r.   groupbyrq   rX   dequechainiterrc   appendro   r   )	r0   rn   rx   retr;   charsfirstrV   sepr   )rw   rs   r   _collapse_string_to_ranges   s:   

r   llc                 C   s6   g }| D ]}t |tr|t| q|| q|S r9   )
isinstancelistextend_flattenr   )r   r   ir   r   r   r      s   
r   )T)r   rM   rX   r   	functoolsr   typingr   r   r   chrrk   r   intr   r1   r3   r5   r7   rT   rZ   dictrg   rm   boolr   r   r   r   r   r   r   <module>   s8   	'	

.