Ñò
•èRc           @` s'  d  Z  d d k l Z l Z l Z d d k Z d d k Z d d k Z d d k l	 Z	 d d k
 l Z d d k l
 Z
 d d	 k l Z d d
 k l Z d d k i Z e Z e i d ƒ Z e i d ƒ i Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e	 i 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   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   __init__"   s    		(   t   __name__t
   __module__R   (    (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/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   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   )   s    	c         C` s   |  i  i ƒ  i | i ƒ d  S(   N(   R   t   getroott   addnextt   _element(   R   t   element(    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   appendChild-   s    c         C` s   |  i  S(   N(   R   (   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _getChildNodes0   s    (   R   R   R   R   R   t   propertyt
   childNodes(    (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   (   s   			c         ` sr   g  ‰  d  } t i ƒ  ‰ d ‡  ‡ ‡ f d † ‰ ˆ |  d ƒ | d  j	 o ˆ  i d d | f ƒ n d i ˆ  ƒ S(   Ni    c         ` sq  t  |  d ƒ p¥t  |  d ƒ où ˆ  i d ƒ |  i i ov |  i i p
 |  i i p d |  i i } n& d |  i i |  i i |  i i f } ˆ  i d d | d | f ƒ n |  i ƒ  } x$ | i ƒ  d  j	 o | i ƒ  } q¿ WxË | d  j	 o! ˆ | | d ƒ | i
 ƒ  } qæ Wqmt |  t ƒ p t |  t ƒ oI t |  t ƒ p t i i d j p t ‚ ˆ  i d	 d | |  f ƒ qmˆ  i d
 ƒ xÛ|  D] } ˆ | | d ƒ q–Wn¹|  i t j o^ ˆ  i d d | |  i f ƒ t  |  d ƒ o, |  i o" ˆ  i d	 d | |  i f ƒ qmnKt |  t i ƒ p t ‚ t i i |  i ƒ } | d  j	 oV | i d ƒ } | i d ƒ } t i | } ˆ  i d d | | ˆ i | ƒ f ƒ n( ˆ  i d d | ˆ i |  i ƒ f ƒ t  |  d ƒ oé g  } x |  i i  ƒ  D]Œ \ }	 }
 t i |	 ƒ } | d  j	 oB | i! ƒ  \ } }	 ˆ i |	 ƒ }	 t i | } d | |	 f } n ˆ i |	 ƒ } | i | |
 f ƒ qWx@ t" | ƒ D]. \ }	 }
 ˆ  i d d | d |	 |
 f ƒ qŸWn |  i o& ˆ  i d	 d | d |  i f ƒ n | d 7} x |  D] } ˆ | | ƒ qWt  |  d ƒ o0 |  i o& ˆ  i d	 d | d |  i 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   rvt   serializeElementt   infosetFilter(    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRF   ;   s€    		#   * &  *
&
 u   |%s"%s"u    i   u   
u     (   R   R   t   InfosetFilterR   t   join(   R   t	   finalText(    (   RE   RF   RG   sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   testSerializer6   s    Fc         ` s]   g  ‰  d } ‡  ‡ f d †  ‰ ˆ |  ƒ | d j	 o ˆ  i d d | f ƒ n d i ˆ  ƒ S(   u4   Serialize an element and its child nodes to a stringc         ` sž  t  |  d ƒ p_ |  i i o> |  i i o |  i i } n d |  i i } ˆ  i | ƒ n ˆ |  i ƒ  ƒ nþ |  i t j o ˆ  i d |  i	 f ƒ nÓ |  i
 p ˆ  i d |  i f ƒ n^ d i g  } |  i
 i ƒ  D] \ } } | d | | f qÙ ~ ƒ } ˆ  i d |  i | f ƒ |  i	 o ˆ  i |  i	 ƒ n x |  D] } ˆ | ƒ qAWˆ  i d |  i f ƒ t  |  d	 ƒ o |  i o ˆ  i |  i ƒ 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<   t   _[1]R	   RB   t   attrRD   (   RE   RF   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRF   Ž   s,    
6
 u   %s"u    i   u    Nu     (   R   R   RI   (   R   RJ   (    (   RE   RF   sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/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  i t d | ƒ‰ t i ƒ  ‰ |  _ | |  _ d t f ‡ f d †  ƒ  Y‰  d ˆ i f ‡ ‡ ‡  f d †  ƒ  Y} d ˆ i	 f ‡ ‡ f d †  ƒ  Y} | |  _
 ˆ i	 |  _ t i i |  | ƒ d  S(   Nt   fullTreet
   Attributesc           ` s)   e  Z h  ‡  f d  † Z ‡  f d †  Z RS(   c         ` s‘   | |  _  t i |  | ƒ xq |  i ƒ  D]c \ } } t | t ƒ o% d | d ˆ  i | d ƒ f } n ˆ  i | ƒ } | |  i  i  i | <q& Wd  S(   Nu   {%s}%si   i   (   R   t   dictR   R8   R%   t   tuplet   coerceAttributeR7   (   R   R   RB   t   keyR	   (   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   Ä   s    	 %c         ` sn   t  i |  | | ƒ t | t ƒ o% d | d ˆ  i | d ƒ f } n ˆ  i | ƒ } | |  i i i | <d  S(   Nu   {%s}%si   i   (   RS   t   __setitem__R%   RT   RU   R   R7   (   R   RV   RB   R	   (   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRW   Î   s
    %(   R   R   R   RW   (    (   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRR   Ã   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;   ˆ i  | ƒ } ˆ  i i |  | d | ƒˆ |  ƒ |  _ d  S(   Nt	   namespace(   t   coerceElementRX   R   t   _attributes(   R   R	   RY   (   t   builderRG   RR   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   ×   s    c         ` s4   ˆ  i  | ƒ |  _ |  i |  i |  i ƒ |  i _ d  S(   N(   RZ   t   _namet   _getETreeTagt
   _namespaceR   R,   (   R   R	   (   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _setNameÜ   s    c         ` s   ˆ  i  |  i ƒ S(   N(   R6   R]   (   R   (   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _getNameá   s    c         S` s   |  i  S(   N(   R[   (   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _getAttributesæ   s    c         ` s   ˆ  |  | ƒ |  _  d  S(   N(   R[   (   R   RA   (   RR   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _setAttributesé   s    c         ` s)   ˆ i  | ƒ } ˆ  i i |  | | ƒ d  S(   N(   t   coerceCharactersRX   t
   insertText(   R   t   datat   insertBefore(   R\   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRe   î   s    c         ` s   ˆ  i  i |  | ƒ d  S(   N(   RX   R   (   R   RD   (   R\   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   ò   s    N(   R   R   R   R`   Ra   R   R	   Rb   Rc   RA   R   Re   R   (    (   R\   RG   RR   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRX   Ö   s   	t   Commentc           ` sA   e  Z ‡  ‡ f d  †  Z ‡ f d †  Z d „  Z e e e ƒ Z RS(   c         ` s&   ˆ i  | ƒ } ˆ  i i |  | ƒ d  S(   N(   t   coerceCommentRh   R   (   R   Rf   (   R\   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   ö   s    c         ` s   ˆ  i  | ƒ } | |  i _ d  S(   N(   Ri   R   R.   (   R   Rf   (   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _setDataú   s    c         S` s
   |  i  i S(   N(   R   R.   (   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   _getDataþ   s    (   R   R   R   Rj   Rk   R   Rf   (    (   R\   RG   (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRh   õ   s   	(   R1   t   getETreeModuleR   R   RH   RG   t   namespaceHTMLElementsRS   RX   Rh   t   elementClasst   commentClassR   RP   R   (   R   Rm   RQ   RX   Rh   (    (   RR   RG   R\   sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyR   ¾   s    	%"	c         C` s2   t  i i |  ƒ |  i |  _ g  |  _ d  |  _ d  S(   N(   R   RP   t   resett   insertCommentInitialt   insertCommentt   initial_commentsR   RL   (   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRp     s    	c         C` s
   t  | ƒ S(   N(   RK   (   R   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRK     s    c         C` s&   t  o |  i i S|  i i i ƒ  Sd  S(   N(   RQ   t   documentR   R   (   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   getDocument  s    c         C` si   g  } |  i  d i } | i o | i | i ƒ n | i t | ƒ ƒ | i o | i | i ƒ n | S(   Ni    (   t   openElementsR   R.   R   t   extendt   listR/   (   R   t   fragmentR   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   getFragment  s    

c         C` s—   | d } | d } | d } | p t  i d t ƒ d  |  _ nR |  i i | ƒ } | | j o t  i d t ƒ n |  i | | | ƒ } | |  _ d  S(   Nu   nameu   publicIdu   systemIdu#   lxml cannot represent empty doctypeu%   lxml cannot represent non-xml doctype(   t   warningst   warnR   R   RL   RG   RZ   t   doctypeClass(   R   t   tokenR	   R
   R   t   coercedNameRL   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   insertDoctype!  s    


c         C` s   |  i  i | ƒ d  S(   N(   Rs   R   (   R   Rf   t   parent(    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRq   1  s    c         C` sa   | |  i  j o4 |  i  i i ƒ  d i t j o t i d t ƒ n t t	 |  ƒ i
 | | ƒ d  S(   Niÿÿÿÿu@   lxml cannot represent adjacent comments beyond the root elements(   Rt   R   R   R,   R-   R{   R|   R   t   superRP   Rr   (   R   Rf   R   (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   insertCommentMain4  s     c   
      C` sv  d } |  i  oa|  i  i p t ‚ | d |  i  i 7} |  i  i d j	 p |  i  i d j	 oÚ | d |  i i |  i  i p d ƒ 7} |  i  i o˜ |  i  i } | i d ƒ d j o< | i d ƒ d j o& t	 i
 d t ƒ | i d d ƒ } n | i d ƒ d j o | d	 | 7} q4| d
 | 7} q8| d 7} n | d 7} |  i  i | d j o t	 i
 d t ƒ qqn | d 7} t i | ƒ } x+ |  i D]  } | i t i | d ƒ ƒ q”W|  i ƒ  |  _ | i ƒ  |  i _ | d } | i d |  i ƒ } | d j o
 | } n d | | f } | | _ |  i | | ƒ }	 | |	 _ |  i i i |	 ƒ |  i i |	 ƒ |  i |  _ 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   RG   t   coercePubidt   findR{   R|   R   t   replaceR   t
   fromstringRs   t   addpreviousRh   t   documentClassRt   t   getroottreeR   t   gett   defaultNamespaceR,   Rn   R   R   R   Rv   Rƒ   Rr   (
   R   R~   t   docStrt   sysidt   roott   comment_tokenR	   RY   t	   etree_tagt   root_element(    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt
   insertRoot:  sL    
!,


 

		N(   R   R   R   R‰   R   R}   R   Rn   Ro   t   fragmentClassR   t   implementationt   FalseR   Rp   RK   Ru   Rz   R€   Rq   Rƒ   R“   (    (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyRP   ¶   s   J				
	(   t   __doc__t
   __future__R    R   R   R{   t   reR(   t    R   R   R   R   R1   R   t
   lxml.etreet   TrueRQ   t   compileR2   Rh   R,   R-   t   objectR   R   RK   RO   RP   (    (    (    sg   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/html5lib/treebuilders/etree_lxml.pyt   <module>
   s$   	S	-