
    ,hX2                       d Z 	 ddlmZ ddlZddlZddlZ	 ddl	Z	ddlmZmZmZ dZej                   d   dkD  Z ej$                  d      Z ej$                  d	      Zd
 Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d dee      Z G d de      Z G d de      Z G d de      Z  G d de       Z! G d d e      Z" G d! d"e      Z# G d# d$e      Z$ G d% d&e      Z% G d' d(e      Z& G d) d*e'      Z(y# e$ rZddlmZ Y dZ[dZ[ww xY w# e$ rZdZ	 ej                  d       Y dZ[/dZ[ww xY w)+MIT    )CallableNzEThe soupsieve package is not installed. CSS selectors cannot be used.)	FormatterHTMLFormatterXMLFormatterzutf-8   z\S+z\s+c                 L     t          fd       }|j                   fd       }|S )z>Alias one attribute name to another for backward compatibilityc                     t        |       S N)getattrselfattrs    M/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/bs4/element.pyaliasz_alias.<locals>.alias$       tT""    c                     t        |       S r   )setattrr   s    r   r   z_alias.<locals>.alias(   r   r   )propertysetter)r   r   s   ` r   _aliasr   "   s2    # # \\# #Lr   c                       e Zd ZdZddZy)NamespacedAttributezA namespaced string (e.g. 'xml:lang') that remembers the namespace
    ('xml') and the name ('lang') that were used to create it.
    Nc                     |sd }|t         j                  | |      }n5|t         j                  | |      }nt         j                  | |dz   |z         }||_        ||_        ||_        |S )N:)str__new__prefixname	namespace)clsr   r    r!   objs        r   r   zNamespacedAttribute.__new__3   si     D<++c6*C^++c4(C++c6C<$#67C
!
r   NN)__name__
__module____qualname____doc__r    r   r   r   r   .   s    r   r   c                       e Zd ZdZy)%AttributeValueWithCharsetSubstitutionz=A stand-in object for a character encoding specified in HTML.N)r%   r&   r'   r(   r)   r   r   r+   r+   E   s    Gr   r+   c                       e Zd ZdZd Zd Zy)CharsetMetaAttributeValuezA 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                 @    t         j                  | |      }||_        |S r   )r   r   original_value)r"   r/   r#   s      r   r   z!CharsetMetaAttributeValue.__new__O   s    kk#~.+
r   c                     |S )zWhen an HTML document is being encoded to a given encoding, the
        value of a meta tag's 'charset' is the name of the encoding.
        r)   r   encodings     r   encodez CharsetMetaAttributeValue.encodeT   s	     r   N)r%   r&   r'   r(   r   r3   r)   r   r   r-   r-   H   s    
r   r-   c                   V    e Zd ZdZ ej
                  dej                        Zd Zd Z	y)ContentMetaAttributeValuea  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.
    z((^|;)\s*charset=)([^;]*)c                     | j                   j                  |      }|t        j                  t        |      S t        j                  | |      }||_        |S r   )
CHARSET_REsearchr   r   r/   )r"   r/   matchr#   s       r   r   z!ContentMetaAttributeValue.__new__f   sI    %%n5=;;sN33kk#~.+
r   c                 Z    fd}| j                   j                  || j                        S )Nc                 ,    | j                  d      z   S )N   )group)r9   r2   s    r   rewritez1ContentMetaAttributeValue.encode.<locals>.rewriteq   s    ;;q>H,,r   )r7   subr/   )r   r2   r>   s    ` r   r3   z ContentMetaAttributeValue.encodep   s%    	-""7D,?,?@@r   N)
r%   r&   r'   r(   recompileMr7   r   r3   r)   r   r   r5   r5   [   s+     8"$$?JAr   r5   c                   
   e Zd ZdZ	 	 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d,dZeZd Zd Zd Zd Zd Zdi dfdZeZdi ddfdZeZdi dfdZeZdi ddfdZ e Z!e Z"di dfdZ#e#Z$di ddfdZ%e%Z&e%Z'di dfdZ(e(Z)di ddfdZ*e*Z+e*Z,di fdZ-e-Z.di dfdZ/e/Z0e/Z1ed        Z2ed        Z3d Z4d  Z5ed!        Z6ed"        Z7ed#        Z8ed$        Z9ed%        Z:d& Z;d' Z<d( Z=d) Z>d* Z?y)-PageElementzContains the navigational information for some part of the page:
    that is, its current location in the parse tree.

    NavigableString, Tag, etc. are all subclasses of PageElement.
    Nc                    || _         || _        || | j                  _        || _        | j                  | | j                  _        || _        | j                  | | j                  _        |;| j                   /| j                   j
                  r| j                   j
                  d   }|| _        || | j                  _        yy)aR  Sets up the initial relations between this element and
        other elements.

        :param parent: The parent of this element.

        :param previous_element: The element parsed immediately before
            this one.
        
        :param next_element: The element parsed immediately before
            this one.

        :param previous_sibling: The most recently encountered element
            on the same level of the parse tree as this one.

        :param previous_sibling: The next element to be encountered
            on the same level of the parse tree as this one.
        N)parentprevious_elementnext_elementnext_siblingprevious_siblingcontents)r   rG   rH   rI   rK   rJ   s         r   setupzPageElement.setup}   s    &  0'15D!!.((15D.((15D.$'DKK,@,@#{{33B7 0'15D!!. (r   c                 r    ||S t        |t              s| j                  |      }|j                  |      }|S )zFormat the given string using the given formatter.

        :param s: A string.
        :param formatter: A Formatter object, or a string naming one of the standard formatters.
        )
isinstancer   formatter_for_name
substitute)r   s	formatteroutputs       r   format_stringzPageElement.format_string   s>     H)Y///	:I%%a(r   c                     t        |t              r|S | j                  rt        }nt        }t        |t
              r	 ||      S |j                  |   S )a|  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.
        )entity_substitution)rO   r   _is_xmlr   r   r   REGISTRY)r   rS   cs      r   rP   zPageElement.formatter_for_name   sI     i+<<AAi*33zz)$$r   c                     | j                   | j                   S | j                  t        | dd      S | j                  j                  S )a  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.
        is_xmlF)	known_xmlrG   r   rX   r   s    r   rX   zPageElement._is_xml   sG     >>% >>!
 ;; 4511{{"""r   rJ   rK   c                    | j                   t        d      || u ry|| j                   u rt        d      | j                   }| j                   j                  |       }| j                          |j	                  ||       | S )zReplace this PageElement with another one, keeping the rest of the
        tree the same.
        
        :param replace_with: A PageElement.
        :return: `self`, no longer part of the tree.
        Nz^Cannot replace one element with another when the element to be replaced is not part of a tree.z%Cannot replace a Tag with its parent.)rG   
ValueErrorindexextractinsert)r   replace_with
old_parentmy_indexs       r   rd   zPageElement.replace_with   s     ;;@A A 44;;&DEE[[
;;$$T*(L1r   c                     | j                   }| j                   t        d      | j                   j                  |       }| j                          t	        | j
                  dd       D ]  }|j                  ||        | S )zjReplace this PageElement with its contents.

        :return: `self`, no longer part of the tree.
        NzSCannot replace an element with its contents when thatelement is not part of a tree.)rG   r`   ra   rb   reversedrL   rc   )r   	my_parentrf   childs       r   unwrapzPageElement.unwrap   sz    
 KK	;;12 2 ;;$$T*dmmA./ 	.EXu-	.r   c                 J    | j                  |      }|j                  |       |S )zWrap this PageElement inside another one.

        :param wrap_inside: A PageElement.
        :return: `wrap_inside`, occupying the position in the tree that used
           to be occupied by `self`, and with `self` inside it.
        )rd   append)r   wrap_insidemes      r   wrapzPageElement.wrap	  s(     {+2r   c                    | j                   0| j                   j                  | j                   j                  |       = | j                         }|j                  }| j
                  | j
                  |ur|| j
                  _        ||| j
                  ur| j
                  |_        d| _        d|_        d| _         | j                  3| j                  | j                  ur| j                  | j                  _        | j                  3| j                  | j                  ur| j                  | j                  _        dx| _        | _        | S )zoDestructively rips this element out of the tree.

        :return: `self`, no longer part of the tree.
        N)rG   rL   ra   _last_descendantrI   rH   rK   rJ   )r   
