o
    h)                     @   s   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZddlm	Z	 dd Z
G dd dZd	d
 Zd#ddZG dd dZG dd dZG dd deZG dd dZG dd deZedejZdd Zdd Zdd Zd$dd Zd!d" ZdS )%    )parseN   )importlib_metadata_getc                 C   s   || _ |j| _| S N)__wrapped____name__)	decoratedfn r
   ]/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/mako/util.pyupdate_wrapper   s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )PluginLoaderc                 C   s   || _ i | _d S r   )groupimpls)selfr   r
   r
   r   __init__      
zPluginLoader.__init__c                 C   sh   || j v r| j |  S t| jD ]}|j|kr#|j| j |< |   S qddlm} |d| j|f )Nr   )
exceptionszCan't load plugin %s %s)r   r   r   nameloadmakor   RuntimeException)r   r   implr   r
   r
   r   r      s   

zPluginLoader.loadc                    s    fdd}|| j |< d S )Nc                     s4   t  }  ddd  D ]}t| |} qt| S )N.r   )
__import__splitgetattr)modtoken
modulepathobjnamer
   r   r   ,   s   
z#PluginLoader.register.<locals>.load)r   )r   r   r    r!   r   r
   r   r   register+   s   zPluginLoader.registerN)r   
__module____qualname__r   r   r"   r
   r
   r
   r   r      s    r   c                 C   sP   d}t j| s&z|d7 }t | d W n	   |dkr Y t j| rdS dS )z,create and/or verify a filesystem directory.r   r   i     N)ospathexistsmakedirs)dir_triesr
   r
   r   verify_directory5   s   r,   c                 C   s$   | d u r|S t | ttfs| gS | S r   )
isinstancelisttuple)xdefaultr
   r
   r   to_listC   s
   r2   c                   @   "   e Zd ZdZdddZdd ZdS )memoized_propertyz2A read-only @property that is only evaluated once.Nc                 C      || _ |p|j| _|j| _d S r   fget__doc__r   r   r7   docr
   r
   r   r   P      zmemoized_property.__init__c                 C   s&   |d u r| S |  | |j| j< }|S r   )r7   __dict__r   )r   objclsresultr
   r
   r   __get__U   s   zmemoized_property.__get__r   r   r#   r$   r8   r   r@   r
   r
   r
   r   r4   L   s    
r4   c                   @   r3   )memoized_instancemethodzDecorate a method memoize its return value.

    Best applied to no-arg methods: memoization is not sensitive to
    argument values, and will always return the same value even when
    called with different arguments.

    Nc                 C   r5   r   r6   r9   r
   r
   r   r   f   r;   z memoized_instancemethod.__init__c                    s.    d u rS  fdd}j |_ j|_|S )Nc                     sD   j g| R i |  fdd}j|_j|_|jj<  S )Nc                     s    S r   r
   )akwr?   r
   r   memor   s   z>memoized_instancemethod.__get__.<locals>.oneshot.<locals>.memo)r7   r   r8   r<   )argsrD   rF   r=   r   rE   r   oneshoto   s   z0memoized_instancemethod.__get__.<locals>.oneshot)r   r8   )r   r=   r>   rI   r
   rH   r   r@   k   s   zmemoized_instancemethod.__get__r   rA   r
   r
   r
   r   rB   \   s    
rB   c                   @   s   e Zd ZdZdd ZdS )SetLikeDictz0a dictionary that has some setlike methods on itc                 C   s   t di | }|| |S )zproduce a 'union' of this dict and another (at the key level).

        values in the second dict take precedence over that of the firstNr
   )rJ   update)r   otherr0   r
   r
   r   union   s   
zSetLikeDict.unionN)r   r#   r$   r8   rM   r
   r
   r
   r   rJ      s    rJ   c                   @   s*   e Zd ZdZd
ddZdd Zdd	 ZdS )FastEncodingBufferzVa very rudimentary buffer that is faster than StringIO,
    and supports unicode data.Nstrictc                 C   s*   t  | _|| _d| _|| _| jj| _d S )N )collectionsdequedataencodingdelimerrorsappendwrite)r   rT   rV   r
   r
   r   r      s
   
zFastEncodingBuffer.__init__c                 C   s   t  | _| jj| _d S r   )rQ   rR   rS   rW   rX   r   r
   r
   r   truncate   s   
zFastEncodingBuffer.truncatec                 C   s.   | j r| j| j| j | jS | j| jS r   )rT   rU   joinrS   encoderV   rY   r
   r
   r   getvalue   s
   zFastEncodingBuffer.getvalue)NrO   )r   r#   r$   r8   r   rZ   r]   r
   r
   r
   r   rN      s
    
rN   c                   @   sP   e Zd ZdZG dd dZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dS )LRUCachea$  A dictionary-like object that stores a limited number of items,
    discarding lesser used items periodically.

    this is a rewrite of LRUCache from Myghty to use a periodic timestamp-based
    paradigm so that synchronization is not really needed.  the size management
    is inexact.
    c                   @   s   e Zd Zdd Zdd ZdS )zLRUCache._Itemc                 C   s   || _ || _t | _d S r   )keyvaluetimeitdefault_timer	timestampr   r_   r`   r
   r
   r   r      s   zLRUCache._Item.__init__c                 C   s
   t | jS r   )reprr`   rY   r
   r
   r   __repr__   s   
