o
    4c                  
   @   s`  d dl 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d	d
ddZ	dd Z
z	d dlZejZW n eyF   e
ZY nw dd Zdd Zdd Zdd Zdd ZG dd deZe ZedZdd ZG dd deZeeeZejZejZd d! Z e !d"e  d#d$d%d&d'd(d)d*d+d,	Z"ej#re"$d(d*i e"% Z&d-e&d.< d/e&d0< dS )1    N)compat)codepoint2name)name2codepoint
quote_plus)unquote_plus&amp;&gt;&lt;&#34;&#39;)&><"'c                 C   s@   |  dd} |  dd} |  dd} |  dd} |  d	d
} | S )z(legacy HTML escape for non-unicode mode.r   r   r   r	   r   r
   r   r   r   r   )replace)s r   B/var/www/html/gps/gps/lib/python3.10/site-packages/mako/filters.pylegacy_html_escape   s   r   c                 C   s   t ddd | S )Nz
([&<"\'>])c                 S   s   t |   S N)xml_escapesgroup)mr   r   r   <lambda>0   s    zxml_escape.<locals>.<lambda>)resubstringr   r   r   
xml_escape/   s   r    c                 C   s   |  d} t| S Nutf8)encoder   r   r   r   r   
url_escape3   s   
r$   c                 C   s   t | S r   r   r   r   r   r   legacy_url_escape9   s   r%   c                 C   s   t | }t|s|d}|S r!   )r   is_ascii_strdecode)r   textr   r   r   url_unescape>   s   
r)   c                 C   s   |   S r   )stripr   r   r   r   trimE   s   r+   c                   @   s   e Zd Zdd ZdS )Decodec                    s    fdd  S )Nc                    s6   t | tjr| S t | tjs t| S tj| dS )N)encoding)
isinstancer   	text_typebinary_typestr)xr'   keyr   r   r'   K   s
   z"Decode.__getattr__.<locals>.decoder   )selfr4   r   r3   r   __getattr__J   s   zDecode.__getattr__N)__name__
__module____qualname__r6   r   r   r   r   r,   I   s    r,   z\A[\x00-\x7f]*\Zc                 C   s   t | to	t| S r   )r.   r1   	_ASCII_rematch)r(   r   r   r   r&   \   s   r&   c                   @   sZ   e Zd Zdd Zdd Zdd ZedZdd	 Z	ed
ej
ejB Zdd Zdd ZdS )XMLEntityEscaperc                 C   s"   t dd | D | _|| _d S )Nc                 S   s"   g | ]\}}|t d | fqS )z&%s;)r   r/   ).0cnr   r   r   
<listcomp>f   s    z-XMLEntityEscaper.__init__.<locals>.<listcomp>)dictitemscodepoint2entityr   )r5   r   r   r   r   r   __init__d   s   
zXMLEntityEscaper.__init__c                 C   s   t || jS )zReplace characters with their character entity references.

        Only characters corresponding to a named entity are replaced.
        )r   r/   	translaterC   r5   r(   r   r   r   escape_entitiesm   s   z XMLEntityEscaper.escape_entitiesc              	   C   s8   t | }z| j| W S  ttfy   d|  Y S w )Nz&#x%X;)ordr   rC   KeyError
IndexError)r5   r   	codepointr   r   r   __escapet   s   zXMLEntityEscaper.__escapez["&<>]|[^\x00-\x7f]c                 C   s   | j | jt|dS )a3  Replace characters with their character references.

        Replace characters by their named entity references.
        Non-ASCII characters, if they do not have a named entity reference,
        are replaced by numerical character references.

        The return value is guaranteed to be ASCII.
        ascii)_XMLEntityEscaper__escapabler   _XMLEntityEscaper__escaper   r/   r#   rF   r   r   r   escape}   s
   	zXMLEntityEscaper.escapez& (?:
                                          \#(\d+)
                                          | \#x([\da-f]+)
                                          | ( (?!\d) [:\w] [-.:\w]+ )
                                          ) ;c                 C   sR   |  \}}}|rt|}n|rt|d}n| j|d}|dk r%t|S t|S )N   i     )groupsintr   getchr)r5   r   dvalhvalnamerK   r   r   r   
__unescape   s   
zXMLEntityEscaper.__unescapec                 C   s   | j | j|S )zUnescape character references.

        All character references (both entity references and numerical
        character references) are unescaped.
        ) _XMLEntityEscaper__characterrefsr   _XMLEntityEscaper__unescaperF   r   r   r   unescape   s   zXMLEntityEscaper.unescapeN)r7   r8   r9   rD   rG   rO   r   compilerN   rP   XUNICODEr[   r\   r]   r   r   r   r   r<   c   s    	

	r<   c                 C   s:   t | tr| j| j| j }t|}t|| jfS | )u7  An encoding error handler.

    This python codecs error handler replaces unencodable
    characters with HTML entities, or, if no HTML entity exists for
    the character, XML character references::

        >>> u'The cost was €12.'.encode('latin1', 'htmlentityreplace')
        'The cost was &euro;12.'
    )	r.   UnicodeEncodeErrorobjectstartend_html_entities_escaperrP   r   r/   )exbad_textr(   r   r   r   htmlentityreplace_errors   s
   


rh   htmlentityreplacezfilters.xml_escapezfilters.html_escapezfilters.url_escapezfilters.trimzfilters.html_entities_escapeunicoder'   r1   r?   )	r2   hur+   entityrj   r'   r1   r?   zfilters.legacy_html_escaperk   zfilters.legacy_url_escaperl   )'codecsr   makor   mako.compatr   r   r   r   r   r   
markupsaferP   html_escapeImportErrorr    r$   r%   r)   r+   rb   r,   r'   r^   r:   r&   r<   re   rG   html_entities_escaper]   html_entities_unescaperh   register_errorDEFAULT_ESCAPESpy3kupdatecopyNON_UNICODE_ESCAPESr   r   r   r   <module>   sd   



J