last_childrI   s      r   rb   zPageElement.extract  s'   
 ;;"$$T[[%6%6t%<=
 **,
!..!!-!!51=D!!.#D<Q<Q(Q,0,A,AL) $"&
!!-%%T->->>151B1BD!!.)!!)>)>>151F1FD.488 1r   c                     |r#| j                   | j                   j                  }nJ| }t        |t              r8|j                  r,|j                  d   }t        |t              r|j                  r,|s|| u rd}|S )zFinds the last element beneath this object to be parsed.

        :param is_initialized: Has `setup` been called on this PageElement
            yet?
        :param accept_self: Is `self` an acceptable answer to the question?
        NrF   )rJ   rH   rO   TagrL   )r   is_initializedaccept_selfrs   s       r   rr   zPageElement._last_descendant4  ss     d//;**;;JJZ-*2E2E'004
 Z-*2E2EzT1Jr   c                    |t        d      || u rt        d      t        |t              rt        |t              st        |      }ddlm} t        ||      r2t        |j                        D ]  }| j                  ||       |dz  } yt        |t        | j                              }t        |d      rE|j                  9|j                  | u r| j                  |      }||k  r|dz  }|j                          | |_        d}|dk(  rd|_        | |_        n@| j                  |dz
     }||_        ||j                  _        |j%                  d      |_        |j                   ||j                   _        |j%                  d      }|t        | j                        k\  rAd|_        | }d}	|	"| |j"                  }	|j                  }|	n|	| |	|	|_        nBd|_        n:| j                  |   }
|
|_        |j"                  ||j"                  _        |
|_        |j&                  ||j&                  _        | j                  j                  ||       y)	a'  Insert a new PageElement in the list of this PageElement's children.

        This works the same way as `list.insert`.

        :param position: The numeric position that should be occupied
           in `self.children` by the new PageElement. 
        :param new_child: A PageElement.
        NzCannot insert None into a tag.z Cannot insert a tag into itself.r   )BeautifulSoupr<   rG   F)r`   rO   r   NavigableStringbs4ry   listrL   rc   minlenhasattrrG   ra   rb   rK   rH   rJ   rr   rI   )r   position	new_childry   subchildcurrent_indexprevious_childnew_childs_last_elementrG   parents_next_sibling
next_childs              r   rc   zPageElement.insertG  s\    =>>?@@y#&y/:'	2I%i/ !!3!34 Hh/A xT]]!349h'I,<,<,H 4' $

9 5 8+
 MH	q=)-I&)-I&!]]8a<8N)7I&6?I&&3)7)H)H)OI&%%16?I&&3"+"<"<U"Cs4==))%)I"F#' &.63E'-':':$'3 '.63E $/7K'4 8<'4x0J%/I"%%1:C	&&73=#0"//;D[#00AXy1r   c                 N    | j                  t        | j                        |       y)zgAppends the given PageElement to the contents of this one.

        :param tag: A PageElement.
        N)rc   r~   rL   )r   tags     r   rm   zPageElement.append  s    
 	C&,r   c                 4    |D ]  }| j                  |        y)zmAppends the given PageElements to this one's contents.

        :param tags: A list of PageElements.
        N)rm   )r   tagsr   s      r   extendzPageElement.extend  s    
  	CKK	r   c                 
     j                   }|t        d      t         fd|D              rt        d      |D ]E  }t        |t              r|j                          |j                         }|j                  ||       G y)zMakes the given element(s) the immediate predecessor of this one.

        All the elements will have the same parent, and the given elements
        will be immediately before this one.

        :param args: One or more PageElements.
        Nz2Element has no parent, so 'before' has no meaning.c              3   &   K   | ]  }|u  
 y wr   r)   .0xr   s     r   	<genexpr>z,PageElement.insert_before.<locals>.<genexpr>       'QqDy'   z&Can't insert an element before itself.rG   r`   anyrO   rD   rb   ra   rc   )r   argsrG   predecessorra   s   `    r   insert_beforezPageElement.insert_before  s     >DF F'$'' !IJJ 	.K +{3##%LL&EMM%-	.r   c                 $     j                   }|t        d      t         fd|D              rt        d      d}|D ]P  }t        |t              r|j                          |j                         }|j                  |dz   |z   |       |dz  }R y)zMakes 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.

        :param args: One or more PageElements.
        Nz1Element has no parent, so 'after' has no meaning.c              3   &   K   | ]  }|u  
 y wr   r)   r   s     r   r   z+PageElement.insert_after.<locals>.<genexpr>  r   r   z%Can't insert an element after itself.r   r<   r   )r   r   rG   offset	successorra   s   `     r   insert_afterzPageElement.insert_after  s     >CE E'$''DEE 	I )[1!!#LL&EMM%'&.)4aKF	r   c                 B     | j                   | j                  |||fi |S )a=  Find the first PageElement that matches the given criteria and
        appears later in the document than this PageElement.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :kwargs: A dictionary of filters on attribute values.
        :return: A PageElement.
        :rtype: bs4.element.PageElement
        )	_find_onefind_all_nextr   r    attrstextkwargss        r   	find_nextzPageElement.find_next  s&     t~~d00$tNvNNr   c                 D     | j                   ||||| j                  fi |S )ag  Find all PageElements that match the given criteria and appear
        later in the document than this PageElement.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.
        :return: A ResultSet containing PageElements.
        )	_find_allnext_elementsr   r    r   r   limitr   s         r   r   zPageElement.find_all_next  s/     t~~dE48J8J '%' 	'r   c                 B     | j                   | j                  |||fi |S )a9  Find the closest sibling to this PageElement that matches the
        given criteria and appears later in the document.

        All find_* methods take a common set of arguments. See the
        online documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :kwargs: A dictionary of filters on attribute values.
        :return: A PageElement.
        :rtype: bs4.element.PageElement
        )r   find_next_siblingsr   s        r   find_next_siblingzPageElement.find_next_sibling  s-     t~~d55tUD '%' 	'r   c                 D     | j                   ||||| j                  fi |S )a  Find all siblings of this PageElement that match the given criteria
        and appear later in the document.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.
        :return: A ResultSet of PageElements.
        :rtype: bs4.element.ResultSet
        )r   next_siblingsr   s         r   r   zPageElement.find_next_siblings  s0      t~~dE4"00<4:< 	<r   c                 B     | j                   | j                  |||fi |S )a>  Look backwards in the document from this PageElement and find the
        first PageElement that matches the given criteria.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :kwargs: A dictionary of filters on attribute values.
        :return: A PageElement.
        :rtype: bs4.element.PageElement
        )r   find_all_previousr   s        r   find_previouszPageElement.find_previous#  s1     t~~""D%A9?A 	Ar   c                 D     | j                   ||||| j                  fi |S )a  Look backwards in the document from this PageElement and find all
        PageElements that match the given criteria.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.
        :return: A ResultSet of PageElements.
        :rtype: bs4.element.ResultSet
        )r   previous_elementsr   s         r   r   zPageElement.find_all_previous5  s/      t~~dE48N8N %#% 	%r   c                 B     | j                   | j                  |||fi |S )a>  Returns the closest sibling to this PageElement that matches the
        given criteria and appears earlier in the document.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :kwargs: A dictionary of filters on attribute values.
        :return: A PageElement.
        :rtype: bs4.element.PageElement
        )r   find_previous_siblingsr   s        r   find_previous_siblingz!PageElement.find_previous_siblingJ  s-     t~~d994 '%' 	'r   c                 D     | j                   ||||| j                  fi |S )a  Returns all siblings to this PageElement that match the
        given criteria and appear earlier in the document.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.
        :return: A ResultSet of PageElements.
        :rtype: bs4.element.ResultSet
        )r   previous_siblingsr   s         r   r   z"PageElement.find_previous_siblings\  s3      t~~dE4"44@8>@ 	@r   c                 B    d} | j                   ||dfi |}|r|d   }|S )a  Find the closest parent of this PageElement that matches the given
        criteria.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :kwargs: A dictionary of filters on attribute values.

        :return: A PageElement.
        :rtype: bs4.element.PageElement
        Nr<   r   )find_parents)r   r    r   r   rls         r   find_parentzPageElement.find_parentq  s5      DdE177!Ar   c                 D     | j                   ||d|| j                  fi |S )a  Find all parents of this PageElement that match the given criteria.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.

        :return: A PageElement.
        :rtype: bs4.element.PageElement
        N)r   parents)r   r    r   r   r   s        r   r   zPageElement.find_parents  s-     t~~dE4 '%' 	'r   c                     | j                   S )zThe PageElement, if any, that was parsed just after this one.

        :return: A PageElement.
        :rtype: bs4.element.PageElement
        rI   r^   s    r   nextzPageElement.next  s        r   c                     | j                   S )zThe PageElement, if any, that was parsed just before this one.

        :return: A PageElement.
        :rtype: bs4.element.PageElement
        rH   r^   s    r   previouszPageElement.previous  s     $$$r   c                 0    d } ||||dfi |}|r|d   }|S )Nr<   r   r)   )r   methodr    r   r   r   r   r   s           r   r   zPageElement._find_one  s-    4a262!Ar   c                    |d|v r|d   }|d= t        t              r}nt        ||fi |}|x|sv|st|srdu sd |D        }t        ||      S t        t              rGj	                  d      dk(  rj                  dd      \  ndfd|D        }t        ||      S t        |      }		 	 t        |      }
