
uXQc           @   s	  d  g Z  d d l Z d d l m Z m Z m Z m Z d d l m Z d d l	 Z	 d d l
 m Z d d l m Z m Z m Z m Z d  e f d     YZ d e	 j j j f d	     YZ d
 e f d     YZ d e	 j j j f d     YZ d e f d     YZ d S(   t   HTML5TreeBuilderiN(   t
   PERMISSIVEt   HTMLt   HTML_5t   HTMLTreeBuilder(   t   NamespacedAttribute(   t
   namespaces(   t   Commentt   Doctypet   NavigableStringt   Tagc           B   sD   e  Z d  Z d e e e g Z d   Z d   Z d   Z	 d   Z
 RS(   s   Use html5lib to build a tree.t   html5libc         C   s   | |  _  | d  d  t f S(   N(   t   user_specified_encodingt   Nonet   False(   t   selft   markupR   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   prepare_markup   s    	c         C   s   |  j  j d  k	 r" t j d  n  t j d |  j  } | j | d |  j	 } t
 | t  rj d  | _ n | j j j d | _ d  S(   Ns   You provided a value for parse_only, but the html5lib tree builder doesn't support parse_only. The entire document will be parsed.t   treet   encodingi    (   t   soupt
   parse_onlyR   t   warningst   warnR   t
   HTMLParsert   create_treebuildert   parseR   t
   isinstancet   unicodet   original_encodingt	   tokenizert   streamt   charEncoding(   R   R   t   parsert   doc(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   feed!   s    c         C   s   t  |  j |  |  _ |  j S(   N(   t   TreeBuilderForHtml5libR   t   underlying_builder(   R   t   namespaceHTMLElements(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR   /   s    c         C   s   d | S(   s   See `TreeBuilder`.u)   <html><head></head><body>%s</body></html>(    (   R   t   fragment(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   test_fragment_to_document4   s    (   t   __name__t
   __module__t   __doc__R   R   R   t   featuresR   R#   R   R(   (    (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR       s   			R$   c           B   sY   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   c         C   s#   | |  _  t t |   j |  d  S(   N(   R   t   superR$   t   __init__(   R   R   R&   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR.   ;   s    	c         C   s#   |  j  j   t |  j  |  j  d   S(   N(   R   t   resett   ElementR   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   documentClass?   s    c         C   sG   | d } | d } | d } t  j | | |  } |  j j |  d  S(   Nt   namet   publicIdt   systemId(   R   t   for_name_and_idsR   t   object_was_parsed(   R   t   tokenR2   R3   R4   t   doctype(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   insertDoctypeC   s
    


c         C   s(   |  j  j | |  } t | |  j  |  S(   N(   R   t   new_tagR0   (   R   R2   t	   namespacet   tag(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   elementClassK   s    c         C   s   t  t |  |  j  S(   N(   t   TextNodeR   R   (   R   t   data(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   commentClassO   s    c         C   s1   t  d  |  _ d |  j _ t |  j |  j d   S(   Nt    s   [document_fragment](   t   BeautifulSoupR   R2   R0   R   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   fragmentClassR   s    c         C   s   |  j  j | j  d  S(   N(   R   t   appendt   element(   R   t   node(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   appendChildW   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   getDocument[   s    c         C   s   t  j j j j |   j S(   N(   R   t   treebuilderst   _baset   TreeBuildert   getFragmentRE   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRL   ^   s    (   R)   R*   R.   R1   R9   R=   R@   RC   RG   RH   RL   (    (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR$   9   s   								t   AttrListc           B   sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s"   | |  _  t |  j  j  |  _ d  S(   N(   RE   t   dictt   attrs(   R   RE   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR.   b   s    	c         C   s   t  |  j j    j   S(   N(   t   listRO   t   itemst   __iter__(   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRR   e   s    c         C   s   d | | f | |  j  | <d  S(   Ns   set attr(   RE   (   R   R2   t   value(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   __setitem__g   s    c         C   s   t  |  j j    S(   N(   RP   RO   RQ   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRQ   j   s    c         C   s   t  |  j j    S(   N(   RP   RO   t   keys(   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRU   l   s    c         C   s   t  |  j  S(   N(   t   lenRO   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   __len__n   s    c         C   s   |  j  | S(   N(   RO   (   R   R2   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   __getitem__p   s    c         C   s   | t  |  j j    k S(   N(   RP   RO   RU   (   R   R2   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   __contains__r   s    (
   R)   R*   R.   RR   RT   RQ   RU   RW   RX   RY   (    (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRM   a   s   							R0   c           B   s   e  Z d    Z d   Z d   Z d   Z e e e  Z d d  Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z e e  Z RS(   c         C   s;   t  j j j j |  | j  | |  _ | |  _ | |  _ d  S(   N(	   R   RI   RJ   t   NodeR.   R2   RE   R   R;   (   R   RE   R   R;   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR.   w   s    		c         C   s   | j  j t k rp |  j  j rp |  j  j d j t k rp |  j  j d } |  j j | | j   } | j |  n |  j  j | j   |  | _ d  S(   Ni(	   RE   t	   __class__R	   t   contentsR   t
   new_stringt   replace_withRD   t   parent(   R   RF   t   old_elementt   new_element(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRG   }   s    c         C   s   t  |  j  S(   N(   RM   RE   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   getAttributes   s    c         C   s   | d  k	 r t |  d k r g  } xO t | j    D]; \ } } t | t  r7 t |   } | | =| | | <q7 q7 W|  j j j	 |  j
 |  x' | j   D] \ } } | |  j | <q W|  j j j |  j  n  d  S(   Ni    (   R   RV   RP   RQ   R   t   tupleR   R   t   buildert$   _replace_cdata_list_attribute_valuesR2   RE   t   set_up_substitutions(   R   t
   attributest   converted_attributesR2   RS   t   new_name(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   setAttributes   s    c         C   sH   t  |  j j |  |  j  } | r7 |  j | |  n |  j |  d  S(   N(   R>   R   R]   t   insertBeforeRG   (   R   R?   Rk   t   text(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt
   insertText   s    c         C   s   |  j  j | j   } | j  j t k r |  j  j r |  j  j | d j t k r |  j  j | d } |  j j | | j   } | j |  n |  j  j | | j   |  | _	 d  S(   Ni   (
   RE   t   indexR[   R	   R\   R   R]   R^   t   insertR_   (   R   RF   t   refNodeRn   t   old_nodet   new_str(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRk      s    c         C   s   | j  j   d  S(   N(   RE   t   extract(   R   RF   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   removeChild   s    c         C   s|   xu |  j  j rw |  j  j d } | j   t | t  r[ | j t | |  j t d   q | j t	 | |  j   q Wd  S(   Ni    t   html(
   RE   R\   Rs   R   R
   RG   R0   R   R   R>   (   R   t	   newParentt   child(    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   reparentChildren   s    
c         C   sa   |  j  j |  j j |  j  } t | |  j  |  j  } x$ |  j D] \ } } | | j | <q@ W| S(   N(   R   R:   RE   R2   R;   R0   Rg   (   R   R<   RF   t   keyRS   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt	   cloneNode   s
    c         C   s
   |  j  j S(   N(   RE   R\   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt
   hasContent   s    c         C   s4   |  j  d  k r  t d |  j f S|  j  |  j f Sd  S(   NRu   (   R;   R   R   R2   (   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   getNameTuple   s    N(   R)   R*   R.   RG   Rb   Rj   t   propertyRg   R   Rm   Rk   Rt   Rx   Rz   R{   R|   t	   nameTuple(    (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR0   v   s   										R>   c           B   s   e  Z d    Z d   Z RS(   c         C   s/   t  j j j j |  d   | |  _ | |  _ d  S(   N(   R   RI   RJ   RZ   R.   R   RE   R   (   R   RE   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR.      s    	c         C   s
   t   d  S(   N(   t   NotImplementedError(   R   (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyRz      s    (   R)   R*   R.   Rz   (    (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyR>      s   	(   t   __all__R   t   bs4.builderR   R   R   R   t   bs4.elementR   R   t   html5lib.constantsR   R   R   R	   R
   R    RI   RJ   RK   R$   t   objectRM   RZ   R0   R>   (    (    (    s:   /scratch/rashmi/Condor_Script/src/bs4/builder/_html5lib.pyt   <module>   s   	""#(a