ó
ÕöePc           @   s  d  Z  d d d g Z d d l m Z m Z d d l m Z m Z m Z m Z m	 Z	 d d d „ Z d d d „ Z d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z y d d l m Z Wn! e k
 rØ d d l m Z n Xd d l Z e j d ƒ j Z d „  Z d S(   s5   External interface to the BeautifulSoup HTML parser.
t
   fromstringt   parset   convert_treeiÿÿÿÿ(   t   etreet   html(   t   BeautifulSoupt   Tagt   Commentt   ProcessingInstructiont   NavigableStringc         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(    (    s8   /usr/lib/python2.7/dist-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(    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR      s    	c         C   sX   | d k r t j j } n  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.
    N(   t   NoneR   t   html_parserR   t   _convert_treet   getchildrent   remove(   t   beautiful_soup_treeR   R   t   childrent   child(    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR   '   s    	c         K   s¡   | d  k r t } n  | d  k r0 t j j } n  d | k rI d | d <n  | |  |  } t | | ƒ } t | ƒ d k r” | d j d k r” | d Sd | _ | S(   Nt   convertEntitiesR   i   i    (   R   R   R   R   R   R   t   lent   tag(   t   sourceR   R   R   t   treeR   (    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR
   ;   s    	%	c         C   s2   | |  j  d t |  j ƒ ƒ} t | |  | ƒ | S(   Nt   attrib(   t   namet   dictt   attrst   _convert_children(   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR   J   s    c         C   s)  t  j } d  } x| D]} t | t ƒ r„ | |  | j d t g  | j D] \ } } | t | ƒ f ^ qG ƒ ƒ} t	 | | | ƒ q t
 | ƒ t k r¯ t |  | t | ƒ ƒ q t | t ƒ r× |  j t  j | ƒ ƒ q t | t ƒ r|  j t  j | j d d ƒ Œ  ƒ q t |  | t | ƒ ƒ q Wd  S(   NR"   t    i   (   R   t
   SubElementR   t
   isinstanceR   R#   R$   R%   t   unescapeR&   t   typeR	   t   _append_textR   t   appendR   t   split(   t   parentR   R   R(   t   et_childR   t   kt   v(    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR&   P   s    	4c         C   s?   | d  k r% |  j p d | |  _ n | j p1 d | | _ d  S(   Nt    (   R   t   textt   tail(   R/   t   elementR4   (    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR,   c   s    (   t   name2codepointNs   &(\w+);c         C   s    |  s
 d Sd „  } t  | |  ƒ S(   NR3   c         S   s=   y t  t |  j d ƒ ƒ SWn t k
 r8 |  j d ƒ SXd  S(   Ni   i    (   t   unichrR7   t   groupt   KeyError(   t   m(    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyt   unescape_entityx   s    (   t   handle_entities(   t   stringR<   (    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyR*   t   s    	(   t   __doc__t   __all__t   lxmlR   R   R   R   R   R   R	   R   R    R   R   R
   R   R&   R,   t   html.entitiesR7   t   ImportErrort   htmlentitydefst   ret   compilet   subR=   R*   (    (    (    s8   /usr/lib/python2.7/dist-packages/lxml/html/soupparser.pyt   <module>   s"   (					