|
r7|j                  |
      }|r$|	j                  |       |rt        |	      |k\  r	 |	S F# t        $ r Y |	S w xY w)z8Iterates over a generator looking for things that match.NstringTc              3   @   K   | ]  }t        |t              r|  y wr   )rO   ru   )r   elements     r   r   z(PageElement._find_all.<locals>.<genexpr>  s!      7g'5 " 7   r   r<   c              3      K   | ]E  }t        |t              r|j                  k(  s |j                  k(  r|j                  k(  r| G y wr   )rO   ru   r    r   )r   r   
local_namer    r   s     r   r   z(PageElement._find_all.<locals>.<genexpr>  sJ      g'5%lld2%llj8#)>W^^v5M " s   AA)rO   SoupStrainer	ResultSetr   countsplitr   StopIterationr8   rm   r~   )r   r    r   r   r   	generatorr   strainerresultresultsifoundr   r   s    `          @@r   r   zPageElement._find_all  sA    <H.(#Dx dL)H#D%@@H<eFt|t|7 7 622D#&::c?a' *.C);&FJ!F!%J  !622H%O  *NN5)W!6  !  s   :C? ?	DDc              #   P   K   | j                   }|| |j                   }|yyw)zgAll PageElements that were parsed after this one.

        :yield: A sequence of PageElements.
        Nr   r   r   s     r   r   zPageElement.next_elements  s-      mGA m   !&&c              #   P   K   | j                   }|| |j                   }|yyw)zAll PageElements that are siblings of this one but were parsed
        later.

        :yield: A sequence of PageElements.
        N)rJ   r   s     r   r   zPageElement.next_siblings  s-      mGA mr   c              #   P   K   | j                   }|| |j                   }|yyw)zhAll PageElements that were parsed before this one.

        :yield: A sequence of PageElements.
        Nr   r   s     r   r   zPageElement.previous_elements  s/      !!mG""A mr   c              #   P   K   | j                   }|| |j                   }|yyw)zAll PageElements that are siblings of this one but were parsed
        earlier.

        :yield: A sequence of PageElements.
        N)rK   r   s     r   r   zPageElement.previous_siblings  s/      !!mG""A mr   c              #   P   K   | j                   }|| |j                   }|yyw)zlAll PageElements that are parents of this PageElement.

        :yield: A sequence of PageElements.
        N)rG   r   s     r   r   zPageElement.parents  s+      KKmGA mr   c                     | j                   S r   )r   r^   s    r   nextGeneratorzPageElement.nextGenerator'      !!!r   c                     | j                   S r   )r   r^   s    r   nextSiblingGeneratorz PageElement.nextSiblingGenerator*  r   r   c                     | j                   S r   )r   r^   s    r   previousGeneratorzPageElement.previousGenerator-      %%%r   c                     | j                   S r   )r   r^   s    r   previousSiblingGeneratorz$PageElement.previousSiblingGenerator0  r   r   c                     | j                   S r   )r   r^   s    r   parentGeneratorzPageElement.parentGenerator3  s    ||r   )NNNNN)TT)@r%   r&   r'   r(   rM   rU   rP   r   rX   r   nextSiblingpreviousSiblingrd   replaceWithrk   replace_with_childrenreplaceWithChildrenrp   rb   rr   _lastRecursiveChildrc   rm   r   r   r   r   findNextr   findAllNextr   findNextSiblingr   findNextSiblingsfetchNextSiblingsr   findPreviousr   findAllPreviousfetchPreviousr   findPreviousSiblingr   findPreviousSiblingsfetchPreviousSiblingsr   
findParentr   findParentsfetchParentsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   r   r   rD   rD   v   s/    FJ26'6R%( # #, (K/0O( K # 	@" +P2d-.,4 "$ O H!%Rd$ '"  K%)$ '  (O&*"4t <$ **!%Rd A  !L%)$d %$ (O%M)-Rd '  0*.bt%)@$ 22#2 * J $Bd '  KL! ! % %2l   	 	 # # 	# 	#  ""&&r   rD   c                   p    e Zd Zd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y)rz   zA Python Unicode string that is part of a parse tree.

    When Beautiful Soup parses the markup <b>penguin</b>, it will
    create a NavigableString for the string "penguin".
     Nc                     t        |t              rt        j                  | |      }nt        j                  | |t              }|j	                          |S )a-  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.
        )rO   r   r   DEFAULT_OUTPUT_ENCODINGrM   )r"   valueus      r   r   zNavigableString.__new__F  s?     eS!C'AC(?@A		r   c                 $     t        |       |       S )zA copy of a NavigableString has the same contents and class
        as the original, but it is not connected to the parse tree.
        )typer^   s    r   __copy__zNavigableString.__copy__U  s     tDz$r   c                     t        |       fS r   )r   r^   s    r   __getnewargs__zNavigableString.__getnewargs__[  s    D	|r   c                 \    |dk(  r| S t        d| j                  j                  d|d      )ztext.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   '' object has no attribute ')AttributeError	__class__r%   r   s     r   __getattr__zNavigableString.__getattr__^  s2     8K NN++T34 4r   c                 ^    | j                  | |      }| j                  |z   | j                  z   S )zRun the string through the provided formatter.

        :param formatter: A Formatter object, or a string naming one of the standard formatters.
        rU   PREFIXSUFFIX)r   rS   rT   s      r   output_readyzNavigableString.output_readyi  s.    
 ##D)4{{V#dkk11r   c                      y)zSince a NavigableString is not a Tag, it has no .name.

        This property is implemented so that code like this doesn't crash
        when run on a mixture of Tag and NavigableString objects:
            [x.name for x in tag.children]
        Nr)   r^   s    r   r    zNavigableString.nameq  s     r   c                     t        d      )z1Prevent NavigableString.name from ever being set.z)A NavigableString cannot be given a name.r  )r   r    s     r   r    zNavigableString.name{  s     HIIr   )minimal)r%   r&   r'   r(   r  r  r]   r   r  r  r  r  r   r    r   r)   r   r   rz   rz   7  sa     FF
 I 	42   
