ó
­V]c           @   s‚  d  Z  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 e f d „  ƒ  YZ d d l m Z e e ƒ y d d l m Z e e ƒ Wn e k
 rKn Xy d d l m Z e e ƒ Wn e k
 r}n Xd S(   t   MITiÿÿÿÿ(   t   defaultdictN(   t   CharsetMetaAttributeValuet   ContentMetaAttributeValuet   nonwhitespace_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(    (    s3   lib/python2.7/site-packages/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(    (    s3   lib/python2.7/site-packages/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(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   lookup)   s.    
(   t   __name__t
   __module__R   R   R$   (    (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR      s   		c           B   s§   e  Z d  Z d Z g  Z g  Z e Z e Z d Z
 i  Z e ƒ  Z e ƒ  Z e e d „ 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.s   [Unknown tree builder]c         C   sU   d |  _ | |  j k r$ |  j } n  | |  _ | |  j k rH |  j } n  | |  _ d S(   s  Constructor.

        :param multi_valued_attributes: If this is set to None, the
        TreeBuilder will not turn any values for attributes like
        'class' into lists. Setting this do a dictionary will
        customize this behavior; look at DEFAULT_CDATA_LIST_ATTRIBUTES
        for an example.

        Internally, these are called "CDATA list attributes", but that
        probably doesn't make sense to an end-user, so the argument name
        is `multi_valued_attributes`.

        :param preserve_whitespace_tags:
        N(   R   t   soupt   USE_DEFAULTt   DEFAULT_CDATA_LIST_ATTRIBUTESt   cdata_list_attributest    DEFAULT_PRESERVE_WHITESPACE_TAGSt   preserve_whitespace_tags(   R   t   multi_valued_attributesR,   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR   g   s    		c         C   s   | |  _  d S(   sp   The BeautifulSoup object has been initialized and is now
        being associated with the TreeBuilder.
        N(   R'   (   R   R'   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   initialize_soup~   s    c         C   s   d  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   reset„   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(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   can_be_empty_element‡   s    c         C   s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R   t   markup(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   feedœ   s    c         C   s   | d  d  t f S(   N(   R   t   False(   R   R5   t   user_specified_encodingt   document_declared_encoding(    (    s3   lib/python2.7/site-packages/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(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   test_fragment_to_document£   s    c         C   s   t  S(   N(   R7   (   R   t   tag(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   set_up_substitutions°   s    c         C   s½   | s
 | S|  j  r¹ |  j  j d g  ƒ } |  j  j | j ƒ  d ƒ } xs | j ƒ  D]b } | | k st | rP | | k rP | | } t | t ƒ rŸ t j | ƒ } n | } | | | <qP qP Wn  | S(   sa   Replaces class="foo bar" with class=["foo", "bar"]

        Modifies its input in place.
        t   *N(	   R*   R   t   lowerR   t   keyst
   isinstancet
   basestringR   t   findall(   R   R2   t   attrst	   universalt   tag_specifict   attrt   valuet   values(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt$   _replace_cdata_list_attribute_values³   s    		
N(   R%   R&   t   __doc__t   NAMEt   ALTERNATE_NAMESR   R7   t   is_xmlt	   picklableR   R0   R)   R   R+   t   objectR(   R   R.   R/   R3   R6   R:   R<   R>   RK   (    (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR   S   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(   R4   (   R   R5   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR6   Ô   s    c         C   s   d  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/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   keyRI   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pys	   <genexpr>Û   s    (   t   dictR   t   itemsR'   t   handle_starttag(   R   t   nameRE   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   startElementÚ   s    "c         C   s   |  j  j | ƒ d  S(   N(   R'   t   handle_endtag(   R   RX   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt
   endElementß   s    c         C   s   |  j  | | ƒ d  S(   N(   RY   (   R   t   nsTuplet   nodeNameRE   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   startElementNSã   s    c         C   s   |  j  | ƒ d  S(   N(   R[   (   R   R\   R]   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   endElementNSç   s    c         C   s   d  S(   N(    (   R   t   prefixt	   nodeValue(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   startPrefixMappingì   s    c         C   s   d  S(   N(    (   R   R`   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   endPrefixMappingð   s    c         C   s   |  j  j | ƒ d  S(   N(   R'   t   handle_data(   R   t   content(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt
   charactersõ   s    c         C   s   d  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   startDocumentø   s    c         C   s   d  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   endDocumentû   s    (   R%   R&   RL   R6   RR   RY   R[   R^   R_   Rb   Rc   Rf   Rg   Rh   (    (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR   Ñ   s   										c        $   B   s|  e  Z d  Z e d d d d d d d d d	 d
 d d d d d d d d d d d d d d g ƒ Z e d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: g# ƒ Z i d; d< d= g d> 6d? d@ g dA 6d? d@ g d
 6dB g dC 6dB g dD 6dB g dC 6dE g d& 6dF g dG 6d? g d 6dH g dI 6dJ g dK 6dL g d3 6Z e d5 dM g ƒ Z dN „  Z RS(O   s]   This TreeBuilder knows facts about HTML.

    Such as which tags are empty-element tags.
    t   areat   baset   brt   colt   embedt   hrt   imgt   inputt   keygent   linkt   menuitemt   metat   paramt   sourcet   trackt   wbrt   basefontt   bgsoundt   commandt   framet   imaget   isindext   nextidt   spacert   addresst   articlet   asidet
   blockquotet   canvast   ddt   divt   dlt   dtt   fieldsett
   figcaptiont   figuret   footert   formt   h1t   h2t   h3t   h4t   h5t   h6t   headert   lit   maint   navt   noscriptt   olt   outputt   pt   pret   sectiont   tablet   tfoott   ult   videot   classt	   accesskeyt   dropzoneR?   t   relt   revt   at   headerst   tdt   ths   accept-charsett   archiveRQ   t   sizest   icont   sandboxt   iframet   fort   textareac         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(   NRt   s
   http-equivRe   t   charsets   content-type(   RX   R7   R   R   R   R@   R   (   R   R=   t
   http_equivRe   R³   t   meta_encoding(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR>   -  s    (	   R%   R&   RL   R   R0   t   block_elementsR)   R+   R>   (    (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyR   ÿ   s(   0!u	







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_moduleRX   t   obj(    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   register_treebuilders_fromN  s    t   ParserRejectedMarkupc           B   s   e  Z RS(    (   R%   R&   (    (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyRÃ   [  s   i   (   t   _htmlparser(   t	   _html5lib(   t   _lxml(   t   __license__t   collectionsR   t	   itertoolsR·   t   bs4.elementR   R   R   R¹   t   FASTt
   PERMISSIVEt   STRICTt   XMLt   HTMLt   HTML_5RQ   R   R¾   R   R   R   RÂ   t	   ExceptionRÃ   t    RÄ   RÅ   t   ImportErrorRÆ   (    (    (    s3   lib/python2.7/site-packages/bs4/builder/__init__.pyt   <module>   sB   	4	~.O	
