o
    4c+                     @   s
  d dl mZ 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eZd	d
 Zd#ddZG dd deZG dd deZG dd deZG dd de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 )%    )absolute_import)parseN)compatc                 C   s   || _ |j| _| S N)__wrapped____name__)	decoratedfn r
   ?/var/www/html/gps/gps/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 dd l}|| j|D ]}|j| j |< |   S ddlm} |d| j|f )Nr   )
exceptionszCan't load plugin %s %s)r   pkg_resourcesiter_entry_pointsr   loadmakor   RuntimeException)r   namer   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.   )
__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   sV   d}t j| s)z|d7 }t | 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   0775   N)ospathexistsmakedirsr   octal)dir_triesr
   r
   r   verify_directory8   s   r1   c                 C   s$   | d u r|S t | ttfs| gS | S r   )
isinstancelisttuple)xdefaultr
   r
   r   to_listF   s
   r7   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   r<   docr
   r
   r   r   S      zmemoized_property.__init__c                 C   s&   |d u r| S |  | |j| j< }|S r   )r<   __dict__r   )r   objclsresultr
   r
   r   __get__X   s   zmemoized_property.__get__r   r   r&   r'   r=   r   rE   r
   r
   r
   r   r9   O   s    
r9   c                   @   r8   )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   r:   r   r;   r>   r
   r
   r   r   i   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rD   r
   r   memou   s   z>memoized_instancemethod.__get__.<locals>.oneshot.<locals>.memo)r<   r   r=   rA   )argsrI   rK   rB   r   rJ   r   oneshotr   s   z0memoized_instancemethod.__get__.<locals>.oneshot)r   r=   )r   rB   rC   rN   r
   rM   r   rE   n   s   zmemoized_instancemethod.__get__r   rF   r
   r
   r
   r   rG   _   s    
rG   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
   )rO   update)r   otherr5   r
   r
   r   union   s   
zSetLikeDict.unionN)r   r&   r'   r=   rR   r
   r
   r
   r   rO      s    rO   c                   @   s*   e Zd ZdZdddZdd Zd	d
 ZdS )FastEncodingBufferzma very rudimentary buffer that is faster than StringIO,
    but doesn't crash on unicode data like cStringIO.NstrictFc                 C   sB   t  | _|| _|rtd| _nd| _|| _|| _| jj	| _
d S )N )collectionsdequedataencodingr   udelim
as_unicodeerrorsappendwrite)r   rY   r]   r\   r
   r
   r   r      s   
zFastEncodingBuffer.__init__c                 C   s   t  | _| jj| _d S r   )rV   rW   rX   r^   r_   r   r
   r
   r   truncate   s   
zFastEncodingBuffer.truncatec                 C   s.   | j r| j| j| j | jS | j| jS r   )rY   r[   joinrX   encoder]   r`   r
   r
   r   getvalue   s
   zFastEncodingBuffer.getvalue)NrT   F)r   r&   r'   r=   r   ra   rd   r
   r
   r
   r   rS      s
    
rS   c                   @   sR   e Zd ZdZG dd de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   rf   rg   r
   r
   r   r      s   zLRUCache._Item.__init__c                 C   s
   t | jS r   )reprrg   r`   r
   r
   r   __repr__   s   
zLRUCache._Item.__repr__N)r   r&   r'   r   rm   r
   r
   r
   r   _Item   s    rn         ?c                 C   s   || _ || _d S r   )capacity	threshold)r   rp   rq   r
   r
   r   r      r   zLRUCache.__init__c                 C   s   t | |}t |_|jS r   )dict__getitem__rh   ri   rj   rg   )r   rf   itemr
   r
   r   rs      s   
zLRUCache.__getitem__c                 C   s   dd t | D S )Nc                 S   s   g | ]}|j qS r
   )rg   ).0ir
   r
   r   
<listcomp>   s    z#LRUCache.values.<locals>.<listcomp>)rr   valuesr`   r
   r
   r   rx      s   zLRUCache.valuesc                 C   s   || v r| | S || |< |S r   r
   rk   r
   r
   r   
setdefault   s   zLRUCache.setdefaultc                 C   sB   t | |}|d u r| ||}t | || n||_|   d S r   )rr   getrn   __setitem__rg   _manage_size)r   rf   rg   rt   r
   r
   r   r{      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 )Nrj   T)rf   reverse)
lenrp   rq   sortedrr   rx   operator
attrgetterrf   KeyError)r   bytimert   r
   r
   r   r|      s   "zLRUCache._manage_sizeN)ro   )r   r&   r'   r=   objectrn   r   rs   rx   ry   r{   r|   r
   r
   r
   r   re      s    
		re   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_UTF8r~   _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                    s   g | ]
}d | | f qS )z%r: %rr
   )ru   kdr
   r   rw   *  s    z$sorted_dict_repr.<locals>.<listcomp>})r3   keyssortrb   )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(object): 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Storerg   StropSubleftAddrightDivMultRShiftLShiftModFloorDivBitOrBitXorBitAndOrrx   AndInvertNotoperandUAddUSubopsIsNotNotEqIsEqGtLtGtELtEInNotIn)_astr   rC   r
   r
   r   restore__ast-  sf   



r   rbc                 C   s,   t | |}z| }|W |  S |  w r   )openreadclose)r+   moder   rX   r
   r
   r   	read_file~  s
   
r   c                 C   sB   t | d}zt|}| }|r||}|W |  S |  w )Nr   )r   r   r   r   r   )r+   r   rY   rX   r
   r
   r   read_python_file  s   

r   r   )r   )
__future__r   astr   r   rV   r   r*   rerh   r   r   r   r   r   r1   r7   r9   rG   rr   rO   rS   re   r   VERBOSEr   r   r   r   r   r   r
   r
   r
   r   <module>   s4   
	#@1
Q	