[[J Jr   rz   c                        e Zd ZdZdZdZddZy)PreformattedStringzA NavigableString not subject to the normal formatting rules.

    This is an abstract class used for special kinds of strings such
    as comments (the Comment class) and CDATA blocks (the CData
    class).
    r  Nc                 b    || j                  | |      }| j                  | z   | j                  z   S )a  Make this string ready for output by adding any subclass-specific
            prefix or suffix.

        :param formatter: A Formatter object, or a string naming one
            of the standard formatters. The string will be passed into the
            Formatter, but only to trigger any side effects: the return
            value is ignored.

        :return: The string, with any subclass-specific prefix and
           suffix added on.
        r  )r   rS   ignores      r   r  zPreformattedString.output_ready  s4      ''i8F{{T!DKK//r   r   )r%   r&   r'   r(   r  r  r  r)   r   r   r  r    s     FF0r   r  c                       e Zd ZdZdZdZy)CDatazA CDATA block.z	<![CDATA[z]]>Nr%   r&   r'   r(   r  r  r)   r   r   r"  r"    s    FFr   r"  c                       e Zd ZdZdZdZy)ProcessingInstructionzA SGML processing instruction.<?>Nr#  r)   r   r   r%  r%    s    (FFr   r%  c                       e Zd ZdZdZdZy)XMLProcessingInstructionzAn XML processing instruction.r&  ?>Nr#  r)   r   r   r)  r)    s    (FFr   r)  c                       e Zd ZdZdZdZy)CommentzAn HTML or XML comment.z<!--z-->Nr#  r)   r   r   r,  r,    s    !FFr   r,  c                       e Zd ZdZdZdZy)DeclarationzAn XML declaration.r&  r*  Nr#  r)   r   r   r.  r.    s    FFr   r.  c                   (    e Zd ZdZed        ZdZdZy)DoctypezA document type declaration.c                 v    |xs d}||d|z  z  }||d|z  z  }t        |      S ||d|z  z  }t        |      S )a  Generate an appropriate document type declaration for a given
        public ID and system ID.

        :param name: The name of the document's root element, e.g. 'html'.
        :param pub_id: The Formal Public Identifier for this document type,
            e.g. '-//W3C//DTD XHTML 1.1//EN'
        :param system_id: The system identifier for this document type,
            e.g. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'

        :return: A Doctype.
        r  z PUBLIC "%s"z "%s"z SYSTEM "%s")r0  )r"   r    pub_id	system_idr  s        r   for_name_and_idszDoctype.for_name_and_ids  sd     
^f,,E$9,, u~ "^i//Eu~r   z
<!DOCTYPE z>
N)r%   r&   r'   r(   classmethodr4  r  r  r)   r   r   r0  r0    s#    & , FFr   r0  c                   4   e Zd ZdZ	 	 	 	 	 d8dZ ed      Zd Zed        Z	e	Z
ed        Zej                  d        Zd	eeffd
Z ee      Zed        Zdd	eeffdZeZ ee      Zd Zd9dZd Zd Zd:dZd: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)xZ*Z(e,dd$d%fd&Z-de,d$fd'Z.d( Z/d<d)Z0de,d$fd*Z1de,d$fd+Z2e,d	d,fd-Z3di d.dfd/Z4e4Z5di d.ddfd0Z6e6Z7e6Z8ed1        Z9ed2        Z:d:d3Z;d=d4Z<d5 Z=d6 Z>d7 Z?y)>ru   zRepresents an HTML or XML tag that is part of a parse tree, along
    with its attributes and contents.

    When Beautiful Soup parses the markup <b>penguin</b>, it will
    create a Tag object representing the <b> tag.
    Nc                    |d| _         n|j                  | _         |t        d      || _        || _        || _        |r|j                  r|
||
| _        || _        |i }nD|r7|)|j                  r|j                  | j                  |      }nt        |      }nt        |      }|r|j                  | _        n|	| _        || _        g | _        | j!                  ||       d| _        ||| _        || _	        || _        y|j)                  |        |j%                  |      | _        |j                  | _	        |j&                  | _        y)a  Basic constructor.

        :param parser: A BeautifulSoup object.
        :param builder: A TreeBuilder.
        :param name: The name of the tag.
        :param namespace: The URI of this Tag's XML namespace, if any.
        :param prefix: The prefix for this Tag's XML namespace, if any.
        :param attrs: A dictionary of this Tag's attribute values.
        :param parent: The PageElement to use as this Tag's parent.
        :param previous: The PageElement that was parsed immediately before
            this tag.
        :param is_xml: If True, this is an XML tag. Otherwise, this is an
            HTML tag.
        :param sourceline: The line number where this tag was found in its
            source document.
        :param sourcepos: The character position within `sourceline` where this
            tag was found.
        :param can_be_empty_element: If True, this tag should be
            represented as <tag/>. If False, this tag should be represented
            as <tag></tag>.
        :param cdata_list_attributes: A list of attributes whose values should
            be treated as CDATA if they ever show up on this tag.
        :param preserve_whitespace_tags: A list of tag names whose contents
            should have their whitespace preserved.
        Nz%No value provided for new tag's name.F)parser_classr  r`   r    r!   r   store_line_numbers
