ó
Ð²Ebc           @` sÃ   d  d l  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	 d d l m
 Z
 d d	 l m Z d d
 l m Z d d l m Z e j d ƒ Z e d „ Z e e ƒ Z d S(   i    (   t   absolute_importt   divisiont   unicode_literals(   t	   text_typeN(   t   copyi   (   t   basei   (   t	   _ihatexml(   t	   constants(   t
   namespaces(   t   moduleFactoryFactoryu   {([^}]*)}(.*)c      
   ` s  ˆ ‰ ˆ j  d ƒ j ‰ d t j f ‡ f d †  ƒ  Y‰ d ˆ f ‡ f d †  ƒ  Y‰  d ˆ f ‡ f d †  ƒ  Y‰ d ˆ f ‡ f d	 †  ƒ  Y‰ d
 ˆ f ‡ f d †  ƒ  Y‰ ‡ f d †  ‰	 ‡ ‡ f d †  } d t j f ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡	 f d †  ƒ  Y} t ƒ  S(   Nu   asdt   Elementc           ` sé   e  Z d ‡  f d  † Z d „  Z d „  Z d „  Z e e e ƒ Z d „  Z	 d „  Z
 e e
 e	 ƒ Z d „  Z d „  Z e e e ƒ Z d „  Z d	 „  Z e e e ƒ Z d
 „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z RS(   c         ` s‰   | |  _  | |  _ ˆ  j |  j | | ƒ ƒ |  _ | d  k rU t d |  j  f |  _ n |  j |  j  f |  _ d  |  _ g  |  _	 g  |  _
 d  S(   Nu   html(   t   _namet
   _namespaceR
   t   _getETreeTagt   _elementt   NoneR   t	   nameTuplet   parentt   _childNodest   _flags(   t   selft   namet	   namespace(   t   ElementTree(    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   __init__   s    				c         S` s)   | d  k r | } n d | | f } | S(   Nu   {%s}%s(   R   (   R   R   R   t	   etree_tag(    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyR   %   s    	c         S` s+   | |  _  |  j |  j  |  j ƒ |  j _ d  S(   N(   R   R   R   R   t   tag(   R   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setName,   s    	c         S` s   |  j  S(   N(   R   (   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getName0   s    c         S` s+   | |  _  |  j |  j |  j  ƒ |  j _ d  S(   N(   R   R   R   R   R   (   R   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setNamespace5   s    	c         S` s   |  j  S(   N(   R   (   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getNamespace9   s    c         S` s
   |  j  j S(   N(   R   t   attrib(   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getAttributes>   s    c         S` sz   |  j  j } | j ƒ  | rv xW | j ƒ  D]F \ } } t | t ƒ r_ d | d | d f } n | } | | | <q) Wn  d  S(   Nu   {%s}%si   i   (   R   R   t   cleart   itemst
   isinstancet   tuple(   R   t
   attributest	   el_attribt   keyt   valueR   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setAttributesA   s    
c         S` s   |  j  S(   N(   R   (   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getChildNodesP   s    c         S` s2   |  j  2g  |  _ x | D] } |  j | ƒ q Wd  S(   N(   R   R   t   insertChild(   R   R(   t   element(    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setChildNodesS   s    	c         S` s   t  |  j j p t |  j ƒ ƒ S(   u,   Return true if the node has children or text(   t   boolR   t   textt   len(   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt
   hasContent[   s    c         S` s0   |  j  j | ƒ |  j j | j ƒ |  | _ d  S(   N(   R   t   appendR   R   (   R   t   node(    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   appendChild_   s    c         S` s>   t  |  j ƒ j | j ƒ } |  j j | | j ƒ |  | _ d  S(   N(   t   listR   t   indext   insertR   (   R   R3   t   refNodeR6   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   insertBefored   s    c         S` s0   |  j  j | ƒ |  j j | j ƒ d  | _ d  S(   N(   R   t   removeR   R   R   (   R   R3   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   removeChildi   s    c         S` s-  t  |  j ƒ s? |  j j s* d |  j _ n  |  j j | 7_ nê | d  k r‡ |  j d j sn d |  j d _ n  |  j d j | 7_ n¢ t |  j ƒ } | j | j ƒ } | d k rü |  j | d j sß d |  j | d _ n  |  j | d j | 7_ n- |  j j sd |  j _ n  |  j j | 7_ d  S(   Nu    iÿÿÿÿi    i   (   R0   R   R/   R   t   tailR5   R6   (   R   t   dataR9   t   childrenR6   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt
   insertTextn   s"    c         S` sF   t  |  ƒ |  j |  j ƒ } |  j j rB t |  j j ƒ | j _ n  | S(   N(   t   typeR   R   R   R   R   (   R   R,   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt	   cloneNode…   s    c         S` s–   | j  r+ | j  d j j |  j j 7_ nH | j j sF d | j _ n  |  j j d  k	 rs | j j |  j j 7_ n  d |  j _ t j j |  | ƒ d  S(   Niÿÿÿÿu    (   t
   childNodesR   R<   R/   R   R   t   Nodet   reparentChildren(   R   t	   newParent(    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRD   ‹   s    	"N(   t   __name__t
   __module__R   R   R   R   R   t   propertyR   R   R   R   R    R)   R%   R*   R-   RB   R1   R4   R9   R;   R?   RA   RD   (    (   R   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyR
      s*   														t   Commentc           ` s8   e  Z ‡  f d  †  Z d „  Z d „  Z e e e ƒ Z RS(   c         ` s1   ˆ  j  | ƒ |  _ d  |  _ g  |  _ g  |  _ d  S(   N(   RI   R   R   R   R   R   (   R   R=   (   R   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyR   —   s    		c         S` s
   |  j  j S(   N(   R   R/   (   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getDataŸ   s    c         S` s   | |  j  _ d  S(   N(   R   R/   (   R   R(   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setData¢   s    (   RF   RG   R   RJ   RK   RH   R=   (    (   R   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRI   –   s   		t   DocumentTypec           ` sY   e  Z ‡  f d  †  Z d „  Z d „  Z e e e ƒ Z d „  Z d „  Z e e e ƒ Z	 RS(   c         ` s2   ˆ  j  |  d ƒ | |  j _ | |  _ | |  _ d  S(   Nu
   <!DOCTYPE>(   R   R   R/   t   publicIdt   systemId(   R   R   RM   RN   (   R
   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyR   ¨   s    	c         S` s   |  j  j d d ƒ S(   Nu   publicIdu    (   R   t   get(   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getPublicId®   s    c         S` s&   | d  k	 r" |  j j d | ƒ n  d  S(   Nu   publicId(   R   R   t   set(   R   R(   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setPublicId±   s    c         S` s   |  j  j d d ƒ S(   Nu   systemIdu    (   R   RO   (   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _getSystemId·   s    c         S` s&   | d  k	 r" |  j j d | ƒ n  d  S(   Nu   systemId(   R   R   RQ   (   R   R(   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   _setSystemIdº   s    (
   RF   RG   R   RP   RR   RH   RM   RS   RT   RN   (    (   R
   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRL   §   s   				t   Documentc           ` s   e  Z ‡  f d  †  Z RS(   c         ` s   ˆ  j  |  d ƒ d  S(   Nu   DOCUMENT_ROOT(   R   (   R   (   R
   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyR   Á   s    (   RF   RG   R   (    (   R
   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRU   À   s   t   DocumentFragmentc           ` s   e  Z ‡  f d  †  Z RS(   c         ` s   ˆ  j  |  d ƒ d  S(   Nu   DOCUMENT_FRAGMENT(   R   (   R   (   R
   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyR   Å   s    (   RF   RG   R   (    (   R
   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRV   Ä   s   c         ` s8   g  ‰  d ‡ ‡  ‡ f d † ‰ ˆ |  d ƒ d j  ˆ  ƒ S(   Ni    c         ` sŠ  t  |  d ƒ s |  j ƒ  }  n  |  j d k r¯ |  j d ƒ sK |  j d ƒ r• |  j d ƒ p] d } |  j d ƒ pr d } ˆ j d |  j | | f ƒ q0ˆ j d |  j f ƒ n|  j d k rMˆ j d	 ƒ |  j d  k	 rÿ ˆ j d
 d | d |  j f ƒ n  |  j d  k	 rt d ƒ ‚ n  t  |  d ƒ r0t	 |  j
 ƒ r0t d ƒ ‚ q0nã|  j ˆ  k r}ˆ j d d | |  j f ƒ n³t |  j t ƒ s±t d t |  j ƒ |  j f ƒ ‚ t j |  j ƒ } | d  k rÛ|  j } n/ | j ƒ  \ } } t j | } d | | f } ˆ j d d | | f ƒ t  |  d ƒ rg  } xƒ |  j
 j ƒ  D]r \ } }	 t j | ƒ } | d  k	 r£| j ƒ  \ } } t j | } d | | f }
 n | }
 | j |
 |	 f ƒ qJWx? t | ƒ D]. \ } }	 ˆ j d d | d | |	 f ƒ qÍWn  |  j r0ˆ j d
 d | d |  j f ƒ n  | d 7} x |  D] } ˆ | | ƒ qAW|  j r†ˆ j d
 d | d |  j f ƒ n  d  S(   Nu   tagu
   <!DOCTYPE>u   publicIdu   systemIdu    u   <!DOCTYPE %s "%s" "%s">u   <!DOCTYPE %s>u   DOCUMENT_ROOTu	   #documentu   |%s"%s"u    i   u   Document node cannot have tailu   attribu$   Document node cannot have attributesu   |%s<!-- %s -->u   Expected unicode, got %s, %su   %s %su   |%s<%s>u
   |%s%s="%s"(   t   hasattrt   getrootR   RO   R2   R/   R   R<   t	   TypeErrorR0   R   R#   R   t   AssertionErrorR@   t
   tag_regexpt   matcht   groupsR   t   prefixesR"   t   sorted(   R,   t   indentRM   RN   t   nsmatchR   t   nst   prefixR%   R(   t   attr_stringt   child(   t   ElementTreeCommentTypet   rvt   serializeElement(    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRh   Ë   s^    	%!)	%
	u   
(   t   join(   R,   (   Rf   (   Rg   Rh   sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   testSerializerÈ   s    7c         ` sD   g  ‰ t  j ƒ  ‰  ‡ ‡ ‡  ‡ ‡ f d †  ‰ ˆ |  ƒ d j ˆ ƒ S(   u4   Serialize an element and its child nodes to a stringc         ` sm  t  |  ˆ  j ƒ r! |  j ƒ  }  n  |  j d k r² |  j d ƒ sN |  j d ƒ r˜ |  j d ƒ p` d } |  j d ƒ pu d } ˆ j d |  j | | f ƒ qMˆ j d |  j f ƒ n›|  j d k rL|  j d  k	 rã ˆ j |  j ƒ n  |  j d  k	 rt	 d ƒ ‚ n  t
 |  d	 ƒ r.t |  j ƒ r.t	 d
 ƒ ‚ n  x|  D] } ˆ | ƒ q5Wn|  j ˆ k ruˆ j d |  j f ƒ nØ |  j s¡ˆ j d ˆ j |  j ƒ f ƒ n^ d j g  |  j j ƒ  D]% \ } } d ˆ j | ƒ | f ^ q·ƒ } ˆ j d |  j | f ƒ |  j rˆ j |  j ƒ n  x |  D] } ˆ | ƒ q"Wˆ j d |  j f ƒ |  j riˆ j |  j ƒ n  d  S(   Nu
   <!DOCTYPE>u   publicIdu   systemIdu    u   <!DOCTYPE %s PUBLIC "%s" "%s">u   <!DOCTYPE %s>u   DOCUMENT_ROOTu   Document node cannot have tailu   attribu$   Document node cannot have attributesu	   <!--%s-->u   <%s>u    u   %s="%s"u   <%s %s>u   </%s>(   R#   R   RX   R   RO   R2   R/   R   R<   RY   RW   R0   R   t   fromXmlNameRi   R"   (   R,   RM   RN   Re   R   R(   t   attr(   R   Rf   t   filterRg   Rh   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRh     s@    		#	;		u    (   R   t   InfosetFilterRi   (   R,   (   R   Rf   (   Rm   Rg   Rh   sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   tostring  s
    -
t   TreeBuilderc           ` sS   e  Z ˆ Z ˆ Z ˆ Z ˆ  Z ˆ Z ˆ Z ‡ f d  †  Z ‡ f d †  Z	 d „  Z
 RS(   c         ` s
   ˆ  | ƒ S(   N(    (   R   R,   (   Rj   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRj   D  s    c         ` sP   ˆ  r |  j  j S|  j d  k	 r9 |  j  j j d |  j ƒ S|  j  j j d ƒ Sd  S(   Nu   {%s}htmlu   html(   t   documentR   t   defaultNamespaceR   t   find(   R   (   t   fullTree(    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   getDocumentG  s    
c         S` s   t  j j |  ƒ j S(   N(   R   Rp   t   getFragmentR   (   R   (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRv   Q  s    (   RF   RG   t   documentClasst   doctypeClasst   elementClasst   commentClasst   fragmentClasst   implementationRj   Ru   Rv   (    (   RI   RU   RV   RL   R
   t   ElementTreeImplementationRt   Rj   (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyRp   <  s   
(   RI   R   R   RC   Rp   t   locals(   R}   Rt   Ro   Rp   (    (
   RI   RU   RV   RL   R
   R   Rf   R}   Rt   Rj   sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   getETreeBuilder   s    >64(   t
   __future__R    R   R   t   pip._vendor.sixR   t   reR   t    R   R   R   R   t   _utilsR	   t   compileR[   t   FalseR   t   getETreeModule(    (    (    sD   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/etree.pyt   <module>   s   ÿ E