
V]c           @   s`  d  Z  y d d l m Z Wn# e k
 r? Z d d l m Z n Xd d l Z d d l Z d d l Z y d d l	 Z	 Wn& e k
 r Z e
 Z	 e j d  n Xd d l m Z m Z m Z d Z e j d d k Z e j d	  Z e j d
  Z d   Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e e f d     YZ d e f d     YZ d e f d     YZ  d e f d     YZ! d e! f d     YZ" d  e f d!     YZ# d" e f d#     YZ$ d$ e f d%     YZ% d& e f d'     YZ& d( e f d)     YZ' d* e( f d+     YZ) d S(,   t   MITi(   t   CallableNsE   The soupsieve package is not installed. CSS selectors cannot be used.(   t	   Formattert   HTMLFormattert   XMLFormatters   utf-8i    i   s   \S+s   \s+c            s1   t    f d    } | j   f d    } | S(   s>   Alias one attribute name to another for backward compatibilityc            s   t  |     S(   N(   t   getattr(   t   self(   t   attr(    s*   lib/python2.7/site-packages/bs4/element.pyt   alias$   s    c            s   t  |     S(   N(   t   setattr(   R   (   R   (    s*   lib/python2.7/site-packages/bs4/element.pyR   (   s    (   t   propertyt   setter(   R   R   (    (   R   s*   lib/python2.7/site-packages/bs4/element.pyt   _alias"   s    t   NamespacedAttributec           B   s   e  Z d d   Z RS(   c         C   s{   | d  k r! t j |  |  } n; | d  k rB t j |  |  } n t j |  | d |  } | | _ | | _ | | _ | S(   Nt   :(   t   Nonet   unicodet   __new__t   prefixt   namet	   namespace(   t   clsR   R   R   t   obj(    (    s*   lib/python2.7/site-packages/bs4/element.pyR   0   s    			N(   t   __name__t
   __module__R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   .   s   t%   AttributeValueWithCharsetSubstitutionc           B   s   e  Z d  Z RS(   s=   A stand-in object for a character encoding specified in HTML.(   R   R   t   __doc__(    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   =   s   t   CharsetMetaAttributeValuec           B   s    e  Z d  Z d   Z d   Z RS(   s   A generic stand-in for the value of a meta tag's 'charset' attribute.

    When Beautiful Soup parses the markup '<meta charset="utf8">', the
    value of the 'charset' attribute will be one of these objects.
    c         C   s   t  j |  |  } | | _ | S(   N(   R   R   t   original_value(   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   G   s    	c         C   s   | S(   N(    (   R   t   encoding(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   encodeL   s    (   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   @   s   	t   ContentMetaAttributeValuec           B   s5   e  Z d  Z e j d e j  Z d   Z d   Z RS(   s  A generic stand-in for the value of a meta tag's 'content' attribute.

    When Beautiful Soup parses the markup:
     <meta http-equiv="content-type" content="text/html; charset=utf8">

    The value of the 'content' attribute will be one of these objects.
    s   ((^|;)\s*charset=)([^;]*)c         C   sM   |  j  j |  } | d  k r. t j t |  St j |  |  } | | _ | S(   N(   t
   CHARSET_REt   searchR   R   R   R   (   R   R   t   matchR   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   [   s    	c            s%     f d   } |  j  j | |  j  S(   Nc            s   |  j  d    S(   Ni   (   t   group(   R"   (   R   (    s*   lib/python2.7/site-packages/bs4/element.pyt   rewritef   s    (   R    t   subR   (   R   R   R$   (    (   R   s*   lib/python2.7/site-packages/bs4/element.pyR   e   s    (	   R   R   R   t   ret   compilet   MR    R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   P   s   	
t   PageElementc           B   s  e  Z d  Z d) d) d) d) d) d  Z d   Z d   Z e d    Z e	 d  Z
 e	 d  Z d   Z e Z d   Z e Z e Z d	   Z d
   Z e e d  Z e Z d   Z d   Z d   Z d   Z d   Z d) i  d) d  Z e Z d) i  d) d) d  Z e Z d) i  d) d  Z e Z  d) i  d) d) d  Z! e! Z" e! Z# d) i  d) d  Z$ e$ Z% d) i  d) d) d  Z& e& Z' e& Z( d) i  d) d  Z) e) Z* d) i  d) d) d  Z+ e+ Z, e+ Z- d) i  d  Z. e. Z/ d) i  d) d  Z0 e0 Z1 e0 Z2 e d    Z3 e d    Z4 d   Z5 d   Z6 e d    Z7 e d     Z8 e d!    Z9 e d"    Z: e d#    Z; d$   Z< d%   Z= d&   Z> d'   Z? d(   Z@ RS(*   se   Contains the navigational information for some part of the page
    (either a tag or a piece of text)c         C   s   | |  _  | |  _ | d k	 r- |  |  j _ n  | |  _ |  j d k	 rT |  |  j _ n  | |  _ |  j d k	 r{ |  |  j _ n  | d k r |  j  d k	 r |  j  j r |  j  j d } n  | |  _ | d k	 r |  |  j _ n  d S(   sN   Sets up the initial relations between this element and
        other elements.iN(   t   parentt   previous_elementR   t   next_elementt   next_siblingt   previous_siblingt   contents(   R   R*   R+   R,   R.   R-   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   setupo   s     					c         C   sD   | d k r | St | t  s1 |  j |  } n  | j |  } | S(   s2   Format the given string using the given formatter.N(   R   t
   isinstanceR   t   formatter_for_namet
   substitute(   R   t   st	   formattert   output(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   format_string   s    c         C   sO   t  | t  r | S|  j r% t } n t } t |  rD | d |  S| j | S(   sd  Look up or create a Formatter for the given identifier,
        if necessary.

        :param formatter: Can be a Formatter object (used as-is), a
        function (used as the entity substitution hook for an
        XMLFormatter or HTMLFormatter), or a string (used to look up
        an XMLFormatter or HTMLFormatter in the appropriate registry.
        t   entity_substitution(   R1   R   t   _is_xmlR   R   t   callablet   REGISTRY(   R   R5   t   c(    (    s*   lib/python2.7/site-packages/bs4/element.pyR2      s    			c         C   s?   |  j  d k	 r |  j  S|  j d k r5 t |  d t  S|  j j S(   s  Is this element part of an XML tree or an HTML tree?

        This is used in formatter_for_name, when deciding whether an
        XMLFormatter or HTMLFormatter is more appropriate. It can be
        inefficient, but it should be called very rarely.
        t   is_xmlN(   t	   known_xmlR   R*   R   t   FalseR9   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR9      s
    R-   R.   c         C   s   |  j  d  k r t d   n  | |  k r. d  S| |  j  k rL t d   n  |  j  } |  j  j |   } |  j   | j | |  |  S(   Ns^   Cannot replace one element with another when the element to be replaced is not part of a tree.s%   Cannot replace a Tag with its parent.(   R*   R   t
   ValueErrort   indext   extractt   insert(   R   t   replace_witht
   old_parentt   my_index(    (    s*   lib/python2.7/site-packages/bs4/element.pyRD      s    	
c         C   sr   |  j  } |  j  d  k r' t d   n  |  j  j |   } |  j   x( t |  j  D] } | j | |  qT W|  S(   NsS   Cannot replace an element with its contents when thatelement is not part of a tree.(   R*   R   R@   RA   RB   t   reversedR/   RC   (   R   t	   my_parentRF   t   child(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   unwrap   s    	
c         C   s    |  j  |  } | j |  | S(   N(   RD   t   append(   R   t   wrap_insidet   me(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   wrap   s    c         C   s,  |  j  d k	 r+ |  j  j |  j  j |   =n  |  j   } | j } |  j d k	 rm |  j | k	 rm | |  j _ n  | d k	 r | |  j k	 r |  j | _ n  d |  _ d | _ d |  _  |  j d k	 r |  j |  j k	 r |  j |  j _ n  |  j d k	 r|  j |  j k	 r|  j |  j _ n  d |  _ |  _ |  S(   s0   Destructively rips this element out of the tree.N(	   R*   R   R/   RA   t   _last_descendantR,   R+   R.   R-   (   R   t
   last_childR,   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRB      s(    				c         C   sv   | r$ |  j  d k	 r$ |  j  j } n2 |  } x) t | t  rU | j rU | j d } q- W| rr | |  k rr d } n  | S(   s8   Finds the last element beneath this object to be parsed.iN(   R-   R   R+   R1   t   TagR/   (   R   t   is_initializedt   accept_selfRP   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRO      s    	c         C   s  | d  k r t d   n  | |  k r6 t d   n  t | t  rd t | t  rd t |  } n  d d l m } t | |  r x1 t | j  D]  } |  j	 | |  | d 7} q Wd  St
 | t |  j   } t | d  r8| j d  k	 r8| j |  k r+|  j |  } | | k  r+| d 8} q+n  | j   n  |  | _ d  } | d k rhd  | _ |  | _ n8 |  j | d } | | _ | | j _ | j t  | _ | j d  k	 r| | j _ n  | j t  } | t |  j  k r\d  | _ |  } d  }	 x> |	 d  k r7| d  k	 r7| j }	 | j } |	 d  k	 rPqqW|	 d  k	 rP|	 | _ qd  | _ n= |  j | }
 |
 | _ | j d  k	 r| | j _ n  |
 | _ | j d  k	 r| | j _ n  |  j j	 | |  d  S(   Ns   Cannot insert None into a tag.s    Cannot insert a tag into itself.i(   t   BeautifulSoupi   R*   i    (   R   R@   R1   t
   basestringt   NavigableStringt   bs4RT   t   listR/   RC   t   mint   lent   hasattrR*   RA   RB   R.   R+   R-   RO   R?   R,   (   R   t   positiont	   new_childRT   t   subchildt   current_indext   previous_childt   new_childs_last_elementR*   t   parents_next_siblingt
   next_child(    (    s*   lib/python2.7/site-packages/bs4/element.pyRC     sh    								c         C   s   |  j  t |  j  |  d S(   s2   Appends the given tag to the contents of this tag.N(   RC   RZ   R/   (   R   t   tag(    (    s*   lib/python2.7/site-packages/bs4/element.pyRK   W  s    c         C   s"   x | D] } |  j  |  q Wd S(   s3   Appends the given tags to the contents of this tag.N(   RK   (   R   t   tagsRd   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   extend[  s    c            s     j  } | d k r$ t d   n  t   f d   | D  rO t d   n  xI | D]A } t | t  rx | j   n  | j    } | j | |  qV Wd S(   s   Makes the given element(s) the immediate predecessor of this one.

        The elements will have the same parent, and the given elements
        will be immediately before this one.
        s2   Element has no parent, so 'before' has no meaning.c         3   s   |  ] } |   k Vq d  S(   N(    (   t   .0t   x(   R   (    s*   lib/python2.7/site-packages/bs4/element.pys	   <genexpr>j  s    s&   Can't insert an element before itself.N(	   R*   R   R@   t   anyR1   R)   RB   RA   RC   (   R   t   argsR*   t   predecessorRA   (    (   R   s*   lib/python2.7/site-packages/bs4/element.pyt   insert_before`  s    	c            s     j  } | d k r$ t d   n  t   f d   | D  rO t d   n  d } x[ | D]S } t | t  r~ | j   n  | j    } | j | d | |  | d 7} q\ Wd S(   s   Makes the given element(s) the immediate successor of this one.

        The elements will have the same parent, and the given elements
        will be immediately after this one.
        s1   Element has no parent, so 'after' has no meaning.c         3   s   |  ] } |   k Vq d  S(   N(    (   Rg   Rh   (   R   (    s*   lib/python2.7/site-packages/bs4/element.pys	   <genexpr>  s    s%   Can't insert an element after itself.i    i   N(	   R*   R   R@   Ri   R1   R)   RB   RA   RC   (   R   Rj   R*   t   offsett	   successorRA   (    (   R   s*   lib/python2.7/site-packages/bs4/element.pyt   insert_aftert  s    	c         K   s   |  j  |  j | | | |  S(   sj   Returns the first item that matches the given criteria and
        appears after this Tag in the document.(   t	   _find_onet   find_all_next(   R   R   t   attrst   textt   kwargs(    (    s*   lib/python2.7/site-packages/bs4/element.pyt	   find_next  s    c         K   s   |  j  | | | | |  j |  S(   sb   Returns all items that match the given criteria and appear
        after this Tag in the document.(   t	   _find_allt   next_elements(   R   R   Rr   Rs   t   limitRt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRq     s    c         K   s   |  j  |  j | | | |  S(   s{   Returns the closest sibling to this Tag that matches the
        given criteria and appears after this Tag in the document.(   Rp   t   find_next_siblings(   R   R   Rr   Rs   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   find_next_sibling  s    c         K   s   |  j  | | | | |  j |  S(   sq   Returns the siblings of this Tag that match the given
        criteria and appear after this Tag in the document.(   Rv   t   next_siblings(   R   R   Rr   Rs   Rx   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRy     s    c         K   s   |  j  |  j | | | |  S(   sk   Returns the first item that matches the given criteria and
        appears before this Tag in the document.(   Rp   t   find_all_previous(   R   R   Rr   Rs   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   find_previous  s    c         K   s   |  j  | | | | |  j |  S(   sc   Returns all items that match the given criteria and appear
        before this Tag in the document.(   Rv   t   previous_elements(   R   R   Rr   Rs   Rx   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR|     s    c         K   s   |  j  |  j | | | |  S(   s|   Returns the closest sibling to this Tag that matches the
        given criteria and appears before this Tag in the document.(   Rp   t   find_previous_siblings(   R   R   Rr   Rs   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   find_previous_sibling  s    c         K   s   |  j  | | | | |  j |  S(   sr   Returns the siblings of this Tag that match the given
        criteria and appear before this Tag in the document.(   Rv   t   previous_siblings(   R   R   Rr   Rs   Rx   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    c         K   s5   d } |  j | | d |  } | r1 | d } n  | S(   sO   Returns the closest parent of this Tag that matches the given
        criteria.i   i    N(   R   t   find_parents(   R   R   Rr   Rt   t   rt   l(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   find_parent  s
    c         K   s   |  j  | | d | |  j |  S(   sF   Returns the parents of this Tag that match the given
        criteria.N(   Rv   R   t   parents(   R   R   Rr   Rx   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    c         C   s   |  j  S(   N(   R,   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   next  s    c         C   s   |  j  S(   N(   R+   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   previous  s    c         K   s5   d  } | | | | d |  } | r1 | d } n  | S(   Ni   i    (   R   (   R   t   methodR   Rr   Rs   Rt   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRp     s
    c            s  | d k r, d | k r, | d } | d =n  t  t  rD  } n t  | | |  } | d k r&| r&| r&| r& t k s  d k r d   | D } t | |  St  t  r& j d  d k r  j d d  \    n d         f d   | D } t | |  Sn  t |  }	 xy t ry t |  }
 Wn t	 k
 r_Pn X|
 r5| j
 |
  } | r|	 j |  | rt |	  | k rPqqq5q5W|	 S(   s8   Iterates over a generator looking for things that match.t   stringc         s   s$   |  ] } t  | t  r | Vq d  S(   N(   R1   RQ   (   Rg   t   element(    (    s*   lib/python2.7/site-packages/bs4/element.pys	   <genexpr>  s    R   i   c         3   s]   |  ]S } t  | t  r' | j  k sQ | j   k r  d  k sQ | j  k r | Vq d  S(   N(   R1   RQ   R   R   R   (   Rg   R   (   t
   local_nameR   R   (    s*   lib/python2.7/site-packages/bs4/element.pys	   <genexpr>  s
    N(   R   R1   t   SoupStrainert   Truet	   ResultSetRU   t   countt   splitR   t   StopIterationR!   RK   RZ   (   R   R   Rr   Rs   Rx   t	   generatorRt   t   strainert   resultt   resultst   it   found(    (   R   R   R   s*   lib/python2.7/site-packages/bs4/element.pyRv     s<    

	!		c         c   s.   |  j  } x | d  k	 r) | V| j  } q Wd  S(   N(   R,   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRw   &  s    	c         c   s.   |  j  } x | d  k	 r) | V| j  } q Wd  S(   N(   R-   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR{   -  s    	c         c   s.   |  j  } x | d  k	 r) | V| j  } q Wd  S(   N(   R+   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR~   4  s    	c         c   s.   |  j  } x | d  k	 r) | V| j  } q Wd  S(   N(   R.   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   ;  s    	c         c   s.   |  j  } x | d  k	 r) | V| j  } q Wd  S(   N(   R*   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   B  s    	c         C   s   |  j  S(   N(   Rw   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   nextGeneratorK  s    c         C   s   |  j  S(   N(   R{   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   nextSiblingGeneratorN  s    c         C   s   |  j  S(   N(   R~   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   previousGeneratorQ  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   previousSiblingGeneratorT  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   parentGeneratorW  s    N(A   R   R   R   R   R0   R7   R2   R
   R9   R   t   nextSiblingt   previousSiblingRD   t   replaceWithRJ   t   replace_with_childrent   replaceWithChildrenRN   RB   R   RO   t   _lastRecursiveChildRC   RK   Rf   Rl   Ro   Ru   t   findNextRq   t   findAllNextRz   t   findNextSiblingRy   t   findNextSiblingst   fetchNextSiblingsR}   t   findPreviousR|   t   findAllPrevioust   fetchPreviousR   t   findPreviousSiblingR   t   findPreviousSiblingst   fetchPreviousSiblingsR   t
   findParentR   t   findParentst   fetchParentsR   R   Rp   Rv   Rw   R{   R~   R   R   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR)   k   sz   									J					
		6					RV   c           B   sk   e  Z d  Z d  Z d	 Z d   Z d   Z d   Z d   Z	 d d  Z
 e d    Z e j d    Z RS(
   t    c         C   sG   t  | t  r$ t j |  |  } n t j |  | t  } | j   | S(   s-  Create a new NavigableString.

        When unpickling a NavigableString, this method is called with
        the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be
        passed in to the superclass's __new__ or the superclass won't know
        how to handle non-ASCII characters.
        (   R1   R   R   t   DEFAULT_OUTPUT_ENCODINGR0   (   R   t   valuet   u(    (    s*   lib/python2.7/site-packages/bs4/element.pyR   e  s
    
c         C   s   t  |   |   S(   s   A copy of a NavigableString has the same contents and class
        as the original, but it is not connected to the parse tree.
        (   t   type(   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __copy__t  s    c         C   s   t  |   f S(   N(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __getnewargs__z  s    c         C   s0   | d k r |  St  d |  j j | f   d S(   s   text.string gives you text. This is for backwards
        compatibility for Navigable*String, but for CData* it lets you
        get the string without the CData wrapper.R   s!   '%s' object has no attribute '%s'N(   t   AttributeErrort	   __class__R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __getattr__}  s
    t   minimalc         C   s$   |  j  |  |  } |  j | |  j S(   s.   Run the string through the provided formatter.(   R7   t   PREFIXt   SUFFIX(   R   R5   R6   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   output_ready  s    c         C   s   d  S(   N(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    c         C   s   t  d   d  S(   Ns)   A NavigableString cannot be given a name.(   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    N(   R   R   R   R   R   R>   R   R   R   R   R   R
   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyRV   [  s   				t   PreformattedStringc           B   s   e  Z d  Z d d  Z RS(   s   A NavigableString not subject to the normal formatting rules.

    The string will be passed into the formatter (to trigger side effects),
    but the return value will be ignored.
    c         C   s3   | d k	 r! |  j |  |  } n  |  j |  |  j S(   sw   CData strings are passed into the formatter, purely
        for any side effects. The return value is ignored.
        N(   R   R7   R   R   (   R   R5   t   ignore(    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    N(   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   t   CDatac           B   s   e  Z d  Z d Z RS(   u	   <![CDATA[u   ]]>(   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   t   ProcessingInstructionc           B   s   e  Z d  Z d Z d Z RS(   s   A SGML processing instruction.u   <?u   >(   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   t   XMLProcessingInstructionc           B   s   e  Z d  Z d Z d Z RS(   s   An XML processing instruction.u   <?u   ?>(   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   t   Commentc           B   s   e  Z d  Z d Z RS(   u   <!--u   -->(   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   t   Declarationc           B   s   e  Z d  Z d Z RS(   u   <?u   ?>(   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   t   Doctypec           B   s#   e  Z e d     Z d Z d Z RS(   c         C   sm   | p	 d } | d  k	 rF | d | 7} | d  k	 rc | d | 7} qc n | d  k	 rc | d | 7} n  t |  S(   NR   s    PUBLIC "%s"s    "%s"s    SYSTEM "%s"(   R   R   (   R   R   t   pub_idt	   system_idR   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   for_name_and_ids  s    u
   <!DOCTYPE u   >
(   R   R   t   classmethodR   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s   RQ   c        
   B   s  e  Z d  Z d5 d5 d5 d5 d5 d5 d5 d5 d5 d 	 Z e d  Z d   Z e d    Z	 e	 Z
 e d    Z e j d    Z e e e f d  Z e e  Z e d    Z d	 e e e f d
  Z e Z e e  Z d   Z e d  Z d   Z d   Z d5 d  Z d5 d  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' d   Z( d d  Z) d    Z* d!   Z+ e, re* Z+ Z) n  e- d5 d" d# d$  Z. d5 e- d" d%  Z/ d&   Z0 d5 d" d'  Z1 d5 e- d" d(  Z2 d5 e- d" d)  Z3 e- e d* d+  Z4 d5 i  e5 d5 d,  Z6 e6 Z7 d5 i  e5 d5 d5 d-  Z8 e8 Z9 e8 Z: e d.    Z; e d/    Z< d5 d0  Z= d5 d5 d1  Z> d2   Z? d3   Z@ d4   ZA RS(6   s=   Represents a found HTML tag with its attributes and contents.c
   
      C   sb  | d k r d |  _ n | j |  _ | d k r? t d   n  | |  _ | |  _ | |  _ | d k ro i  } nN | r | d k	 r | j r | j |  j |  } q t	 |  } n t	 |  } | r | j
 |  _ n	 |	 |  _ | |  _ g  |  _ |  j | |  t |  _ | d k r't |  _ d |  _ n7 | j |   | j |  |  _ | j |  _ | j |  _ d S(   s   Basic constructor.s%   No value provided for new tag's name.N(   R   t   parser_classR   R@   R   R   R   t   cdata_list_attributest$   _replace_cdata_list_attribute_valuest   dictR=   R>   Rr   R/   R0   R?   t   hiddent   can_be_empty_elementt   set_up_substitutionst   preserve_whitespace_tags(
   R   t   parsert   builderR   R   R   Rr   R*   R   R=   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __init__  s<    									
R   c      	   C   s   t  |   d |  j |  j |  j |  j |  j d |  j } x' d D] } t | | t	 |  |   q@ Wx$ |  j
 D] } | j | j    qm W| S(   s   A copy of a Tag is a new Tag, unconnected to the parse tree.
        Its contents are a copy of the old Tag's contents.
        R=   R   R   N(   R   R   (   R   R   R   R   R   R   Rr   R9   R	   R   R/   RK   R   (   R   t   cloneR   RI   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    c         C   s   t  |  j  d k o |  j S(   s7  Is this tag an empty-element tag? (aka a self-closing tag)

        A tag that has contents is never an empty-element tag.

        A tag that has no contents may or may not be an empty-element
        tag. It depends on the builder used to create the tag. If the
        builder has a designated list of empty-element tags, then only
        a tag whose name shows up in that list is considered an
        empty-element tag.

        If the builder has no designated list of empty-element tags,
        then any tag with no contents is an empty-element tag.
        i    (   RZ   R/   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   is_empty_element#  s    c         C   s@   t  |  j  d k r d S|  j d } t | t  r9 | S| j S(   sq  Convenience property to get the single string within this tag.

        :Return: If this tag has a single string child, return value
         is that string. If this tag has no children, or more than one
         child, return value is None. If this tag has one child tag,
         return value is the 'string' attribute of the child tag,
         recursively.
        i   i    N(   RZ   R/   R   R1   RV   R   (   R   RI   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   5  s    
c         C   s$   |  j    |  j | j |   d  S(   N(   t   clearRK   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   F  s    
c         c   s   x |  j  D]x } | d k r, t | t  s
 | d k	 rP t |  | k rP q
 n  | r} | j   } t |  d k r} q
 q} n  | Vq
 Wd S(   s   Yield all strings of certain classes, possibly stripping them.

        By default, yields only NavigableString and CData objects. So
        no comments, processing instructions, etc.
        i    N(   t   descendantsR   R1   RV   R   t   stripRZ   (   R   R   t   typest
   descendant(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   _all_stringsK  s    	c         c   s#   x |  j  t  D] } | Vq Wd  S(   N(   R   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   stripped_strings_  s    u    c         C   s/   | j  g  |  j | d | D] } | ^ q  S(   sP   
        Get all child strings, concatenated using the given separator.
        R   (   t   joinR   (   R   t	   separatorR   R   R4   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   get_textd  s    c         C   sL   |  j    |  } x5 | d k	 rG | j } | j j   g  | _ | } q Wd S(   s/   Recursively destroys the contents of this tree.N(   RB   R   R,   t   __dict__R   R/   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt	   decomposen  s    
		c         C   sg   | rD xZ |  j  D], } t | t  r3 | j   q | j   q Wn x |  j  D] } | j   qO Wd S(   sP   
        Extract all children. If decompose is True, decompose instead.
        N(   R/   R1   RQ   R   RB   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   x  s    c         C   s   g  } x t  |  j  D] \ } } t | t  r> | j   n  | t |  j  d k r] q n  |  j | d } t | t  r t | t  r t | t  r t | t  r | j |  q q WxY t	 |  D]K } |  j | } |  j | d } | j
   t | |  } | j |  q Wd S(   s   Smooth out this element's children by consolidating consecutive strings.

        This makes pretty-printed output look more natural following a
        lot of operations that modified the tree.
        i   N(   t	   enumerateR/   R1   RQ   t   smoothRZ   RV   R   RK   RG   RB   RD   (   R   t   markedR   t   at   bt   n(    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s$    

c         C   s@   x- t  |  j  D] \ } } | | k r | Sq Wt d   d S(   s   
        Find the index of a child by identity, not value. Avoids issues with
        tag.contents.index(element) getting the index of equal elements.
        s   Tag.index: element not in tagN(   R   R/   R@   (   R   R   R   RI   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRA     s    c         C   s   |  j  j | |  S(   s   Returns the value of the 'key' attribute for the tag, or
        the value given for 'default' if it doesn't have that
        attribute.(   Rr   t   get(   R   t   keyt   default(    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    c         C   s1   |  j  | |  } t | t  s- | g } n  | S(   s-   The same as get(), but always returns a list.(   R   R1   RX   (   R   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   get_attribute_list  s    c         C   s   | |  j  k S(   N(   Rr   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   has_attr  s    c         C   s   t  |   j   S(   N(   t   strt   __hash__(   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    c         C   s   |  j  | S(   sq   tag[key] returns the value of the 'key' attribute for the tag,
        and throws an exception if it's not there.(   Rr   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __getitem__  s    c         C   s   t  |  j  S(   s0   Iterating over a tag iterates over its contents.(   t   iterR/   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __iter__  s    c         C   s   t  |  j  S(   s:   The length of a tag is the length of its list of contents.(   RZ   R/   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __len__  s    c         C   s   | |  j  k S(   N(   R/   (   R   Rh   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __contains__  s    c         C   s   t  S(   s-   A tag is non-None even if it has no contents.(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __nonzero__  s    c         C   s   | |  j  | <d S(   sK   Setting tag[key] sets the value of the 'key' attribute for the
        tag.N(   Rr   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __setitem__  s    c         C   s   |  j  j | d  d S(   s;   Deleting tag[key] deletes all 'key' attributes for the tag.N(   Rr   t   popR   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __delitem__  s    c         O   s   |  j  | |   S(   s   Calling a tag like a function is the same as calling its
        find_all() method. Eg. tag('a') returns a list of all the A tags
        found within this tag.(   t   find_all(   R   Rj   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __call__  s    c         C   s   t  |  d k rR | j d  rR | d  } t j d t d |   |  j |  S| j d  r| | d k r| |  j |  St d |  j | f   d  S(	   Ni   RQ   is   .%(name)sTag is deprecated, use .find("%(name)s") instead. If you really were looking for a tag called %(name)sTag, use .find("%(name)sTag")R   t   __R/   s!   '%s' object has no attribute '%s'(	   RZ   t   endswitht   warningst   warnR   t   findt
   startswithR   R   (   R   Rd   t   tag_name(    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    !
	c         C   s   |  | k r t  St | d  s| t | d  s| t | d  s| |  j | j k s| |  j | j k s| t |   t |  k r t Sx4 t |  j  D]# \ } } | | j | k r t Sq Wt  S(   s   Returns true iff this tag has the same name, the same attributes,
        and the same contents (recursively) as the given tag.R   Rr   R/   (   R   R[   R   Rr   RZ   R?   R   R/   (   R   t   otherR   t   my_child(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __eq__  s    c         C   s   |  | k S(   sZ   Returns true iff this tag is not identical to the other tag,
        as defined in __eq__.(    (   R   R  (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __ne__  s    s   unicode-escapec         C   s!   t  r |  j   S|  j |  Sd S(   s   Renders this tag as a string.N(   t   PY3Kt   decodeR   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __repr__  s    
c         C   s
   |  j    S(   N(   R	  (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __unicode__  s    c         C   s   t  r |  j   S|  j   Sd  S(   N(   R  R	  R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   __str__   s    
R   t   xmlcharrefreplacec         C   s%   |  j  | | |  } | j | |  S(   N(   R	  R   (   R   R   t   indent_levelR5   t   errorsR   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   )  s    c         C   s  t  | t  s! |  j |  } n  | j |   } g  } x | D] \ } } | d
 k r^ | } n t  | t  s| t  | t  r d j |  } nK t  | t  s t	 |  } n- t  | t
  r | d
 k	 r | j |  } n  | j |  }	 t	 |  d | j |	  } | j |  q= Wd }
 d } d } |  j rA|  j d } n  |  j r\| j pVd }
 n d | |  j f } |  j |  } d } d } | d
 k	 rd | d } n  | r| } | d } n d
 } |  j | | |  } |  j r| } ng  } d } | rd d j |  } n  | d
 k	 r1| j |  n  | j d | |  j | |
 f  | rg| j d  n  | j |  | r| r| d	 d k r| j d  n  | r| r| j |  n  | j |  | d
 k	 r| r|  j r| j d  n  d j |  } | S(   s  Returns a Unicode representation of this tag and its contents.

        :param eventual_encoding: The tag is destined to be
           encoded into this encoding. This method is _not_
           responsible for performing that encoding. This information
           is passed in so that it can be substituted in if the
           document contains a <META> tag that mentions the document's
           encoding.
        t    t   =R   R   s   </%s%s>i   s
   <%s%s%s%s>s   
iN(   R1   R   R2   t
   attributesR   RX   t   tupleR   RU   R   R   R   t   attribute_valuet   quoted_attribute_valueRK   R   R   t   void_element_close_prefixR   t   _should_pretty_printt   decode_contentsR   R-   (   R   R  t   eventual_encodingR5   R  Rr   R   t   valt   decodedRs   t   closet   closeTagR   t   pretty_printt   spacet   indent_spacet   indent_contentsR/   R4   t   attribute_string(    (    s*   lib/python2.7/site-packages/bs4/element.pyR	  1  st    						c         C   s   | d k	 o |  j |  j k S(   s"   Should this tag be pretty-printed?N(   R   R   R   (   R   R  (    (    s*   lib/python2.7/site-packages/bs4/element.pyR    s    c         C   s9   | d  k r |  j t d | S|  j | t d | Sd  S(   NR5   (   R   R	  R   R   (   R   R   R5   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   prettify  s    c   	      C   s;  t  | t  s! |  j |  } n  | d k	 } g  } x |  D] } d } t  | t  rg | j |  } n. t  | t  r | j | j | | |   n  |  j	 o |  j
 |  j	 k } | r | r | r | j   } n  | r: | r | r | j d | d  n  | j |  | r*| r*| j d  q*q: q: Wd j |  S(   st  Renders the contents of this tag as a Unicode string.

        :param indent_level: Each line of the rendering will be
           indented this many spaces.

        :param eventual_encoding: The tag is destined to be
           encoded into this encoding. decode_contents() is _not_
           responsible for performing that encoding. This information
           is passed in so that it can be substituted in if the
           document contains a <META> tag that mentions the document's
           encoding.

        :param formatter: A Formatter object, or a string naming one of
            the standard Formatters.
        R  i   s   
R   N(   R1   R   R2   R   RV   R   RQ   RK   R	  R   R   R   R   (	   R   R  R  R5   R  R4   R<   Rs   t   preserve_whitespace(    (    s*   lib/python2.7/site-packages/bs4/element.pyR    s*    c         C   s"   |  j  | | |  } | j |  S(   sc  Renders the contents of this tag as a bytestring.

        :param indent_level: Each line of the rendering will be
           indented this many spaces.

        :param eventual_encoding: The bytestring will be in this encoding.

        :param formatter: The output formatter responsible for converting
           entities to Unicode characters.
        (   R  R   (   R   R  R   R5   R/   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   encode_contents  s    i    c         C   s%   | s d  } n  |  j d | d |  S(   NR  R   (   R   R%  (   R   R   t   prettyPrintt   indentLevel(    (    s*   lib/python2.7/site-packages/bs4/element.pyt   renderContents  s    		c         K   s;   d } |  j | | | | d |  } | r7 | d } n  | S(   sL   Return only the first child of this Tag matching the given
        criteria.i   i    N(   R   R   (   R   R   Rr   t	   recursiveRs   Rt   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR    s
    c         K   s7   |  j  } | s |  j } n  |  j | | | | | |  S(   s  Extracts a list of Tag objects that match the given
        criteria.  You can specify the name of the Tag and any
        attributes you want the Tag to have.

        The value of a key-value pair in the 'attrs' map can be a
        string, a list of strings, a regular expression object, or a
        callable that takes a string and returns whether or not the
        string matches for some custom definition of 'matches'. The
        same is true of the tag name.(   R   t   childrenRv   (   R   R   Rr   R)  Rs   Rx   Rt   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR     s    	c         C   s   t  |  j  S(   N(   R   R/   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR*    s    c         c   sT   t  |  j  s d  S|  j   j } |  j d } x | | k	 rO | V| j } q2 Wd  S(   Ni    (   RZ   R/   RO   R,   (   R   t   stopNodet   current(    (    s*   lib/python2.7/site-packages/bs4/element.pyR   	  s    c         K   s*   |  j  | | d |  } | r& | d Sd S(   s9   Perform a CSS selection operation on the current element.i   i    N(   t   selectR   (   R   t   selectort
   namespacesRt   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt
   select_one  s    c         K   sa   | d k r |  j } n  | d k r- d } n  t d k rH t d   n  t j | |  | | |  S(   s:  Perform a CSS selection operation on the current element.

        This uses the SoupSieve library.

        :param selector: A string containing a CSS selector.

        :param namespaces: A dictionary mapping namespace prefixes
        used in the CSS selector to namespace URIs. By default,
        Beautiful Soup will use the prefixes it encountered while
        parsing the document.

        :param limit: After finding this number of results, stop looking.

        :param kwargs: Any extra arguments you'd like to pass in to
        soupsieve.select().
        i    sL   Cannot execute CSS selectors because the soupsieve package is not installed.N(   R   t   _namespacest	   soupsievet   NotImplementedErrorR-  (   R   R.  R/  Rx   Rt   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR-    s    	c         C   s   |  j  S(   N(   R*  (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   childGenerator9  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   recursiveChildGenerator<  s    c         C   s   t  j d |  |  j |  S(   s   This was kind of misleading because has_key() (attributes)
        was different from __in__ (contents). has_key() is gone in
        Python 3, anyway.s2   has_key is deprecated. Use has_attr("%s") instead.(   R   R   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   has_key?  s    	N(B   R   R   R   R   R   R   t   parserClassR   R
   R   t   isSelfClosingR   R   R?   RV   R   R   t   stringsR   R   t   getTextRs   R   R   R   RA   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R
  R  R  R  R   R   R	  R  R#  R  R%  R(  R   R  t	   findChildR   t   findAllt   findChildrenR*  R   R0  R-  R4  R5  R6  (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyRQ     s   >		
	%	
															]	,			R   c           B   s\   e  Z d  Z d i  d d  Z d   Z d   Z d i  d  Z e Z d   Z	 d d  Z
 RS(   sM   Encapsulates a number of ways of matching a markup element (tag or
    text).c         K   s   |  j  |  |  _ t | t  s4 | | d <d  } n  d | k rX | d | d <| d =n  | r | r | j   } | j |  q | } n  i  } x- | j   D] \ } } |  j  |  | | <q W| |  _ |  j  |  |  _	 d  S(   Nt   classt   class_(
   t   _normalize_search_valueR   R1   R   R   t   copyt   updatet   itemsRr   Rs   (   R   R   Rr   Rs   Rt   t   normalized_attrsR   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   L  s"    
	
		c         C   s   t  | t  sH t  | t  sH t | d  sH t  | t  sH | d  k rL | St  | t  rh | j d  St | d  r g  } xc | D][ } t | d  r t  | t  r t  | t  r | j |  q | j |  j	 |   q W| St t
 |   S(   NR"   t   utf8R   (   R1   R   R   R[   t   boolR   t   bytesR	  RK   R@  R   (   R   R   t	   new_valuet   v(    (    s*   lib/python2.7/site-packages/bs4/element.pyR@  g  s    -c         C   s(   |  j  r |  j  Sd |  j |  j f Sd  S(   Ns   %s|%s(   Rs   R   Rr   (   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR    s    	c         C   s  d  } d  } t | t  r* | } | } n  t |  j t  oI t | t  } |  j s | s | rw |  j | |  j  s | rt|  j | |  j  rt| r |  j | |  } n t } d  } x t |  j j	    D] \ } }	 | s$t
 | d  r | } q$i  } x! | D] \ }
 } | | |
 <qWn  | j |  } |  j | |	  s t } Pq q W| rt| rh| } qq| } qtn  | r|  j r|  j | j |  j  rd  } n  | S(   NR   (   R   R1   RQ   R   R   t   _matchesR   RX   Rr   RC  R[   R   R?   Rs   R   (   R   t   markup_namet   markup_attrsR   t   markupt   call_function_with_tag_dataR"   t   markup_attr_mapR   t   match_againstt   kRI  t
   attr_value(    (    s*   lib/python2.7/site-packages/bs4/element.pyt
   search_tag  sB    	
"		(	c         C   s  d  } t | d  rg t | t t f  rg x | D]. } t | t  r2 |  j |  r2 | } Pq2 q2 Wn t | t  r |  j s |  j s |  j	 r|  j
 |  } qnf t | t  s t | t  r |  j r|  j	 r|  j | |  j  r| } qn t d | j   | S(   NR   s&   I don't know how to match against a %s(   R   R[   R1   RQ   RU   RV   R!   Rs   R   Rr   RS  RJ  t	   ExceptionR   (   R   RM  R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR!     s"    %)c   	      C   s  t  } t | t  s$ t | t  rn x$ | D] } |  j | |  r+ t Sq+ W|  j d j |  |  rj t St  S| t k r | d  k	 St | t  r | |  S| } t | t	  r | j
 } n  |  j |  } | d  k r | St | d  r}t | t  r}| st   } n  xk | D]\ } | j r.| } n t |  } | | k rLqq| j |  |  j | | |  rt SqWt  Sn  t  } | rt | t  r| | k } n  | rt | d  r| j |  S| rt | t	  r| j r|  j | j d | j
 |  S| S(   NR  R   R!   R   (   R?   R1   RX   R  RJ  R   R   R   R   RQ   R   R@  R[   RU   t   setR   t   idt   addR   R!   R   (	   R   RM  RP  t   already_triedR   t   itemt   original_markupR   R"   (    (    s*   lib/python2.7/site-packages/bs4/element.pyRJ    sV    

			N(   R   R   R   R   R   R@  R  RS  t	   searchTagR!   RJ  (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   H  s   		'	R   c           B   s#   e  Z d  Z d d  Z d   Z RS(   sT   A ResultSet is just a list that keeps track of the SoupStrainer
    that created it.c         C   s#   t  t |   j |  | |  _ d  S(   N(   t   superR   R   t   source(   R   R]  R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   $  s    c         C   s   t  d |   d  S(   Ns   ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?(   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   (  s    (    (   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyR   !  s   (*   t   __license__t   collections.abcR   t   ImportErrort   et   collectionsR&   t   sysR   R2  R   R   t   bs4.formatterR   R   R   R   t   version_infoR  R'   t   nonwhitespace_ret   whitespace_reR   R   R   R   R   R   t   objectR)   RV   R   R   R   R   R   R   R   RQ   R   RX   R   (    (    (    s*   lib/python2.7/site-packages/bs4/element.pyt   <module>   sL   	 :  y