sourceline	sourceposcdata_list_attributes$_replace_cdata_list_attribute_valuesdictr\   r]   r   rL   rM   hiddencan_be_empty_elementpreserve_whitespace_tagsset_up_substitutions)r   parserbuilderr    r!   r   r   rG   r   r\   r:  r;  r@  r<  rA  s                  r   __init__zTag.__init__  sQ   > > $D !' 0 0D<DEE	"G66'9+@(DO&DN=E"w'D'DDDIIu& UKE $^^DN#DN


68$? )=D%)>D&,DD) ((. )0(D(DT(JD% *1)F)FD& -4,L,LD)r   r8  c                     t        |       d| j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                        }dD ]  }t        ||t        | |              | j                  D ]!  }|j                  |j!                                # |S )zA copy of a Tag is a new Tag, unconnected to the parse tree.
        Its contents are a copy of the old Tag's contents.
        N)r\   r:  r;  r@  r<  rA  )r@  r?  )r
  rD  r    r!   r   r   rX   r:  r;  r@  r<  rA  r   r   rL   rm   r  )r   cloner   rj   s       r   r  zTag.__copy__?  s     T
$,,		4>>KKDLL$..!%!:!:"&"<"<%)%B%B
 7 	6DE4t!45	6]] 	+ELL)*	+r   c                 N    t        | j                        dk(  xr | j                  S )a7  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.
        r   )r~   rL   r@  r^   s    r   is_empty_elementzTag.is_empty_elementQ  s#     4==!Q&D4+D+DDr   c                     t        | j                        dk7  ry| j                  d   }t        |t              r|S |j                  S )a  Convenience property to get the single string within this
        PageElement.

        TODO It might make sense to have NavigableString.string return
        itself.

        :return: If this element has a single string child, return
         value is that string. If this element has one child tag,
         return value is the 'string' attribute of the child tag,
         recursively. If this element is itself a string, has no
         children, or has more than one child, return value is None.
        r<   Nr   )r~   rL   rO   rz   r   )r   rj   s     r   r   z
Tag.stringc  s?     t}}"a e_-L||r   c                 d    | j                          | j                  |j                  |             y)z2Replace this PageElement's contents with `string`.N)clearrm   r  r   r   s     r   r   z
Tag.stringx  s$     	

F$$V,-r   Fc              #      K   | j                   D ]I  }|t        |t              r|t        |      |vr%|r|j	                         }t        |      dk(  rF| K yw)a  Yield all strings of certain classes, possibly stripping them.

        :param strip: If True, all strings will be stripped before being
            yielded.

        :types: A tuple of NavigableString subclasses. Any strings of
            a subclass not found in this list will be ignored. By
            default, this means only NavigableString and CData objects
            will be considered. So no comments, processing instructions,
            etc.

        :yield: A sequence of strings.
        Nr   )descendantsrO   rz   r
  stripr~   )r   rP  types
descendants       r   _all_stringszTag._all_strings~  sf      ** 
	Jz*o'N"tJ'7u'D'--/
z?a'
	s   AAc              #   @   K   | j                  d      D ]  }|  yw)zrYield all strings in the document, stripping them first.

        :yield: A sequence of stripped strings.
        TN)rS  rM  s     r   stripped_stringszTag.stripped_strings  s'      ''- 	FL	r   r  c                 l    |j                  | j                  ||      D cg c]  }| c}      S c c}w )a;  Get all child strings, concatenated using the given separator.

        :param separator: Strings will be concatenated using this separator.

        :param strip: If True, strings will be stripped before being
            concatenated.

        :types: A tuple of NavigableString subclasses. Any strings of
            a subclass not found in this list will be ignored. By
            default, this means only NavigableString and CData objects
            will be considered. So no comments, processing instructions,
            etc.

        :return: A string.
        )rQ  )joinrS  )r   	separatorrP  rQ  rR   s        r   get_textzTag.get_text  s@    " ~~$*;*; +< +( )Qq ) * 	* )s   	1c                     | j                          | }|3|j                  }|j                  j                          g |_        |}|2yy)zRecursively destroys this PageElement and its children.

        This element will be removed from the tree and wiped out; so
        will everything beneath it.
        N)rb   rI   __dict__rL  rL   )r   r   r   s      r   	decomposezTag.decompose  sC     	m>>DJJAJA	 mr   c                     |rF| j                   dd D ]3  }t        |t              r|j                          $|j	                          5 y| j                   dd D ]  }|j	                           y)zWipe out all children of this PageElement by calling extract()
           on them.

        :param decompose: If this is True, decompose() (a more
            destructive method) will be called instead of extract().
        N)rL   rO   ru   r\  rb   )r   r\  r   s      r   rL  z	Tag.clear  sc     ==+ &gs+%%'OO%	&  ==+ "!"r   c                 H   g }t        | j                        D ]  \  }}t        |t              r|j	                          |t        | j                        dz
  k(  rB| j                  |dz      }t        |t              set        |t              svt        |t              rt        |t              r|j                  |        t        |      D ]R  }| j                  |   }| j                  |dz      }|j                          t        ||z         }|j                  |       T y)zSmooth 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.
        r<   N)	enumeraterL   rO   ru   smoothr~   rz   r  rm   rh   rb   rd   )r   markedr   abns         r   r`  z
Tag.smooth  s     dmm, 	!DAq!S!
C&q(( ac"A1o.q/2"1&89"1&89a 	!& &! 	Aa Aac"AIIK!$ANN1	r   c                 b    t        | j                        D ]  \  }}||u s|c S  t        d      )zFind the index of a child by identity, not value.

        Avoids issues with tag.contents.index(element) getting the
        index of equal elements.

        :param element: Look for this PageElement in `self.contents`.
        zTag.index: element not in tag)r_  rL   r`   )r   r   r   rj   s       r   ra   z	Tag.index  s;     "$--0 	HAu	 899r   c                 :    | j                   j                  ||      S )zReturns the value of the 'key' attribute for the tag, or
        the value given for 'default' if it doesn't have that
        attribute.)r   get)r   keydefaults      r   rg  zTag.get  s     zz~~c7++r   c                 P    | j                  ||      }t        |t              s|g}|S )a&  The same as get(), but always returns a list.

        :param key: The attribute to look for.
        :param default: Use this value if the attribute is not present
            on this PageElement.
        :return: A list of values, probably containing only a single
            value.
        )rg  rO   r|   )r   rh  ri  r  s       r   get_attribute_listzTag.get_attribute_list  s*     g&%&GEr   c                     || j                   v S )z<Does this PageElement have an attribute with the given name?r   r   rh  s     r   has_attrzTag.has_attr  s    djj  r   c                 4    t        |       j                         S r   )r   __hash__r^   s    r   rq  zTag.__hash__#  s    4y!!##r   c                      | j                   |   S )zqtag[key] returns the value of the 'key' attribute for the Tag,
        and throws an exception if it's not there.rm  rn  s     r   __getitem__zTag.__getitem__&  s     zz#r   c                 ,    t        | j                        S )z0Iterating over a Tag iterates over its contents.iterrL   r^   s    r   __iter__zTag.__iter__+  s    DMM""r   c                 ,    t        | j                        S )z:The length of a Tag is the length of its list of contents.)r~   rL   r^   s    r   __len__zTag.__len__/  s    4==!!r   c                     || j                   v S r   )rL   )r   r   s     r   __contains__zTag.__contains__3  s    DMM!!r   c                      y)z-A tag is non-None even if it has no contents.Tr)   r^   s    r   __bool__zTag.__bool__6  s    r   c                 "    || j                   |<   y)zKSetting tag[key] sets the value of the 'key' attribute for the
        tag.Nrm  )r   rh  r  s      r   __setitem__zTag.__setitem__:  s      

