mň
żŘÜ=c           @   sR   d  k  l  Z  l Z l Z l Z l Z d k l Z l Z d e  f d     YZ d S(   (   s
   HTMLParsers   HTMLParseErrors   picloses   charrefs	   entityref(   s   lowers   findt   HTML2SafeHTMLc           B   sŤ   t  Z d d d d d g Z d d d d	 d
 d d d g Z d   Z d   Z d   Z d   Z d k l	 Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nt   lit   pt   ddt   dtt   optiont   brt   wbrt   hrt   inputt   isindext   baset   metat   imgc         C   s,   t  i |   | |  _ d |  _ g  |  _ d  S(   Nt    (   t
   HTMLParsert   __init__t   selft
   valid_tagst   resultt   openTags(   R   R   (    (    tQ   /home2/kennisonb/webapps/zope/Zope/Products/Squishdot/stripogram/html2safehtml.pyR      s    		c         C   s   d |  i | f |  _ d  S(   Ns   %s</%s>(   R   R   t   tag(   R   R   (    (    R   t   end_tag   s    c         C   s   | o |  i | |  _ n d  S(   N(   t   dataR   R   (   R   R   (    (    R   t   handle_data   s    c         C   s   d |  i | f |  _ d  S(   Ns   %s&#%s;(   R   R   t   name(   R   R   (    (    R   t   handle_charref   s    (   s
   entitydefsc         C   s@   |  i i |  o
 d } n d } d |  i | | f |  _ d  S(   Nt   &s   &amp;s   %s%s%s;(   R   t
   entitydefst   has_keyR   t   ampR   (   R   R   R   (    (    R   t   handle_entityref#   s    
c         C   sě   | |  i j oŘ |  i d | |  _ x | D] \ } } | d
 j o |  i d | 7_ q+ t | d d ! d j o7 t | d d ! d j o |  i d | | f 7_ q+ q+ W| |  i	 j o |  i
 i |  n |  i d	 |  _ n d
 S(   s'    Delete all tags except for legal ones t   <t    i    i   t   oni
   t
   javascripts    %s="%s"t   >N(   R   R   R   R   t   attrst   kt   vt   Nonet   lowert   never_closeR   t   append(   R   R   R&   R'   R(   (    (    R   t   handle_starttag+   s      4!c         C   s   yr x= | |  i d j o( |  i d |  i j o |  i i   q W| |  i d j o |  i |  i i    n Wn t j
 o n Xd  S(   Ni˙˙˙˙(   R   R   R   t	   can_closet   popR   t
   IndexError(   R   R   (    (    R   t   handle_endtag>   s     +c         C   sF   x? |  i o4 |  i i   } | |  i j o |  i |  q q Wd S(   s    Append missing closing tags N(   R   R   R/   R   R.   R   (   R   R   (    (    R   t   cleanupK   s      
c         C   se   y t  i |  |  SWnJ t j
 o> y t i |  i |  i   SWqa t	 j
 o d Sqa Xn Xd  S(   Ni˙˙˙˙(
   R   t   parse_starttagR   t   it   HTMLParseErrort   picloset   searcht   rawdatat   endt   AttributeError(   R   R4   (    (    R   R3   R   s    c         C   sY   y t  i |  |  SWn> t j
 o2 y t i |  i |  i   SWqU d SqU Xn Xd  S(   Ni˙˙˙˙(	   R   t   parse_endtagR   R4   R5   R6   R7   R8   R9   (   R   R4   (    (    R   R;   [   s    c         C   sň   |  i } d } t |  } d } x | | j  o t | d |  } | d j o Pn | | | | !} t i	 | |  p t
 i	 | |  o | d } n | d } | d } q$ W| | | |  _ y t i |  |  SWn t j
 o n Xd  S(   Ni    R   R   i˙˙˙˙s   &amp;i   (   R   R8   R4   t   lent   nt   newdatat   findt   jt   charreft   matcht	   entityrefR   t   goaheadR9   R5   (   R   R9   R4   R@   R=   R8   R>   (    (    R   RD   d   s&    	 &
(   t   __name__t
   __module__R.   R+   R   R   R   R   t   htmlentitydefsR   R    R-   R1   R2   R3   R;   RD   (    (    (    R   R       s   												N(	   R   R5   R6   RA   RC   t   stringR*   R?   R    (   R5   R*   RA   R    R   RC   R6   R?   (    (    R   t   ?	   s   %