ó
Ð²Ebc           @` sÏ   d  d l  m Z m Z m Z y d  d l m Z Wn! e k
 rS d  d l m Z n Xd  d l m	 Z	 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 „  Z e e ƒ Z d S(   i    (   t   absolute_importt   divisiont   unicode_literals(   t   MutableMapping(   t   minidomt   NodeNi   (   t   basei   (   t	   constants(   t
   namespaces(   t   moduleFactoryFactoryc         ` sv   ˆ ‰ d t  f d „  ƒ  Y‰  d t j f ‡  ‡ f d †  ƒ  Y‰ d t j f ‡ ‡ ‡ ‡ f d †  ƒ  Y} d „  ‰ t ƒ  S(   Nt   AttrListc           B` sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         S` s   | |  _  d  S(   N(   t   element(   t   selfR   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   __init__   s    c         S` s   t  |  j j j ƒ  ƒ S(   N(   t   iterR   t
   attributest   keys(   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   __iter__   s    c         S` sJ   t  | t ƒ r t ‚ n. |  j j j | ƒ } | | _ | |  j j | <d  S(   N(   t
   isinstancet   tuplet   NotImplementedErrorR   t   ownerDocumentt   createAttributet   valueR   (   R   t   nameR   t   attr(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   __setitem__   s
    		c         S` s   t  |  j j ƒ S(   N(   t   lenR   R   (   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   __len__#   s    c         S` s   t  |  j j j ƒ  ƒ S(   N(   t   listR   R   t   items(   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR   &   s    c         S` s   t  |  j j j ƒ  ƒ S(   N(   R   R   R   t   values(   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR   )   s    c         S` s-   t  | t ƒ r t ‚ n |  j j | j Sd  S(   N(   R   R   R   R   R   R   (   R   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   __getitem__,   s    	c         S` s)   t  | t ƒ r t ‚ n |  j j | =d  S(   N(   R   R   R   R   R   (   R   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   __delitem__2   s    	(
   t   __name__t
   __module__R   R   R   R   R   R   R    R!   (    (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR
      s   							t   NodeBuilderc           ` s¤   e  Z d  „  Z e d „  ƒ Z d „  Z d d „ Z d „  Z d „  Z	 d „  Z
 ‡  f d †  Z d „  Z e e e ƒ Z ‡ f d	 †  Z d
 „  Z d „  Z e e ƒ Z RS(   c         S` s#   t  j j |  | j ƒ | |  _ d  S(   N(   R   R   R   t   nodeNameR   (   R   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR   9   s    c         S` s"   t  |  j d ƒ r |  j j p! d  S(   Nu   namespaceURI(   t   hasattrR   t   namespaceURIt   None(   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   <lambda>=   s   c         S` s    |  | _  |  j j | j ƒ d  S(   N(   t   parentR   t   appendChild(   R   t   node(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR+   @   s    	c         S` sH   |  j  j j | ƒ } | r4 |  j  j | | j  ƒ n |  j  j | ƒ d  S(   N(   R   R   t   createTextNodet   insertBeforeR+   (   R   t   dataR.   t   text(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt
   insertTextD   s    c         S` s&   |  j  j | j  | j  ƒ |  | _ d  S(   N(   R   R.   R*   (   R   R,   t   refNode(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR.   K   s    c         S` s8   | j  j |  j  k r+ |  j  j | j  ƒ n  d  | _ d  S(   N(   R   t
   parentNodet   removeChildR(   R*   (   R   R,   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR4   O   s    c         S` sO   x? |  j  j ƒ  rA |  j  j } |  j  j | ƒ | j  j | ƒ q Wg  |  _ d  S(   N(   R   t   hasChildNodest
   firstChildR4   R+   t
   childNodes(   R   t	   newParentt   child(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   reparentChildrenT   s
    c         ` s   ˆ  |  j  ƒ S(   N(   R   (   R   (   R
   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   getAttributes[   s    c         S` s¢   | rž x• t  | j ƒ  ƒ D]~ \ } } t | t ƒ r„ | d d  k	 r] | d d | d } n
 | d } |  j j | d | | ƒ q |  j j | | ƒ q Wn  d  S(   Ni    u   :i   i   (   R   R   R   R   R(   R   t   setAttributeNSt   setAttribute(   R   R   R   R   t   qualifiedName(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   setAttributes^   s    

	c         ` s   ˆ  |  j  j t ƒ ƒ S(   N(   R   t	   cloneNodet   False(   R   (   R$   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR@   m   s    c         S` s   |  j  j ƒ  S(   N(   R   R5   (   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt
   hasContentp   s    c         S` s4   |  j  d  k r  t d |  j f S|  j  |  j f Sd  S(   Nu   html(   t	   namespaceR(   R   R   (   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   getNameTuples   s    N(   R"   R#   R   t   propertyRC   R+   R(   R1   R.   R4   R:   R;   R?   R   R@   RB   RD   t	   nameTuple(    (   R
   R$   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR$   8   s   								t   TreeBuilderc           ` s›   e  Z ‡  f d  †  Z ‡  ‡ f d †  Z d
 ‡ f d † Z ‡ f d †  Z ‡ f d †  Z d „  Z ‡ f d †  Z	 d „  Z
 d „  Z d
 d	 „ Z ˆ Z d
 Z RS(   c         ` s+   ˆ  j  ƒ  j d  d  d  ƒ |  _ t j |  ƒ S(   N(   t   getDOMImplementationt   createDocumentR(   t   domt   weakreft   proxy(   R   (   t   Dom(    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   documentClass|   s    c         ` st   | d } | d } | d } ˆ  j  ƒ  } | j | | | ƒ } |  j j ˆ | ƒ ƒ ˆ  t k rp |  j | _ n  d  S(   Nu   nameu   publicIdu   systemId(   RH   t   createDocumentTypet   documentR+   R   RJ   R   (   R   t   tokenR   t   publicIdt   systemIdt   domimplt   doctype(   RM   R$   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   insertDoctype€   s    


c         ` sO   | d  k r0 |  j d  k r0 |  j j | ƒ } n |  j j | | ƒ } ˆ  | ƒ S(   N(   R(   t   defaultNamespaceRJ   t   createElementt   createElementNS(   R   R   RC   R,   (   R$   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   elementClass‹   s    c         ` s   ˆ  |  j  j | ƒ ƒ S(   N(   RJ   t   createComment(   R   R/   (   R$   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   commentClass“   s    c         ` s   ˆ  |  j  j ƒ  ƒ S(   N(   RJ   t   createDocumentFragment(   R   (   R$   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   fragmentClass–   s    c         S` s   |  j  j | j ƒ d  S(   N(   RJ   R+   R   (   R   R,   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR+   ™   s    c         ` s
   ˆ  | ƒ S(   N(    (   R   R   (   t   testSerializer(    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR_   œ   s    c         S` s   |  j  S(   N(   RJ   (   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   getDocumentŸ   s    c         S` s   t  j j |  ƒ j S(   N(   R   RG   t   getFragmentR   (   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyRa   ¢   s    c         S` s¦   | } | |  k r+ t  j j |  | | ƒ nw t |  j d ƒ r† t j |  j j k r† t |  j j ƒ |  j _ |  j j j	 t j ƒ q† n  |  j j
 |  j j | ƒ ƒ d  S(   Nu   _child_node_types(   R   RG   R1   R&   RJ   R   t	   TEXT_NODEt   _child_node_typesR   t   appendR+   R-   (   R   R/   R*   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR1   ¥   s    N(   R"   R#   RN   RV   R(   RZ   R\   R^   R+   R_   R`   Ra   R1   t   implementationR   (    (   RM   t   DomImplementationR$   R_   (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyRG   {   s   			c         ` s?   |  j  ƒ  g  ‰  d ‡  ‡ f d † ‰ ˆ |  d ƒ d j ˆ  ƒ S(   Ni    c         ` sÉ  |  j  t j k r® |  j r“ |  j s- |  j rr |  j p9 d } |  j pH d } ˆ  j d d | |  j | | f ƒ q« ˆ  j d d | |  j f ƒ qšˆ  j d d | f ƒ nì|  j  t j k rÐ ˆ  j d ƒ nÊ|  j  t j k rò ˆ  j d ƒ n¨|  j  t j	 k r%ˆ  j d d | |  j
 f ƒ nu|  j  t j k rXˆ  j d	 d | |  j
 f ƒ nBt |  d
 ƒ r–|  j d  k	 r–d t j |  j |  j f } n	 |  j } ˆ  j d d | | f ƒ |  j ƒ  ršg  } x‰ t t |  j ƒ ƒ D]r } |  j j | ƒ } | j } | j } | j }	 |	 r8d t j |	 | j f } n	 | j } | j | | f ƒ qâWx? t | ƒ D]. \ } } ˆ  j d d | d | | f ƒ qeWn  | d 7} x |  j D] }
 ˆ |
 | ƒ q®Wd  S(   Nu    u   |%s<!DOCTYPE %s "%s" "%s">u    u   |%s<!DOCTYPE %s>u   |%s<!DOCTYPE >u	   #documentu   #document-fragmentu   |%s<!-- %s -->u   |%s"%s"u   namespaceURIu   %s %su   |%s<%s>u
   |%s%s="%s"i   (   t   nodeTypeR   t   DOCUMENT_TYPE_NODER   RR   RS   Rd   t   DOCUMENT_NODEt   DOCUMENT_FRAGMENT_NODEt   COMMENT_NODEt	   nodeValueRb   R&   R'   R(   R   t   prefixesR%   t   hasAttributest   rangeR   R   t   itemR   t	   localNamet   sortedR7   (   R   t   indentRR   RS   R   R   t   iR   R   t   nsR9   (   t   rvt   serializeElement(    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyRw   ¹   sN    		!!!					)
u   
(   t	   normalizet   join(   R   (    (   Rv   Rw   sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyR_   µ   s
    
.(   R   R   R   RG   t   locals(   Rf   RG   (    (   R
   RM   Rf   R$   R_   sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   getDomBuilder   s    $"C(:	6(   t
   __future__R    R   R   t   collections.abcR   t   ImportErrort   collectionst   xml.domR   R   RK   t    R   R   R   t   _utilsR	   R{   t   getDomModule(    (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/dom.pyt   <module>   s   	Þ