3r   c                 <    | j                   j                  |d       y)z;Deleting tag[key] deletes all 'key' attributes for the tag.N)r   poprn  s     r   __delitem__zTag.__delitem__?  s    

sD!r   c                 &     | j                   |i |S )zCalling 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.find_all)r   r   r   s      r   __call__zTag.__call__C  s     t}}d-f--r   c                 6   t        |      dkD  rI|j                  d      r8|dd }t        j                  dt	        |      z         | j                  |      S |j                  d      s|dk(  s| j                  |      S t        d	| j                  d
|d	      )zACalling tag.subtag is the same as calling tag.find(name="subtag")   ru   Nz.%(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    __rL   r  r  )	r~   endswithwarningswarnr>  find
startswithr  r  )r   r   tag_names      r   r  zTag.__getattr__I  s     s8a<CLL/3BxHMM _  bf!b 
 99X&&%cZ.?99S>!37>>3GI 	Ir   c                 L   | |u ryt        |d      rat        |d      rUt        |d      rI| j                  |j                  k7  s0| j                  |j                  k7  st        |       t        |      k7  ryt	        | j
                        D ]  \  }}||j
                  |   k7  s y y)zyReturns true iff this Tag has the same name, the same attributes,
        and the same contents (recursively) as `other`.Tr    r   rL   F)r   r    r   r~   r_  rL   )r   otherr   my_childs       r   __eq__z
Tag.__eq__[  s     5=v&w'z*II#JJ%++%IU#$T]]3 	KAx5>>!,,	 r   c                     | |k(   S )zTReturns true iff this Tag is not identical to `other`,
        as defined in __eq__.r)   )r   r  s     r   __ne__z
Tag.__ne__l  s     5=  r   c                 P    t         r| j                         S | j                  |      S )zRenders this PageElement as a string.

        :param encoding: The encoding to use (Python 2 only).
        :return: Under Python 2, a bytestring; under Python 3,
            a Unicode string.
        PY3Kdecoder3   r1   s     r   __repr__zTag.__repr__q  s$     ;;= 
 ;;x((r   c                 "    | j                         S )z-Renders this PageElement as a Unicode string.)r  r^   s    r   __unicode__zTag.__unicode__  s    {{}r   c                 N    t         r| j                         S | j                         S )zRenders this PageElement as a generic string.

        :return: Under Python 2, a UTF-8 bytestring; under Python 3,
            a Unicode string.        
        r  r^   s    r   __str__zTag.__str__  s     ;;= ;;= r   r  xmlcharrefreplacec                 L    | j                  |||      }|j                  ||      S )a  Render a bytestring representation of this PageElement and its
        contents.

        :param encoding: The destination encoding.
        :param indent_level: Each line of the rendering will be
            indented this many spaces. Used internally in
            recursive calls while pretty-printing.
        :param formatter: A Formatter object, or a string naming one of
            the standard formatters.
        :param errors: An error handling strategy such as
            'xmlcharrefreplace'. This value is passed along into
            encode() and its value should be one of the constants
            defined by Python.
        :return: A bytestring.

        r  r3   )r   r2   indent_levelrS   errorsr  s         r   r3   z
Tag.encode  s'    * KKh	:xx&))r   c                    t        |t              s| j                  |      }|j                  |       }g }|D ]  \  }}||}nt        |t              st        |t
              rdj                  |      }n?t        |t              st        |      }n#t        |t              r||j                  |      }|j                  |      }	t        |      dz   |j                  |	      z   }|j                  |        d}
d}d}| j                  r| j                  dz   }| j                  r|j                  xs d}
nd|| j                   d}| j#                  |      }d}d}|d|dz
  z  }|r|}|dz   }nd}| j%                  |||      }| j&                  r|}|S g }d}|rddj                  |      z   }||j                  |       |j                  d	|| j                   ||
d       |r|j                  d
       |j                  |       |r|r|d   d
k7  r|j                  d
       |r|r|j                  |       |j                  |       ||r| j(                  r|j                  d
       dj                  |      }|S )a  Render a Unicode representation of this PageElement and its
        contents.

        :param indent_level: Each line of the rendering will be
             indented this many spaces. Used internally in
             recursive calls while pretty-printing.
        :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.
        :param formatter: A Formatter object, or a string naming one of
            the standard formatters.
        N =r  r   z</r'  r<   <