zLRUCache._Item.__repr__N)r   r#   r$   r   rf   r
   r
   r
   r   _Item   s    rg         ?c                 C   s   || _ || _d S r   )capacity	threshold)r   ri   rj   r
   r
   r   r      r   zLRUCache.__init__c                 C   s   t | |}t |_|jS r   )dict__getitem__ra   rb   rc   r`   )r   r_   itemr
   r
   r   rl      s   
zLRUCache.__getitem__c                 C   s   dd t | D S )Nc                 S   s   g | ]}|j qS r
   )r`   ).0ir
   r
   r   
<listcomp>   s    z#LRUCache.values.<locals>.<listcomp>)rk   valuesrY   r
   r
   r   rq      s   zLRUCache.valuesc                 C   s   || v r| | S || |< |S r   r
   rd   r
   r
   r   
setdefault   s   zLRUCache.setdefaultc                 C   sB   t | |}|d u r| ||}t | || n||_|   d S r   )rk   getrg   __setitem__r`   _manage_size)r   r_   r`   rm   r
   r
   r   rt      s   zLRUCache.__setitem__c              	   C   s   t | | j| j| j  krCtt| tddd}|| jd  D ]}z| |j= W q! t	y3   Y  nw t | | j| j| j  ksd S d S )Nrc   T)r_   reverse)
lenri   rj   sortedrk   rq   operator
attrgetterr_   KeyError)r   bytimerm   r
   r
   r   ru      s   "zLRUCache._manage_sizeN)rh   )r   r#   r$   r8   rg   r   rl   rq   rr   rt   ru   r
   r
   r
   r   r^      s    
		r^   z([ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c              	   C   s   |   }| d zh|  }|tj}|r|ttjd }t|	dd}|sMz
t
|	dd W n ttfy?   Y nw |  }t|	dd}|r]|rUtdW | | dS |rj|dW | | S W | | dS | | w )a  Deduce the encoding of a Python source file (binary mode) from magic
    comment.

    It does this in the same way as the `Python interpreter`__

    .. __: http://docs.python.org/ref/encodings.html

    The ``fp`` argument should be a seekable file object in binary mode.
    r   Nasciiignorez\python refuses to compile code with both a UTF8 byte-order-mark and a magic encoding commentutf_8r   )tellseekreadline
startswithcodecsBOM_UTF8rw   _PYTHON_MAGIC_COMMENT_rematchdecoder   ImportErrorSyntaxErrorr   )fpposline1has_bommline2r
   r
   r   parse_encoding   s<   



r   c                    s4   t   }|  dd fdd|D  d S )z{repr() a dictionary with the keys in order.

    Used by the lexer unit test to compare parse trees based on strings.

    {z, c                 3   s     | ]}d | | f V  qdS )z%r: %rNr
   )rn   kdr
   r   	<genexpr>"  s    z#sorted_dict_repr.<locals>.<genexpr>})r.   keyssortr[   )r   r   r
   r   r   sorted_dict_repr  s    r   c                 C   sx  t | drdS d| _tddd| j}t|| _| jjD ]}|jdkr&|| _q|jdkr.|| _qt|j	d | _
t|j	d	 | _t|j	d
 | _t|j	d jd | _t|j	d jd j| _t|j	d j| _t|j	d jj| _t|j	d jjj| _t|j	d jjj| _t|j	d jjjj| _t|j	d jj| _t|j	d jjj| _t|j	d jjjj| _t|j	d jjjjj| _t|j	d jj| _t|j	d jjj| _t|j	d jjjj| _ t|j	d jj| _!t|j	d jj"d j| _#t|j	d jjj| _$t|j	d jjjj| _%t|j	d jjjj&j| _'t|j	d jjjj| _(t|j	d jj| _!t|j	d jj"d j| _#t|j	d jj)d | _*t|j	d jj)d	 | _+t|j	d jjj)d | _,t|j	d jjj)d	 | _-t|j	d jj)d | _.t|j	d jj)d	 | _/t|j	d jj)d
 | _0t|j	d jj)d | _1t|j	d jj)d | _2t|j	d jj)d	 | _3dS )zdAttempt to restore the required classes to the _ast module if it
    appears to be missing them
    ASTNi   a  def foo(): pass
class Bar: pass
if False: pass
baz = 'mako'
1 + 2 - 3 * 4 / 5
6 // 7 % 8 << 9 >> 10
11 & 12 ^ 13 | 14
15 and 16 or 17
-baz + (not +18) - ~17
baz and 'foo' or 'bar'
(mako is baz == baz) is not baz != mako
mako > baz < mako >= baz <= mako
mako in baz not in makoz	<unknown>execr   r   r            r%            	   
         )4hasattrPyCF_ONLY_ASTcompiletypeModule__mro__r   r   r   bodyFunctionDefClassDefIftargetsNamectxStorer`   StropSubleftAddrightDivMultRShiftLShiftModFloorDivBitOrBitXorBitAndOrrq   AndInvertNotoperandUAddUSubopsIsNotNotEqIsEqGtLtGtELtEInNotIn)_astr   r>   r
   r
   r   restore__ast%  sf   



r   rbc                 C   s6   t | |}| W  d    S 1 sw   Y  d S r   )openread)r'   moder   r
   r
   r   	read_filev  s   $r   c                 C   sB   t | d}zt|}| }|r||}|W |  S |  w )Nr   )r   r   r   r   close)r'   r   rT   rS   r
   r
   r   read_python_file{  s   

r   r   )r   )astr   r   rQ   ry   r&   rera   compatr   r   r   r,   r2   r4   rB   rk   rJ   rN   r^   r   VERBOSEr   r   r   r   r   r   r
   r
   r
   r   <module>   s2   
	#?1
Q