
    ci2              
       6   d dl Z d dlmZ d dlmZ d dlZd dlmZ d dlZej                  Z	ddddd	d
Z
d Zd Zd Z G d d      Z e       Z G d d      Z eee      Zej$                  Zej(                  Zd Z e j.                  de       dddddddddd	Zy)    N)codepoint2name)name2codepoint)
quote_plusz&amp;z&gt;z&lt;z&#34;z&#39;)&><"'c                 2    t        j                  dd |       S )Nz
([&<"\'>])c                 0    t         | j                            S N)xml_escapesgroup)ms    3/tmp/pip-target-z3e9_cxr/lib/python/mako/filters.py<lambda>zxml_escape.<locals>.<lambda>   s    ;qwwy+A     )resubstrings    r   
xml_escaper      s    66-!A6JJr   c                 :    | j                  d      } t        |       S )Nutf8)encoder   r   s    r   
url_escaper      s    ]]6"Ffr   c                 "    | j                         S r   )stripr   s    r   trimr   %   s    <<>r   c                       e Zd Zd Zy)Decodec                     fdS )Nc                     t        | t              r| S t        | t              s t        |             S t        |       S )N)encoding)
isinstancestrbytes)xdecodekeys    r   r)   z"Decode.__getattr__.<locals>.decode+   s7    !S!5)c!f~%1s++r    )selfr*   r)   s    `@r   __getattr__zDecode.__getattr__*   s    	, r   N)__name__
__module____qualname__r-   r+   r   r   r!   r!   )   s    	r   r!   c                       e Zd Zd Zd Zd Z ej                  d      Zd Z	 ej                  dej                  ej                  z        Zd Zd Zy	)
XMLEntityEscaperc           	           |j                          D ci c]  \  }}|t        d|z         c}}| _        || _        y c c}}w )Nz&%s;)itemsr&   codepoint2entityr   )r,   r   r   cns        r   __init__zXMLEntityEscaper.__init__:   sE    +?>+?+?+A!
#'1aAs6A:!
 -!
s   ?c                 J    t        |      j                  | j                        S )zReplace characters with their character entity references.

        Only characters corresponding to a named entity are replaced.
        )r&   	translater5   r,   texts     r   escape_entitiesz XMLEntityEscaper.escape_entities@   s    
 4y""4#8#899r   c                     t        |j                               }	 | j                  |   S # t        t        f$ r d|z  cY S w xY w)Nz&#x%X;)ordr   r5   KeyError
IndexError)r,   r   	codepoints      r   __escapezXMLEntityEscaper.__escapeG   sF    	N		(((33*% 	(i''	(s   * A Az["&<>]|[^\x00-\x7f]c                 ~    | j                   j                  | j                  t        |            j	                  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;   s     r   escapezXMLEntityEscaper.escapeP   s0     ##DMM3t9=DDWMMr   z& (?:
                                          \#(\d+)
                                          | \#x([\da-f]+)
                                          | ( (?!\d) [:\w] [-.:\w]+ )
                                          ) ;c                     |j                         \  }}}|rt        |      }n+|rt        |d      }n| j                  j                  |d      }|dk  rt	        |      S t	        |      S )N   i     )groupsintr   getchr)r,   r   dvalhvalnamerB   s         r   
__unescapezXMLEntityEscaper.__unescapeh   sa    88:dDD	ID"I++//f=Is?y>!9~r   c                 N    | j                   j                  | j                  |      S )zUnescape character references.

        All character references (both entity references and numerical
        character references) are unescaped.
        ) _XMLEntityEscaper__characterrefsr   _XMLEntityEscaper__unescaper;   s     r   unescapezXMLEntityEscaper.unescapeu   s!     ##''>>r   N)r.   r/   r0   r8   r=   rG   r   compilerF   rH   XUNICODErU   rV   rW   r+   r   r   r2   r2   9   s]    -:( "**34K	N !bjj	1
 	rzzO?r   r2   c                     t        | t              rO| j                  | j                  | j                   }t
        j                  |      }t        |      | j                  fS | )u6  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::

        >>> 'The cost was €12.'.encode('latin1', 'htmlentityreplace')
        'The cost was &euro;12.'
    )r%   UnicodeEncodeErrorobjectstartend_html_entities_escaperrH   r&   )exbad_textr<   s      r   htmlentityreplace_errorsrc      sO     "()99RXX/%,,X6D	266""
Hr   htmlentityreplacezfilters.xml_escapezfilters.html_escapezfilters.url_escapezfilters.trimzfilters.html_entities_escaper&   r)   r7   )	r(   hur   entityunicoder)   r&   r7   )codecshtml.entitiesr   r   r   urllib.parser   
markupsaferH   html_escaper   r   r   r   r!   r)   r2   r`   r=   html_entities_escaperW   html_entities_unescaperc   register_errorDEFAULT_ESCAPESr+   r   r   <module>rr      s     ( ( 	 #  
				K
 
 
B? B?J *..I -== /88 $   )+C D 
		,	
r   