rF   )rO   r   rP   
attributesr|   tuplerW  r   r+   r3   attribute_valuequoted_attribute_valuerm   r   rI  void_element_close_prefixr    _should_pretty_printdecode_contentsr?  rJ   )r   r  eventual_encodingrS   r  r   rh  valdecodedr   closecloseTagr   pretty_printspaceindent_spaceindent_contentsrL   rR   attribute_strings                       r   r  z
Tag.decode  s   , )Y///	:I))$/
" 	"HC{c4(JsE,B((3-C#C-c(C"3(MN-9**%67C 005HsN66t<=  LL!%	"& ;;[[3&F  77=2E ! %+DII6H00>#<!#34L E*Q.O"O''.	
 ;;A4 1 A!#&%#8 ' &HHDII'7@ AHHXXb\T-AHHX'H9J9J 
Ar   c                 \    |duxr' | j                    xs | j                  | j                   vS )zShould this tag be pretty-printed?

        Most of them should, but some (such as <pre> in HTML
        documents) should not.
        N)rA  r    )r   r  s     r   r  zTag._should_pretty_print  s:     $ 111 B99D$A$AA		
r   c                 T    || j                  d|      S | j                  |d|      S )a  Pretty-print this PageElement as a string.

        :param encoding: The eventual encoding of the string. If this is None,
            a Unicode string will be returned.
        :param formatter: A Formatter object, or a string naming one of
            the standard formatters.
        :return: A Unicode string (if encoding==None) or a bytestring 
            (otherwise).
        T)rS   r  )r   r2   rS   s      r   prettifyzTag.prettify  s2     ;;ty;99;;x;CCr   c                 0   t        |t              s| j                  |      }|du}g }| D ]  }d}t        |t              r|j	                  |      }n2t        |t
              r"|j                  |j                  |||             | j                  xr | j                  | j                  v }|r|r|s|j                         }|s|r|s|j                  d|dz
  z         |j                  |       |s|r|j                  d        dj                  |      S )a  Renders the contents of this tag as a Unicode string.

        :param indent_level: Each line of the rendering will be
           indented this many spaces. Used internally in
           recursive calls while pretty-printing.

        :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.
        Nr  r<   r  r  )rO   r   rP   rz   r  ru   rm   r  rA  r    rP  rW  )	r   r  r  rS   r  rR   rZ   r   preserve_whitespaces	            r   r  zTag.decode_contents-  s   * )Y///	:I$D0 	#AD!_-~~i0As#,0A"+- . --\$))t?\?\2\   -@zz|(;HHSL1$456(;HHTN#	#$ wwqzr   c                 J    | j                  |||      }|j                  |      S )a  Renders the contents of this PageElement as a bytestring.

        :param indent_level: Each line of the rendering will be
           indented this many spaces. Used internally in
           recursive calls while pretty-printing.

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

        :param formatter: A Formatter object, or a string naming one of
            the standard Formatters.

        :return: A bytestring.
        )r  r3   )r   r  r2   rS   rL   s        r   encode_contentszTag.encode_contents[  s'      ''h	Jx((r   r   c                 0    |sd}| j                  ||      S )z(Deprecated method for BS3 compatibility.N)r  r2   )r  )r   r2   prettyPrintindentLevels       r   renderContentszTag.renderContentso  s)     K##$x $ 9 	9r   Tc                 F    d} | j                   ||||dfi |}|r|d   }|S )a  Look in the children of this PageElement and find the first
        PageElement that matches the given criteria.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param recursive: If this is True, find() will perform a
            recursive search of this PageElement's children. Otherwise,
            only the direct children will be considered.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.
        :return: A PageElement.
        :rtype: bs4.element.PageElement
        Nr<   r   r  )r   r    r   	recursiver   r   r   r   s           r   r  zTag.findy  s7    $ DMM$y$DVD!Ar   c                 d    | j                   }|s| j                  } | j                  |||||fi |S )a  Look in the children of this PageElement and find all
        PageElements that match the given criteria.

        All find_* methods take a common set of arguments. See the online
        documentation for detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param recursive: If this is True, find_all() will perform a
            recursive search of this PageElement's children. Otherwise,
            only the direct children will be considered.
        :param limit: Stop looking after finding this many results.
        :kwargs: A dictionary of filters on attribute values.
        :return: A ResultSet of PageElements.
        :rtype: bs4.element.ResultSet
        )rO  childrenr   )r   r    r   r  r   r   r   r   s           r   r  zTag.find_all  s9    $ $$	It~~dE4	LVLLr   c                 ,    t        | j                        S )zkIterate over all direct children of this PageElement.

        :yield: A sequence of PageElements.
        ru  r^   s    r   r  zTag.children  s     DMM""r   c              #      K   t        | j                        sy| j                         j                  }| j                  d   }||ur| |j                  }||uryyw)zIterate over all children of this PageElement in a
        breadth-first sequence.

        :yield: A sequence of PageElements.
        Nr   )r~   rL   rr   rI   )r   stopNodecurrents      r   rO  zTag.descendants  s[      4==!((*77--"X%M**G X%s   AAAc                 <     | j                   ||dfi |}|r|d   S y)a  Perform a CSS selection operation on the current element.

        :param selector: 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 kwargs: Keyword arguments to be passed into SoupSieve's 
           soupsieve.select() method.

        :return: A PageElement.
        :rtype: bs4.element.PageElement
        r<   r   N)select)r   selector
namespacesr   r  s        r   
select_onezTag.select_one  s,      Hj!>v>8Or   c                     || j                   }|d}t        t        d      t        j                  || ||fi |}t	        d|      S )a  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: Keyword arguments to be passed into SoupSieve's 
           soupsieve.select() method.

        :return: A ResultSet of PageElements.
        :rtype: bs4.element.ResultSet
        Nr   zLCannot execute CSS selectors because the soupsieve package is not installed.)_namespaces	soupsieveNotImplementedErrorr  r   )r   r  r  r   r   r   s         r   r  z
Tag.select  sa    ( ))J=E%^  ""8T:uOO w''r   c                     | j                   S zDeprecated generator.)r  r^   s    r   childGeneratorzTag.childGenerator  s    }}r   c                     | j                   S r  )rO  r^   s    r   recursiveChildGeneratorzTag.recursiveChildGenerator  s    r   c                 T    t        j                  d|z         | j                  |      S )zDeprecated method. This was kind of misleading because has_key()
        (attributes) was different from __in__ (contents).

        has_key() is gone in Python 3, anyway.
        z2has_key is deprecated. Use has_attr("%s") instead.)r  r  ro  rn  s     r   has_keyzTag.has_key  s*     	J 	}}S!!r   )NNNNNNNNNNNNNN)Fr   )zunicode-escape)Nr  r$   )@r%   r&   r'   r(   rE  r   parserClassr  r   rI  isSelfClosingr   r   rz   r"  rS  stringsrU  rY  getTextr   r\  rL  r`  ra   rg  rk  ro  rq  rs  rw  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r3   r  r  r  r  r  r  r  	findChildr  findAllfindChildrenr  rO  r  r  r  r  r  r)   r   r   ru   ru     s!    HL@D9=BF*.	^M@ (K$ E E %M ( ]]. .
 "'.F 4 |$G  "$5'/*& GHD""$L:,!$
