ó
^†êWc           @` s'  d  Z  d d l m Z m Z m Z d d l Z 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 l j Z e Z e j d ƒ Z e j d ƒ j Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e	 j f d „  ƒ  YZ d S(   uÃ  Module for supporting the lxml.etree library. The idea here is to use as much
of the native library as possible, without using fragile hacks like custom element
names that break between releases. The downside of this is that we cannot represent
all possible trees; specifically the following are known to cause problems:

Text or comments as siblings of the root element
Docypes with no name

When any of these things occur, we emit a DataLossWarning
i    (   t   absolute_importt   divisiont   unicode_literalsNi   (   t   _basei   (   t   DataLossWarning(   t	   constants(   t   etree(   t   ihatexmlu   {([^}]*)}(.*)u   asdt   DocumentTypec           B` s   e  Z d  „  Z RS(   c         C` s   | |  _  | |  _ | |  _ d  S(   N(   t   namet   publicIdt   systemId(   t   selfR	   R
   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   __init__"   s    		(   t   __name__t
   __module__R   (    (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   !   s   t   Documentc           B` s/   e  Z d  „  Z d „  Z d „  Z e e ƒ Z RS(   c         C` s   d  |  _ g  |  _ d  S(   N(   t   Nonet   _elementTreet   _childNodes(   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   )   s    	c         C` s   |  j  j ƒ  j | j ƒ d  S(   N(   R   t   getroott   addnextt   _element(   R   t   element(    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   appendChild-   s    c         C` s   |  j  S(   N(   R   (   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _getChildNodes0   s    (   R   R   R   R   R   t   propertyt
   childNodes(    (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   (   s   			c         ` sp   g  ‰ d  } t j ƒ  ‰  d ‡  ‡ ‡ f d † ‰ ˆ |  d ƒ | d  k	 rc ˆ j d d | f ƒ n  d j ˆ ƒ S(   Ni    c         ` sL  t  |  d ƒ s¢t  |  d ƒ rˆ j d ƒ |  j j r© |  j j pL |  j j sb d |  j j } n% d |  j j |  j j |  j j f } ˆ j d d | d | f ƒ n  |  j ƒ  } x" | j ƒ  d  k	 rÙ | j ƒ  } q¸ WxÂ | d  k	 r	ˆ | | d ƒ | j
 ƒ  } qÝ WqHt |  t ƒ s+t |  t ƒ rpt |  t ƒ sRt j j d k sRt ‚ ˆ j d	 d | |  f ƒ qHˆ j d
 ƒ xÈ|  D] } ˆ | | d ƒ q„Wn¦|  j t k rˆ j d d | |  j f ƒ t  |  d ƒ rH|  j rHˆ j d	 d | |  j f ƒ qHn=t |  t j ƒ s#t ‚ t j j |  j ƒ } | d  k	 r™| j d ƒ } | j d ƒ } t j | } ˆ j d d | | ˆ  j | ƒ f ƒ n' ˆ j d d | ˆ  j |  j ƒ f ƒ t  |  d ƒ rµg  } x› |  j j  ƒ  D]Š \ }	 }
 t j |	 ƒ } | d  k	 rM| j! ƒ  \ } }	 ˆ  j |	 ƒ }	 t j | } d | |	 f } n ˆ  j |	 ƒ } | j | |
 f ƒ qåWx? t" | ƒ D]. \ }	 }
 ˆ j d d | d |	 |
 f ƒ q€Wn  |  j rãˆ j d	 d | d |  j f ƒ n  | d 7} x |  D] } ˆ | | ƒ qôWt  |  d ƒ rH|  j rHˆ j d	 d | d |  j f ƒ n  d  S(   Nu   tagu   getrootu	   #documentu   <!DOCTYPE %s>u   <!DOCTYPE %s "%s" "%s">u   |%s%su    i   u   |%s"%s"u   #document-fragmentu   |%s<!-- %s -->u   taili   u
   |%s<%s %s>u   |%s<%s>u   attribu   %s %su
   |%s%s="%s"(#   t   hasattrt   appendt   docinfot   internalDTDt	   public_idt
   system_urlt	   root_nameR   t   getpreviousR   t   getnextt
   isinstancet   strt   bytest   syst   version_infot   majort   AssertionErrort   tagt   comment_typet   textt   tailR   t   _Elementt   etree_builderst
   tag_regexpt   matcht   groupR   t   prefixest   fromXmlNamet   attribt   itemst   groupst   sorted(   R   t   indentt   dtd_strt   next_elementt   nsmatcht   nsR,   t   prefixt
   attributesR	   t   valuet   attr_stringt   child(   t   infosetFiltert   rvt   serializeElement(    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRG   ;   st    		"'$)	%
u   |%s"%s"u    i   u   
u     (   R   R   t   InfosetFilterR   t   join(   R   t	   finalText(    (   RE   RF   RG   s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   testSerializer6   s    Fc         ` s[   g  ‰  d } ‡  ‡ f d †  ‰ ˆ |  ƒ | d k	 rN ˆ  j d d | f ƒ n  d j ˆ  ƒ S(   u4   Serialize an element and its child nodes to a stringc         ` s‡  t  |  d ƒ si |  j j rV |  j j r6 |  j j } n d |  j j } ˆ  j | ƒ n  ˆ |  j ƒ  ƒ nï |  j t k r’ ˆ  j d |  j	 f ƒ nÆ |  j
 sµ ˆ  j d |  j f ƒ nU d j g  |  j
 j ƒ  D] \ } } d | | f ^ qË ƒ } ˆ  j d |  j | f ƒ |  j	 r&ˆ  j |  j	 ƒ n  x |  D] } ˆ | ƒ q-Wˆ  j d |  j f ƒ t  |  d	 ƒ rƒ|  j rƒˆ  j |  j ƒ n  d  S(
   Nu   tagu   <!DOCTYPE %s>u	   <!--%s-->u   <%s>u    u   %s="%s"u   <%s %s>u   </%s>u   tail(   R   R   R   t   doctypeR"   R   R   R,   R-   R.   R7   RI   R8   R/   (   R   R<   R	   RB   t   attrRD   (   RF   RG   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRG   Ž   s*    		2	u   %s"u    i   u    Nu     (   R   R   RI   (   R   RJ   (    (   RF   RG   s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   tostring‰   s     
t   TreeBuilderc           B` s†   e  Z e Z e Z d	 Z d	 Z e Z	 e
 Z e d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 d „ Z d	 d „ Z d „  Z RS(
   c         ` sÀ   t  j t d | ƒ‰ t j ƒ  ‰ |  _ | |  _ d t f ‡ f d †  ƒ  Y‰  d ˆ j f ‡  ‡ ‡ f d †  ƒ  Y} d ˆ j	 f ‡ ‡ f d †  ƒ  Y} | |  _
 ˆ j	 |  _ t j j |  | ƒ d  S(   Nt   fullTreet
   Attributesc           ` s)   e  Z i  ‡  f d  † Z ‡  f d †  Z RS(   c         ` s   | |  _  t j |  | ƒ xo |  j ƒ  D]a \ } } t | t ƒ re d | d ˆ  j | d ƒ f } n ˆ  j | ƒ } | |  j  j  j | <q& Wd  S(   Nu   {%s}%si   i   (   R   t   dictR   R8   R%   t   tuplet   coerceAttributeR7   (   R   R   RB   t   keyR	   (   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   Ä   s    	$c         ` sl   t  j |  | | ƒ t | t ƒ rF d | d ˆ  j | d ƒ f } n ˆ  j | ƒ } | |  j j j | <d  S(   Nu   {%s}%si   i   (   RR   t   __setitem__R%   RS   RT   R   R7   (   R   RU   RB   R	   (   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRV   Î   s
    $(   R   R   R   RV   (    (   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRQ   Ã   s   
t   Elementc           ` s•   e  Z ‡  ‡ ‡ f d  †  Z ‡ f d †  Z ‡ f d †  Z e e e ƒ Z d „  Z ‡  f d †  Z e e e ƒ Z	 d ‡ ‡ f d † Z ‡ f d †  Z RS(   c         ` s;   ˆ j  | ƒ } ˆ j j |  | d | ƒˆ  |  ƒ |  _ d  S(   Nt	   namespace(   t   coerceElementRW   R   t   _attributes(   R   R	   RX   (   RQ   t   builderRE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   ×   s    c         ` s4   ˆ  j  | ƒ |  _ |  j |  j |  j ƒ |  j _ d  S(   N(   RY   t   _namet   _getETreeTagt
   _namespaceR   R,   (   R   R	   (   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _setNameÜ   s    c         ` s   ˆ  j  |  j ƒ S(   N(   R6   R\   (   R   (   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _getNameá   s    c         S` s   |  j  S(   N(   RZ   (   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _getAttributesæ   s    c         ` s   ˆ  |  | ƒ |  _  d  S(   N(   RZ   (   R   RA   (   RQ   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _setAttributesé   s    c         ` s)   ˆ j  | ƒ } ˆ  j j |  | | ƒ d  S(   N(   t   coerceCharactersRW   t
   insertText(   R   t   datat   insertBefore(   R[   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRd   î   s    c         ` s   ˆ  j  j |  | ƒ d  S(   N(   RW   R   (   R   RD   (   R[   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   ò   s    N(   R   R   R   R_   R`   R   R	   Ra   Rb   RA   R   Rd   R   (    (   RQ   R[   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRW   Ö   s   	t   Commentc           ` sA   e  Z ‡  ‡ f d  †  Z ‡ f d †  Z d „  Z e e e ƒ Z RS(   c         ` s&   ˆ j  | ƒ } ˆ  j j |  | ƒ d  S(   N(   t   coerceCommentRg   R   (   R   Re   (   R[   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   ö   s    c         ` s   ˆ  j  | ƒ } | |  j _ d  S(   N(   Rh   R   R.   (   R   Re   (   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _setDataú   s    c         S` s
   |  j  j S(   N(   R   R.   (   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   _getDataþ   s    (   R   R   R   Ri   Rj   R   Re   (    (   R[   RE   (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRg   õ   s   	(   R1   t   getETreeModuleR   R   RH   RE   t   namespaceHTMLElementsRR   RW   Rg   t   elementClasst   commentClassR   RO   R   (   R   Rl   RP   RW   Rg   (    (   RQ   R[   RE   s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR   ¾   s    	%"	c         C` s2   t  j j |  ƒ |  j |  _ g  |  _ d  |  _ d  S(   N(   R   RO   t   resett   insertCommentInitialt   insertCommentt   initial_commentsR   RL   (   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRo     s    	c         C` s
   t  | ƒ S(   N(   RK   (   R   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRK     s    c         C` s$   t  r |  j j S|  j j j ƒ  Sd  S(   N(   RP   t   documentR   R   (   R   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   getDocument  s    
c         C` se   g  } |  j  d j } | j r2 | j | j ƒ n  | j t | ƒ ƒ | j ra | j | j ƒ n  | S(   Ni    (   t   openElementsR   R.   R   t   extendt   listR/   (   R   t   fragmentR   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   getFragment  s    		c         C` s“   | d } | d } | d } | s@ t  j d t ƒ d  |  _ nO |  j j | ƒ } | | k rq t  j d t ƒ n  |  j | | | ƒ } | |  _ d  S(   Nu   nameu   publicIdu   systemIdu#   lxml cannot represent empty doctypeu%   lxml cannot represent non-xml doctype(   t   warningst   warnR   R   RL   RE   RY   t   doctypeClass(   R   t   tokenR	   R
   R   t   coercedNameRL   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   insertDoctype!  s    


c         C` s   |  j  j | ƒ d  S(   N(   Rr   R   (   R   Re   t   parent(    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRp   1  s    c         C` s^   | |  j  k rA |  j  j j ƒ  d j t k rA t j d t ƒ n  t t	 |  ƒ j
 | | ƒ d  S(   Niÿÿÿÿu@   lxml cannot represent adjacent comments beyond the root elements(   Rs   R   R   R,   R-   Rz   R{   R   t   superRO   Rq   (   R   Re   R€   (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   insertCommentMain4  s    c   
      C` sc  d } |  j  r`|  j  j s! t ‚ | d |  j  j 7} |  j  j d k	 sY |  j  j d k	 r*| d |  j j |  j  j pw d ƒ 7} |  j  j r|  j  j } | j d ƒ d k ræ | j d ƒ d k ræ t	 j
 d t ƒ | j d d ƒ } n  | j d ƒ d k r| d	 | 7} q'| d
 | 7} q*| d 7} n  | d 7} |  j  j | d k r`t	 j
 d t ƒ q`n  | d 7} t j | ƒ } x+ |  j D]  } | j t j | d ƒ ƒ qƒW|  j ƒ  |  _ | j ƒ  |  j _ | d } | j d |  j ƒ } | d k rü| } n d | | f } | | _ |  j | | ƒ }	 | |	 _ |  j j j |	 ƒ |  j j |	 ƒ |  j |  _ d S(   u   Create the document rootu    u   <!DOCTYPE %su    PUBLIC "%s" u   'i    u   "u6   DOCTYPE system cannot contain single and double quotesu   U00027u   "%s"u   '%s'u   ''u   >u   nameuG   lxml cannot represent doctype with a different name to the root elementu$   <THIS_SHOULD_NEVER_APPEAR_PUBLICLY/>u   datau	   namespaceu   {%s}%sN(    RL   R	   R+   R
   R   R   RE   t   coercePubidt   findRz   R{   R   t   replaceR   t
   fromstringRr   t   addpreviousRg   t   documentClassRs   t   getroottreeR   t   gett   defaultNamespaceR,   Rm   R   R   R   Ru   R‚   Rq   (
   R   R}   t   docStrt   sysidt   roott   comment_tokenR	   RX   t	   etree_tagt   root_element(    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt
   insertRoot:  sJ    	 *


			N(   R   R   R   Rˆ   R   R|   R   Rm   Rn   t   fragmentClassR   t   implementationt   FalseR   Ro   RK   Rt   Ry   R   Rp   R‚   R’   (    (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRO   ¶   s   J				
	(   t   __doc__t
   __future__R    R   R   Rz   t   reR(   t    R   R   R   R   R1   R   t
   lxml.etreet   TrueRP   t   compileR2   Rg   R,   R-   t   objectR   R   RK   RN   RO   (    (    (    s}   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt   <module>
   s$   	S	-