ó
n€
\c           @   s¬  d  Z  d d d g Z d d l Z d d l m Z m Z yD d d l m Z m Z m	 Z	 m
 Z
 m Z m Z m Z e e f Z WnE e k
 rÂ d d l m Z m Z m	 Z	 m
 Z
 m Z m Z e Z n Xd d d	 „ Z d d d
 „ Z d d „ Z d „  Z e j d e j ƒ j Z d d d „  ƒ  YZ d „  Z d „  Z y d d l m Z Wn! e k
 rjd d l m Z n Xe j d ƒ j Z  y e! Wn e" k
 rže# Z! n Xd „  Z$ d S(   s5   External interface to the BeautifulSoup HTML parser.
t
   fromstringt   parset   convert_treeiÿÿÿÿN(   t   etreet   html(   t   BeautifulSoupt   Tagt   Commentt   ProcessingInstructiont   NavigableStringt   Declarationt   Doctype(   R   R   R   R   R	   R
   c         K   s   t  |  | | |  S(   s¤  Parse a string of HTML data into an Element tree using the
    BeautifulSoup parser.

    Returns the root ``<html>`` Element of the tree.

    You can pass a different BeautifulSoup parser through the
    `beautifulsoup` keyword, and a diffent Element factory function
    through the `makeelement` keyword.  By default, the standard
    ``BeautifulSoup`` class and the default factory of `lxml.html` are
    used.
    (   t   _parse(   t   datat   beautifulsoupt   makeelementt   bsargs(    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR       s    c         K   s@   t  |  d ƒ s t |  ƒ }  n  t |  | | |  } t j | ƒ S(   sY  Parse a file into an ElemenTree using the BeautifulSoup parser.

    You can pass a different BeautifulSoup parser through the
    `beautifulsoup` keyword, and a diffent Element factory function
    through the `makeelement` keyword.  By default, the standard
    ``BeautifulSoup`` class and the default factory of `lxml.html` are
    used.
    t   read(   t   hasattrt   openR   R   t   ElementTree(   t   fileR   R   R   t   root(    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR   $   s    	c         C   s=   t  |  | ƒ } | j ƒ  } x | D] } | j | ƒ q" W| S(   s  Convert a BeautifulSoup tree to a list of Element trees.

    Returns a list instead of a single root Element to support
    HTML-like soup with more than one root element.

    You can pass a different Element factory through the `makeelement`
    keyword.
    (   t   _convert_treet   getchildrent   remove(   t   beautiful_soup_treeR   R   t   childrent   child(    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR   3   s
    	c         K   sÃ   | d  k r t } n  t | d ƒ r@ d | k r@ d | d <q@ n  t | d ƒ rk d | k rk d | d <qk n  | |  |  } t | | ƒ } t | ƒ d k r¶ | d j d k r¶ | d Sd | _ | S(	   Nt   HTML_ENTITIESt   convertEntitiesR   t   DEFAULT_BUILDER_FEATURESt   featuress   html.parseri   i    (   t   NoneR   R   R   t   lent   tag(   t   sourceR   R   R   t   treeR   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR   E   s    	%	s`   (?:\s|[<!])*DOCTYPE\s*HTML(?:\s+PUBLIC)?(?:\s+(\'[^\']*\'|"[^"]*"))?(?:\s+(\'[^\']*\'|"[^"]*"))?t
   _PseudoTagc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   d |  _  g  |  _ | |  _ d  S(   NR   (   t   namet   attrst   contents(   t   selfR)   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   __init__`   s    		c         C   s   |  j  j ƒ  S(   N(   R)   t   __iter__(   R*   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR,   e   s    (   t   __name__t
   __module__R+   R,   (    (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR&   ^   s   	c         C   s¸  | d  k r t j j } n  d  } } d  } } xž t |  ƒ D] \ } } t | t ƒ r¨ | d  k rl | } n  | } | d  k rÌ | j rÌ | j j ƒ  d k rÌ | } qÌ q< | d  k r< t | t	 ƒ r< | } q< q< W| d  k rò g  } }	 |  j
 }
 n2 |  j
 |  } |  j
 | | d !}
 |  j
 | d }	 | d  k	 rb|
 j | ƒ } |
 |  | j
 |
 | d | _
 n t |
 ƒ } t | ƒ } | | ƒ } | } xB t | ƒ D]4 } | | ƒ } | d  k	 r™| j | ƒ | } q™q™W| } x< |	 D]4 } | | ƒ } | d  k	 rÞ| j | ƒ | } qÞqÞW| d  k	 r´y | j ƒ  } Wn t k
 rN| j } n Xt | ƒ } | sdq´| j ƒ  \ } } | j ƒ  j } | o•| d d !| _ | o«| d d !| _ n  | S(   NR   i   iÿÿÿÿ(   R!   R   t   html_parserR   t	   enumeratet
   isinstanceR   R'   t   lowert   _DECLARATION_OR_DOCTYPER)   t   indexR&   t   _init_node_converterst   reversedt   addprevioust   addnextt   output_readyt   AttributeErrort   stringt   _parse_doctype_declarationt   groupst   getroottreet   docinfot	   public_idt
   system_url(   R   R   t   first_element_idxt   last_element_idxt	   html_roott   declarationt   it   et   pre_roott	   post_roott   rootst   convert_nodet   res_roott   prevt	   convertedt   doctype_stringt   matcht   external_idt   sys_uriR?   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR   i   sd    

	*
#c            sÇ   i  ‰ g  ‰ ‡ ‡ f d †  } ‡ ‡ f d †  ‰ d  ‡ ‡ f d † ‰ d „  ‰ d „  ‰ | t t ƒ ‡  ‡ ‡ ‡ f d †  ƒ } | t ƒ d „  ƒ } | t ƒ d „  ƒ } | t ƒ ‡ f d	 †  ƒ } ˆ S(
   Nc             s   ‡ ‡  ‡ f d †  } | S(   Nc            s,   x% ˆ D] } |  ˆ | <ˆ  j  | ƒ q W|  S(   N(   t   append(   t   handlert   t(   t   ordered_node_typest   typest
   converters(    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   addÃ   s    
(    (   RW   RY   (   RV   RX   (   RW   sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt	   converterÂ   s    c            s,   x% ˆ  D] } t  |  | ƒ r ˆ | Sq Wd  S(   N(   R1   R!   (   t   nodeRU   (   RV   RX   (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   find_best_converterÊ   s    c            s_   y ˆ t  |  ƒ } Wn+ t k
 rA ˆ  |  ƒ } ˆ t  |  ƒ <n X| d  k rR d  S| |  | ƒ S(   N(   t   typet   KeyErrorR!   (   t   bs_nodet   parentRT   (   R\   RX   (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyRK   Ð   s    c         S   s€   t  |  t ƒ rf i  } xd |  j ƒ  D]= \ } } t  | t ƒ rO d j | ƒ } n  t | ƒ | | <q" Wn t d „  |  Dƒ ƒ } | S(   Nt    c         s   s'   |  ] \ } } | t  | ƒ f Vq d  S(   N(   t   unescape(   t   .0t   kt   v(    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pys	   <genexpr>â   s    (   R1   t   dictt   itemst   listt   joinRb   (   t   bs_attrst   attribsRd   Re   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt	   map_attrsÚ   s    c         S   sM   t  |  ƒ d k r+ |  j p d | |  _ n |  d j p; d | |  d _ d  S(   Ni    t    iÿÿÿÿ(   R"   t   textt   tail(   R`   Rn   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   append_textå   s    c            sá   |  j  } | d  k	 rK | r' ˆ | ƒ n d  } t j | |  j d | ƒ} n- | r] ˆ | ƒ n i  } ˆ  |  j d | ƒ} xb |  D]Z } y ˆ t | ƒ } Wn t k
 r¬ n  X| d  k	 r | | | ƒ q q ˆ | | ƒ q W| S(   Nt   attrib(   R(   R!   R   t
   SubElementR'   R]   R^   (   R_   R`   R(   Rk   t   resR   RT   (   R   RK   RX   Rl   (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   convert_tagí   s     	c         S   s/   t  j |  ƒ } | d  k	 r+ | j | ƒ n  | S(   N(   R   t   HtmlCommentR!   RS   (   R_   R`   Rs   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   convert_comment  s    c         S   sW   |  j  d ƒ r |  d  }  n  t j |  j d d ƒ Œ  } | d  k	 rS | j | ƒ n  | S(   Nt   ?iÿÿÿÿRa   i   (   t   endswithR   R   t   splitR!   RS   (   R_   R`   Rs   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt
   convert_pi  s    c            s&   | d  k	 r" ˆ  | t |  ƒ ƒ n  d  S(   N(   R!   Rb   (   R_   R`   (   Rp   (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   convert_text  s    (   R!   R   R&   R   R   R	   (   R   RZ   Rt   Rv   Rz   R{   (    (   R   Rp   RK   RV   R\   RX   Rl   sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyR5   ¾   s    
		'(   t   name2codepoints   &(\w+);c         C   s    |  s
 d Sd „  } t  | |  ƒ S(   NRm   c         S   s=   y t  t |  j d ƒ ƒ SWn t k
 r8 |  j d ƒ SXd  S(   Ni   i    (   t   unichrR|   t   groupR^   (   t   m(    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   unescape_entity5  s    (   t   handle_entities(   R;   R€   (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyRb   1  s    	(    (%   t   __doc__t   __all__t   ret   lxmlR   R   t   bs4R   R   R   R   R	   R
   R   R3   t   ImportErrorR!   R    R   R   R   t   compilet
   IGNORECASERP   R<   R&   R   R5   t   html.entitiesR|   t   htmlentitydefst   subR   R}   t	   NameErrort   chrRb   (    (    (    sI   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/soupparser.pyt   <module>   s:   4.
		U	c