#"" 
".I$"!
) 	! (((5 I)*0 #'!8"cJ
D ,0)@!*,^  *A)( '>#(a9 B$T . I dM, GL # # + +*"(J "r   ru   c                   H    e Zd ZdZdi dfdZd Zd Zdi fdZeZd Z	d	dZ
y)
r   a&  Encapsulates a number of ways of matching a markup element (tag or
    string).

    This is primarily used to underpin the find_* methods, but you can
    create one yourself and pass it in as `parse_only` to the
    `BeautifulSoup` constructor, to parse a subset of a large
    document.
    Nc                 t   | j                  |      | _        t        |t              s||d<   d}d|v r|d   |d<   |d= |r&|r"|j	                         }|j                  |       n|}i }t        |j                               D ]  \  }}| j                  |      ||<    || _        | j                  |      | _	        y)a  Constructor.

        The SoupStrainer constructor takes the same arguments passed
        into the find_* methods. See the online documentation for
        detailed explanations.

        :param name: A filter on tag name.
        :param attrs: A dictionary of filters on attribute values.
        :param text: A filter for a NavigableString with specific text.
        :kwargs: A dictionary of filters on attribute values.
        classNclass_)
_normalize_search_valuer    rO   r>  copyupdater|   itemsr   r   )r   r    r   r   r   normalized_attrsrh  r  s           r   rE  zSoupStrainer.__init__  s     006	%& $F7OEv %X.F7Ox 

V$u{{}- 	HJC$($@$@$GS!	H &
006	r   c                    t        |t              s.t        |t              st        |d      st        |t              s||S t        |t
              r|j                  d      S t        |d      rig }|D ]`  }t        |d      r2t        |t
              s"t        |t              s|j                  |       A|j                  | j                  |             b |S t        t        |            S )Nr9   utf8rw  )	rO   r   r   r   boolbytesr  rm   r  )r   r  	new_valuevs       r   r  z$SoupStrainer._normalize_search_valueB  s     uc"j&AWUT[E\%&%-L eU#<<'' 5*%I FAz*:a3G&q#. $$Q'$$T%A%A!%DEF 
 3u:r   c                 h    | j                   r| j                   S | j                  d| j                  S )z5A human-readable representation of this SoupStrainer.|)r   r    r   r^   s    r   r  zSoupStrainer.__str__`  s&    9999"ii44r   c                    d}d}t        |t              r|}|}t        | j                  t              xr t        |t               }| j                  r>|s<|r| j	                  || j                        s|s| j	                  || j                        r|r| j                  ||      }nxd}d}t        | j                  j                               D ]N  \  }}	|s t        |d      r|}ni }|D ]
  \  }
}|||
<    |j                  |      }| j	                  ||	      rLd} n |r|r|}n|}|r4| j                  r(| j	                  |j                  | j                        sd}|S )a  Check whether a Tag with the given name and attributes would
        match this SoupStrainer.

        Used prospectively to decide whether to even bother creating a Tag
        object.

        :param markup_name: A tag name as found in some markup.
        :param markup_attrs: A dictionary of attributes as found in some markup.

        :return: True if the prospective tag would match this SoupStrainer;
            False otherwise.
        NTrg  F)rO   ru   r    r   _matchesr|   r   r  r   rg  r   r   )r   markup_namemarkup_attrsr   markupcall_function_with_tag_datar9   markup_attr_mapr   match_againstkr  
attr_values                r   
search_tagzSoupStrainer.search_tagg  sR    k3' F!Ltyy(+ 1{C00 	$ *4==;t}}[$))D*		+|<"&+/

0@0@0B+C 'D-*"<7.:O.0O(4 7156 27!0!4!4T!:J==]C % "E'ETYYt}}U\\499'MEr   c                    d}t        |d      rFt        |t        t        f      s0|D ])  }t        |t              s| j                  |      s&|} |S  |S t        |t              r7| j                  r| j                  s| j                  r| j                  |      }|S t        |t              st        |t              r8| j                  s*| j                  s| j                  || j                        r|}|S t        d|j                  z        )zFind all items in `markup` that match this SoupStrainer.

        Used by the core _find_all() method, which is ultimately
        called by all find_* methods.

        :param markup: A PageElement or a list of them.
        Nrw  z&I don't know how to match against a %s)r   rO   ru   r   rz   r8   r   r    r   r   r  	Exceptionr  )r   r  r   r   s       r   r8   zSoupStrainer.search  s      6:&z&3*/M! g7;;w/#E %$  $99		TZZ/  0FC(99TZZDMM&$))4T  86;K;KKM Mr   c                 \   d}t        |t              st        |t              r>|D ]  }| j                  ||      s y | j                  dj	                  |      |      ryy|du r|d uS t        |t
              r ||      S |}t        |t              r|j                  }| j                  |      }|| S t        |d      rit        |t              sY|s
t               }|D ]G  }|j                  r|}nt        |      }||v r"|j                  |       | j                  |||      sG y yd}|st        |t              r||k(  }|st        |d      r|j                  |      S |sHt        |t              r8|j                   r,| j                  |j                   dz   |j                  z   |      S |S )NFTr  rw  r8   r   )rO   r|   r  r  rW  r   ru   r    r  r   r   setrq  idaddr8   r   )	r   r  r  already_triedr   itemoriginal_markuprh  r9   s	            r   r  zSoupStrainer._matches  s   fd#z&%'@   ==}5  }}SXXf-}=D %%mX. (( !fc"[[F --f5>$$$M:.}c2 ! #% ==CT(C-'!%%c*}}_dMJ#  M37m+E9 ''//?C0&&==&&,/C/CC]  r   r   )r%   r&   r'   r(   rE  r  r  r   	searchTagr8   r  r)   r   r   r   r     s@     ! $7L<5 &* 2j IBPr   r   c                   *     e Zd ZdZd fd	Zd Z xZS )r   zTA ResultSet is just a list that keeps track of the SoupStrainer
    that created it.c                 :    t         t        |   |       || _        y)zlConstructor.

        :param source: A SoupStrainer.
        :param result: A list of PageElements.
        N)superr   rE  source)r   r  r   r  s      r   rE  zResultSet.__init__  s     	i'/r   c                     t        d|z        )z7Raise a helpful exception to explain a common code fix.zResultSet object has no attribute '%s'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?r  rn  s     r   r  zResultSet.__getattr__  s"     p  sv  v
 	
r   )r)   )r%   r&   r'   r(   rE  r  __classcell__)r  s   @r   r   r     s    
r   r   ))__license__collections.abcr   ImportErrorecollectionsr@   sysr  r  r  bs4.formatterr   r   r   r  version_infor  rA   nonwhitespace_rewhitespace_rer   r   r   r+   r-   r5   objectrD   rz   r  r"  r%  r)  r,  r.  r0  ru   r   r|   r   r)   r   r   <module>r     s  %( 
 
   " a2::f%  

6"	# .HC H E &A E A6~
& ~
BGJc; GJT0 06 
. 4 
  $   :z"+ z"z}6 }@
 
Y@  %$$%  IHMMO s.   D D+ D(D##D(+E0E

E