
uXQc           @   sf  d  d l  m Z d  d l Z d  d l Z d  d l m Z m Z m Z d d d d g Z d Z	 d	 Z
 d
 Z d Z d Z d Z d e f d     YZ e   Z d e f d     YZ d e f d     YZ d e f d     YZ d   Z d d l m Z e e  y d d l m Z e e  Wn e k
 r/n Xy d d l m Z e e  Wn e k
 ran Xd S(   i(   t   defaultdictN(   t   CharsetMetaAttributeValuet   ContentMetaAttributeValuet   whitespace_ret   HTMLTreeBuildert   SAXTreeBuildert   TreeBuildert   TreeBuilderRegistryt   fastt
   permissivet   strictt   xmlt   htmlt   html5c           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  t  |  _ g  |  _ d  S(   N(   R    t   listt   builders_for_featuret   builders(   t   self(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   __init__   s    c         C   sB   x( | j  D] } |  j | j d |  q
 W|  j j d |  d S(   s8   Register a treebuilder based on its advertised features.i    N(   t   featuresR   t   insertR   (   R   t   treebuilder_classt   feature(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   register    s    c         G   s  t  |  j  d k r d  St  |  d k r6 |  j d St |  } | j   d  } d  } x t  |  d k r | j   } |  j j | g   } t  |  d k r[ | d  k r | } t |  } q | j	 t |   } q[ q[ W| d  k r d  Sx | D] } | | k r | Sq Wd  S(   Ni    (
   t   lenR   t   NoneR   t   reverset   popR   t   gett   sett   intersection(   R   R   t
   candidatest   candidate_setR   t   we_have_the_featuret	   candidate(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   lookup&   s.    
(   t   __name__t
   __module__R   R   R#   (    (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR      s   		c           B   s}   e  Z d  Z g  Z e Z e   Z d	 Z	 i  Z
 d   Z d   Z d   Z d   Z d	 d	 d  Z d   Z d   Z d   Z RS(
   s2   Turn a document into a Beautiful Soup object tree.c         C   s   d  |  _ d  S(   N(   R   t   soup(   R   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR   _   s    c         C   s   d  S(   N(    (   R   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   resetb   s    c         C   s    |  j  d k r t S| |  j  k S(   s  Might a tag with this name be an empty-element tag?

        The final markup may or may not actually present this tag as
        self-closing.

        For instance: an HTMLBuilder does not consider a <p> tag to be
        an empty-element tag (it's not in
        HTMLBuilder.empty_element_tags). This means an empty <p> tag
        will be presented as "<p></p>", not "<p />".

        The default implementation has no opinion about which tags are
        empty-element tags, so a tag will be presented as an
        empty-element tag if and only if it has no contents.
        "<foo></foo>" will become "<foo />", and "<foo>bar</foo>" will
        be left alone.
        N(   t   empty_element_tagsR   t   True(   R   t   tag_name(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   can_be_empty_elemente   s    c         C   s   t     d  S(   N(   t   NotImplementedError(   R   t   markup(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   feedz   s    c         C   s   | d  d  t f S(   N(   R   t   False(   R   R-   t   user_specified_encodingt   document_declared_encoding(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   prepare_markup}   s    c         C   s   | S(   s  Wrap an HTML fragment to make it look like a document.

        Different parsers do this differently. For instance, lxml
        introduces an empty <head> tag, and html5lib
        doesn't. Abstracting this away lets us write simple tests
        which run HTML fragments through the parser and compare the
        results against other HTML fragments.

        This method should not be used outside of tests.
        (    (   R   t   fragment(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   test_fragment_to_document   s    c         C   s   t  S(   N(   R/   (   R   t   tag(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   set_up_substitutions   s    c         C   s   |  j  r |  j  j d g   } |  j  j | j   g   } xm t j | |  D]V } | t |  k rL | | } t | t  r t j	 |  } n | } | | | <qL qL Wn  | S(   sa   Replaces class="foo bar" with class=["foo", "bar"]

        Modifies its input in place.
        t   *(
   t   cdata_list_attributesR   t   lowert	   itertoolst   chaint   dictt
   isinstancet
   basestringR   t   split(   R   R*   t   attrst	   universalt   tag_specifict   cdata_list_attrt   valuet   values(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt$   _replace_cdata_list_attribute_values   s    		
N(   R$   R%   t   __doc__R   R/   t   is_xmlR   t   preserve_whitespace_tagsR   R(   R8   R   R'   R+   R.   R2   R4   R6   RF   (    (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR   P   s   							c           B   sq   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z RS(   s9   A Beautiful Soup treebuilder that listens for SAX events.c         C   s   t     d  S(   N(   R,   (   R   R-   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR.      s    c         C   s   d  S(   N(    (   R   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   close   s    c         C   s9   t  d   t | j    D  } |  j j | |  d  S(   Nc         s   s%   |  ] \ } } | d  | f Vq d S(   i   N(    (   t   .0t   keyRD   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pys	   <genexpr>   s    (   R<   R   t   itemsR&   t   handle_starttag(   R   t   nameR@   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   startElement   s    "c         C   s   |  j  j |  d  S(   N(   R&   t   handle_endtag(   R   RO   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt
   endElement   s    c         C   s   |  j  | |  d  S(   N(   RP   (   R   t   nsTuplet   nodeNameR@   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   startElementNS   s    c         C   s   |  j  |  d  S(   N(   RR   (   R   RS   RT   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   endElementNS   s    c         C   s   d  S(   N(    (   R   t   prefixt	   nodeValue(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   startPrefixMapping   s    c         C   s   d  S(   N(    (   R   RW   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   endPrefixMapping   s    c         C   s   |  j  j |  d  S(   N(   R&   t   handle_data(   R   t   content(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt
   characters   s    c         C   s   d  S(   N(    (   R   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   startDocument   s    c         C   s   d  S(   N(    (   R   (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   endDocument   s    (   R$   R%   RG   R.   RJ   RP   RR   RU   RV   RY   RZ   R]   R^   R_   (    (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR      s   										c        
   B   s   e  Z d  Z e d d g  Z e d d d d d d d	 d
 d g	  Z i d d d g d 6d d g d 6d d g d	 6d g d 6d g d 6d g d 6d g d 6d g d 6d g d 6d g d 6d g d 6d g d  6Z d!   Z RS("   s]   This TreeBuilder knows facts about HTML.

    Such as which tags are empty-element tags.
    t   pret   textareat   brt   hrt   inputt   imgt   metat   spacert   linkt   framet   baset   classt	   accesskeyt   dropzoneR7   t   relt   revt   at   headerst   tdt   ths   accept-charsett   formt   archivet   objectt   areat   sizest   icont   sandboxt   iframet   fort   outputc         C   s   | j  d k r t S| j d  } | j d  } | j d  } d  } | d  k	 rk | } t |  | d <n= | d  k	 r | d  k	 r | j   d k r t |  | d <n  | d  k	 S(   NRf   s
   http-equivR\   t   charsets   content-type(   RO   R/   R   R   R   R9   R   (   R   R5   t
   http_equivR\   R~   t   meta_encoding(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR6      s    (   R$   R%   RG   R   RI   R(   R8   R6   (    (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyR      s$   	







c         C   sv   t  j d } xb |  j D]W } t |  |  } t | t  r t | | |  | j j |  | j j	 |  q q Wd S(   s9   Copy TreeBuilders from the given module into this module.s   bs4.builderN(
   t   syst   modulest   __all__t   getattrt
   issubclassR   t   setattrt   appendt   builder_registryR   (   t   modulet   this_moduleRO   t   obj(    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   register_treebuilders_from  s    i   (   t   _htmlparser(   t	   _html5lib(   t   _lxml(   t   collectionsR    R:   R   t   bs4.elementR   R   R   R   t   FASTt
   PERMISSIVEt   STRICTt   XMLt   HTMLt   HTML_5Rv   R   R   R   R   R   R   t    R   R   t   ImportErrorR   (    (    (    s9   /scratch/rashmi/Condor_Script/src/bs4/builder/__init__.pyt   <module>   s>   	4	].C	
