Skip to main content
Glama

API Docs MCP Server

element.cpython-310.pyc82.5 kB
o �I�g��@snUddlmZdZddlZddlZddlmZddlmZm Z m Z ddl m Z m Z mZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$m%Z%er�dd l&m'Z'dd l(m)Z)dd l*m+Z+dd l m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:e!edeedfZ;de<d<ee!dZ=de<d<e>dd�Z?e�@d�ZAde<d<dXdd�ZBdZCde<d <e�@d!�ZDde<d"<eEgd#��ZFd$e<d%<Gd&d'�d'eG�ZHGd(d)�d)eG�ZIGd*d+�d+eI�ZJGd,d-�d-eeG�ZKGd.d/�d/eeef�ZLGd0d1�d1eL�ZMGd2d3�d3eL�ZNGd4d5�d5eI�ZOGd6d7�d7eP�ZQGd8d�deGeQ�ZRGd9d:�d:eR�ZSGd;d<�d<eS�ZTGd=d>�d>eS�ZUGd?d@�d@eU�ZVGdAdB�dBeS�ZWGdCdD�dDeS�ZXGdEdF�dFeS�ZYGdGdH�dHeR�ZZGdIdJ�dJeR�Z[GdKdL�dLeR�Z\GdMdN�dNeR�Z]GdOdP�dPeR�Z^GdQdR�dReQ�Z_e dSeQdT�Z`GdUdV�dVee`ee`�ZaddWl*mbZbdS)Y�)� annotations�MITN��CSS)� _deprecated�_deprecated_alias�_deprecated_function_alias)� Formatter� HTMLFormatter� XMLFormatter)�!AttributeResemblesVariableWarning)�Any�Callable�Dict�Generic�Iterable�Iterator�List�Mapping�Optional�Pattern�Set� TYPE_CHECKING�Tuple�Type�TypeVar�Union�cast)�Self� TypeAlias�� BeautifulSoup)� TreeBuilder�� ElementFilter)�_EntitySubstitutionFunction�_FormatterOrName) �_AtMostOneElement�_AttributeValue�_AttributeValues� _Encoding�_InsertableElement� _OneElement� _QueryResults�_RawOrProcessedAttributeValues�_StrainableElement�_StrainableAttribute�_StrainableAttributes�_StrainableString�NavigableStringr�_OneOrMoreStringTypes)r/r$�_FindMethodNamezYThe {name} attribute was deprecated in version 4.7.0. If you need it, make your own copy.)Z whitespace_rez\s+� Pattern[str]�_deprecated_whitespace_re�name�str�returnr cCsL|tvrt|}tj|j|d�tdd�t�d|��Stdt�d|����)N�r8��� stacklevelZ _deprecated_zmodule z has no attribute )�_deprecated_names�warnings�warn�format�DeprecationWarning�globals�AttributeError�__name__)r8�message�rH�YC:\Users\apqls\Documents\Github\tkbase\api-docs-mcp\venv\Lib\site-packages\bs4/element.py� __getattr__Ts rJ�utf-8�DEFAULT_OUTPUT_ENCODINGz\S+�nonwhitespace_re) �idna�mbcsZoemZpalmos�punycodeZraw_unicode_escape� undefined�unicode_escapezraw-unicode-escapezunicode-escapez string-escapeZ string_escapezSet[_Encoding]�PYTHON_SPECIFIC_ENCODINGSc@s:eZdZUdZded<ded<ded<  d d d d �ZdS) �NamespacedAttributez�A namespaced attribute (e.g. the 'xml:lang' in 'xml:lang="en"') which remembers the namespace prefix ('xml') and the name ('lang') that were used to create it. � Optional[str]�prefixr8� namespaceNr:rcCsV|sd}|s t�||�}n|st�||�}n t�||d|�}||_||_||_|S)N�:)r9�__new__rVr8rW)�clsrVr8rW�objrHrHrIrY�szNamespacedAttribute.__new__)NN)rVrUr8rUrWrUr:r)rF� __module__� __qualname__�__doc__�__annotations__rYrHrHrHrIrT�s �rTc@s$eZdZUdZded<d dd�ZdS) �%AttributeValueWithCharsetSubstitutiona�An abstract class standing in for a character encoding specified inside an HTML ``<meta>`` tag. Subclasses exist for each place such a character encoding might be found: either inside the ``charset`` attribute (`CharsetMetaAttributeValue`) or inside the ``content`` attribute (`ContentMetaAttributeValue`) This allows Beautiful Soup to replace that part of the HTML file with a different encoding when ouputting a tree as a string. r9�original_value�eventual_encodingr:cC�t��)z�Do whatever's necessary in this implementation-specific portion an HTML document to substitute in a specific encoding. N��NotImplementedError��selfrbrHrHrI�substitute_encoding�sz9AttributeValueWithCharsetSubstitution.substitute_encodingN)rbr9r:r9)rFr\r]r^r_rhrHrHrHrIr`�s r`c@s&eZdZdZddd�Zddd d �Zd S)�CharsetMetaAttributeValueazA 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 become one of these objects. If the document is later encoded to an encoding other than UTF-8, its ``<meta>`` tag will mention the new encoding instead of ``utf8``. rar9r:rcCst�||�}||_|S�N)r9rYra�rZrar[rHrHrIrY�s z!CharsetMetaAttributeValue.__new__rKrbr*cCs|tvrdS|S)z�When an HTML document is being encoded to a given encoding, the value of a ``<meta>`` tag's ``charset`` becomes the name of the encoding. �N)rSrfrHrHrIrh�sz-CharsetMetaAttributeValue.substitute_encodingN�rar9r:r�rK�rbr*r:r9)rFr\r]r^rYrhrHrHrHrIri�s ric@�eZdZdZdS)�AttributeValueLista-Class for the list used to hold the values of attributes which have multiple values (such as HTML's 'class'). It's just a regular list, but you can subclass it and pass it in to the TreeBuilder constructor as attribute_value_list_class, to have your subclass instantiated instead. N�rFr\r]r^rHrHrHrIrq��rqc@rp)� AttributeDictz�Superclass for the dictionary used to hold a tag's attributes. You can use this, but it's just a regular dict with no special logic. NrrrHrHrHrIrt�rsrtc�"eZdZdZd �fdd � Z�ZS) �XMLAttributeDictzyA dictionary for holding a Tag's attributes, which processes incoming values for consistency with the HTML spec. �keyr9�valuer r:�Nonecs@|durd}t|t�r n t|ttf�rt|�}t��||�dS)z�Set an attribute value, possibly modifying it to comply with the XML spec. This just means converting common non-string values to strings: XML attributes may have "any literal string as a value." Nrl)� isinstance�bool�int�floatr9�super� __setitem__�rgrwrx�� __class__rHrIr�s zXMLAttributeDict.__setitem__�rwr9rxr r:ry�rFr\r]r^r� __classcell__rHrHr�rIrv�srvcru) �HTMLAttributeDicta�A dictionary for holding a Tag's attributes, which processes incoming values for consistency with the HTML spec, which says 'Attribute values are a mixture of text and character references...' Basically, this means converting common non-string values into strings, like XMLAttributeDict, though HTML also has some rules around boolean attributes that XML doesn't have. rwr9rxr r:rycsd|dvr ||vr ||=dSt|t�rt|t�r|j}n|}n t|ttf�r)t|�}t��||�dS)z\Set an attribute value, possibly modifying it to comply with the HTML spec, )FNN) rzr{rTr8r|r}r9r~rr�r�rHrIrs  zHTMLAttributeDict.__setitem__r�r�rHrHr�rIr� s r�c@s>eZdZUdZe�dej�Zded<dd d �Z dddd�Z dS)�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 become one of these objects. If the document is later encoded to an encoding other than UTF-8, its ``<meta>`` tag will mention the new encoding instead of ``utf8``. z((^|;)\s*charset=)([^;]*)r6� CHARSET_RErar9r:rcCs"|j�|�t�||�}||_|Srj)r��searchr9rYrarkrHrHrIrYFs  z!ContentMetaAttributeValue.__new__rKrbr*cs6�tvr |j�d|j�Sd �fdd� }|j�||j�S) z�When an HTML document is being encoded to a given encoding, the value of the ``charset=`` in a ``<meta>`` tag's ``content`` becomes the name of the encoding. rl�match� re.Match[str]r:r9cs|�d��S)N�)�group)r��rbrHrI�rewriteTsz>ContentMetaAttributeValue.substitute_encoding.<locals>.rewriteN)r�r�r:r9)rSr��subra)rgrbr�rHr�rIrhLsz-ContentMetaAttributeValue.substitute_encodingNrmrnro) rFr\r]r^�re�compile�Mr�r_rYrhrHrHrHrIr�4s  r�c@seZdZUdZdZded<ded<ded<d ed <d ed <d ed <d ed <dZded<     d�d�dd�Zd�dd�Zd�dd�Z e d�dd ��Z e d!d d"�Z e d#d d"�Zd�d�d(d)�Zd�d*d+�Ze�Zd,ed-<defd�d1d2�Ze d�d3d4��Zd5defd�d8d9�ZeZe e�Zd�d;d<�Zed=d>d"�Zd�dAdB�Zd�d�dEdF�Zd�dGdH�Z Id�d�dLdM�Ze dNdOd"�Zd�dRdS�Z d�dTdU�Z!didfd�d^d_�Z"ed`dad"�Z#didddbfd�dgdh�Z$edidjd"�Z%didfd�dkdl�Z&edmdnd"�Z'didddbfd�dodp�Z(edqdrd"�Z)edsdrdt�Z*didfd�dudv�Z+edwdxdt�Z,didddbfd�dydz�Z-ed{d|d"�Z.ed}d|dt�Z/didfd�d~d�Z0ed�d�d"�Z1didddbfd�d�d��Z2ed�d�d"�Z3ed�d�dt�Z4difd�d�d��Z5ed�d�d"�Z6diddbfd�d�d��Z7ed�d�d"�Z8ed�d�dt�Z9e d�d�d���Z:e d�d�d���Z;d�d�d��Z< �d�d�d�d��Z=e d�d�d���Z>e d�d�d���Z?e d�d�d���Z@e d�d�d���ZAe d�d�d���ZBe d�d�d���ZCe d�d�d���ZDe d�d�d���ZEe d�d�d���ZFe d�d�d���ZGd�d�d��ZHe d�d�d���ZIeJd�d"�d�d�d���ZKeJd�d"�d�d�d���ZLeJd�d"�d�d�d���ZMeJd�d"�d�d�d„�ZNeJd�d"�d�d�dń�ZOdS)�� PageElementazAn abstract class representing a single element in the parse tree. `NavigableString`, `Tag`, etc. are all subclasses of `PageElement`. For this reason you'll see a lot of methods that return `PageElement`, but you'll never see an actual `PageElement` object. For the most part you can think of `PageElement` as meaning "a `Tag` or a `NavigableString`." N�Optional[bool]� known_xmlr{� _decomposed� Optional[Tag]�parentr'� next_element�previous_element� next_sibling�previous_siblingF�hiddenr:rycCs�||_||_|jdur||j_||_|jdur||j_||_|jdur'||j_|dur:|jdur:|jjr:|jjd}||_|jdurH||j_dSdS)aJSets 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�����)r�r�r�r�r��contents)rgr�r�r�r�r�rHrHrI�setupxs*   ���   �zPageElement.setup�sr9� formatter�Optional[_FormatterOrName]cCs.|dur|St|t�s|�|�}|�|�}|S)z�Format 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. N)rzr �formatter_for_name� substitute)rgr�r��outputrHrHrI� format_string�s    zPageElement.format_string�formatter_name�4Union[_FormatterOrName, _EntitySubstitutionFunction]r cCsDt|t�r|S|jrt}tj}nt}tj}t|�r||d�S||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 `bs4.formatter.XMLFormatter` or `bs4.formatter.HTMLFormatter`), or a string (used to look up an `bs4.formatter.XMLFormatter` or `bs4.formatter.HTMLFormatter` in the appropriate registry. )Zentity_substitutionN)rzr �_is_xmlr ZREGISTRYr �callable)rgr��c�registryrHrHrIr��s  zPageElement.formatter_for_namecCs.|jdur|jS|jdurt|dd�S|jjS)aIs 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. N�is_xmlF)r�r��getattrr��rgrHrHrIr��s   zPageElement._is_xml� nextSibling�4.0.0�previousSibling�memo�Dict[Any, Any]� recursivercCrcrjrd�rgr�r�rHrHrI� __deepcopy__�szPageElement.__deepcopy__cCs |�i�S)z�A copy of a PageElement can only be a deep copy, because only one PageElement can occupy a given place in a parse tree. N)r�r�rHrHrI�__copy__�s zPageElement.__copy__�Iterable[type[NavigableString]]�default�strip�types� Iterator[str]cCrc)z�Yield all strings of certain classes, possibly stripping them. This is implemented differently in `Tag` and `NavigableString`. Nrd)rgr�r�rHrHrI� _all_strings�szPageElement._all_stringsccs�|�d�D]}|VqdS)z�Yield all interesting strings in this PageElement, stripping them first. See `Tag` for information on which strings are considered interesting in a given context. TN�r�)rg�stringrHrHrI�stripped_stringss��zPageElement.stripped_stringsrl� separator�Iterable[Type[NavigableString]]cCs|�dd�|j||d�D��S)a�Get all child strings of this PageElement, 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. :param types: A tuple of NavigableString subclasses. Any strings of a subclass not found in this list will be ignored. Although there are exceptions, the default behavior in most cases is to consider only NavigableString and CData objects. That means no comments, processing instructions, etc. :return: A string. cSsg|]}|�qSrHrH)�.0r�rHrHrI� <listcomp>#sz(PageElement.get_text.<locals>.<listcomp>)r�N)�joinr�)rgr�r�r�rHrHrI�get_text szPageElement.get_text�argscs��jdur td��t|�dkr|d�ur�St�fdd�|D��r&td���j}�j���}�j|d�t||d �D] \}}|�||�q;�S) z�Replace this `PageElement` with one or more other `PageElement`, objects, keeping the rest of the tree the same. :return: This `PageElement`, 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.r�rc3s�|]}|�juVqdSrj�r��r��xr�rHrI� <genexpr>6s�z+PageElement.replace_with.<locals>.<genexpr>z%Cannot replace a Tag with its parent.�� _self_index)�start)r�� ValueError�len�any�index�extract� enumerate�insert)rgr�Z old_parent�my_index�idx� replace_withrHr�rIr�(s �  zPageElement.replace_with� replaceWithr�� wrap_inside�TagcCs|�|�}|�|�|S)z�Wrap this `PageElement` inside a `Tag`. :return: ``wrap_inside``, occupying the position in the tree that used to be occupied by this object, and with this object now inside it. N)r��append)rgr��merHrHrI�wrapAs  zPageElement.wrapr�� Optional[int]cCs�|jdur|dur|j�|�}|jj|=|��}tt|�}|j}|jdur.|j|ur.||j_|dur;||jur;|j|_d|_d|_d|_|jdurT|j|j urT|j |j_ |j durd|j |jurd|j|j _d|_|_ |S)a'Destructively rips this element out of the tree. :param _self_index: The location of this element in its parent's .contents, if known. Passing this in allows for a performance optimization. :return: this `PageElement`, no longer part of the tree. N) r�r�r��_last_descendantrr�r�r�r�r�)rgr�� last_childr�rHrHrIr�Ks6      � � � �  zPageElement.extractcCsR|��|}d}|dur'|j}|j��t|t�rg|_d|_|}|dus dSdS)a�Recursively destroys this `PageElement` and its children. The element will be removed from the tree and wiped out; so will everything beneath it. The behavior of a decomposed `PageElement` is undefined and you should never use one for anything, but if you need to *check* whether an element has been decomposed, you can use the `PageElement.decomposed` property. NT)r�r��__dict__�clearrzr�r�r�)rg�eZnext_uprHrHrI� decompose{s   �zPageElement.decomposeT�is_initialized� accept_selfcCsZ|r |jdur |jj}n|}t|t�r#|jr#|jd}t|t�r#|js|s+||ur+d}|S)apFinds the last element beneath this object to be parsed. Special note to help you figure things out if your type checking is tripped up by the fact that this method returns _AtMostOneElement instead of PageElement: the only time this method returns None is if `accept_self` is False and the `PageElement` has no children--either it's a NavigableString or an empty Tag. :param is_initialized: Has `PageElement.setup` been called on this `PageElement` yet? :param accept_self: Is ``self`` an acceptable answer to the question? Nr�)r�r�rzr�r�)rgr�r�r�rHrHrIr��s  � zPageElement._last_descendant�_lastRecursiveChildr�r+�List[PageElement]cst�j}|dur td��t�fdd�|D��rtd��g}|D]}t|t�r)|��|���}|�|�||��q|S)aVMakes the given element(s) the immediate predecessor of this one. All the elements will have the same `PageElement.parent` as this one, and the given elements will occur immediately before this one. :param args: One or more PageElements. :return The list of PageElements that were inserted. Nz2Element has no parent, so 'before' has no meaning.c3��|]}|�uVqdSrjrHr�r�rHrIr����z,PageElement.insert_before.<locals>.<genexpr>z&Can't insert an element before itself.� r�r�r�rzr�r�r��extendr�)rgr�r��resultsZ predecessorr�rHr�rI� insert_before�s   zPageElement.insert_beforecs��j}|dur td��t�fdd�|D��rtd��d}g}|D]!}t|t�r+|��|���}|�|�|d||��|d7}q |S)aOMakes the given element(s) the immediate successor of this one. The elements will have the same `PageElement.parent` as this one, and the given elements will occur immediately after this one. :param args: One or more PageElements. :return The list of PageElements that were inserted. Nz1Element has no parent, so 'after' has no meaning.c3r�rjrHr�r�rHrIr��r�z+PageElement.insert_after.<locals>.<genexpr>z%Can't insert an element after itself.rr�r�)rgr�r��offsetr�� successorr�rHr�rI� insert_after�s    zPageElement.insert_afterr8r5�attrsr1r��Optional[_StrainableString]�kwargsr0cK�|j|j|||fi|��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: Additional filters on attribute values. :param string: A filter for a NavigableString with specific text. :kwargs: Additional filters on attribute values. N)� _find_one� find_all_next�rgr8r�r�r�rHrHrI� find_next��zPageElement.find_next�findNextr�r<�limit� _stacklevelr|r-cK�$|j|||||jfd|di|��S)a}Find all `PageElement` objects 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: Additional filters on attribute values. :param string: A filter for a NavigableString with specific text. :param limit: Stop looking after finding this many results. :param _stacklevel: Used internally to improve warning messages. :kwargs: Additional filters on attribute values. rr�N)� _find_all� next_elements�rgr8r�r�rrr�rHrHrIr�����zPageElement.find_all_next� findAllNextr�cKr�)a�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: Additional filters on attribute values. :param string: A filter for a `NavigableString` with specific text. :kwargs: Additional filters on attribute values. N)r��find_next_siblingsr�rHrHrI�find_next_sibling#r�zPageElement.find_next_sibling�findNextSiblingr cKr)apFind 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: Additional filters on attribute values. :param string: A filter for a `NavigableString` with specific text. :param limit: Stop looking after finding this many results. :param _stacklevel: Used internally to improve warning messages. :kwargs: Additional filters on attribute values. rr�N)r� next_siblingsrrHrHrIr;rzPageElement.find_next_siblings�findNextSiblingsr�fetchNextSiblings�3.0.0cKr�)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: Additional filters on attribute values. :param string: A filter for a `NavigableString` with specific text. :kwargs: Additional filters on attribute values. N)r��find_all_previousr�rHrHrI� find_previousbr�zPageElement.find_previous� findPreviousrcKr)ayLook backwards in the document from this `PageElement` and find all `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: Additional filters on attribute values. :param string: A filter for a `NavigableString` with specific text. :param limit: Stop looking after finding this many results. :param _stacklevel: Used internally to improve warning messages. :kwargs: Additional filters on attribute values. rr�N)r�previous_elementsrrHrHrIrxrzPageElement.find_all_previous�findAllPreviousr�fetchAllPreviouscKr�)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: Additional filters on attribute values. :param string: A filter for a `NavigableString` with specific text. :kwargs: Additional filters on attribute values. N)r��find_previous_siblingsr�rHrHrI�find_previous_sibling�s  ��z!PageElement.find_previous_sibling�findPreviousSiblingrcKr)aqReturns 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: Additional filters on attribute values. :param string: A filter for a NavigableString with specific text. :param limit: Stop looking after finding this many results. :param _stacklevel: Used internally to improve warning messages. :kwargs: Additional filters on attribute values. rr�N)r�previous_siblingsrrHrHrIr�rz"PageElement.find_previous_siblings�findPreviousSiblingsr�fetchPreviousSiblingscKs.d}|j||dfddi|��}|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: Additional filters on attribute values. :param self: Whether the PageElement itself should be considered as one of its 'parents'. :kwargs: Additional filters on attribute values. Nr�r�r)� find_parents)rgr8r�r��rr�rHrHrI� find_parent�s���zPageElement.find_parent� findParentrcKs(|j}|j||d||fd|di|��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: Additional filters on attribute values. :param limit: Stop looking after finding this many results. :param _stacklevel: Used internally to improve warning messages. :kwargs: Additional filters on attribute values. Nrr�)�parentsr)rgr8r�rrr��iteratorrHrHrIr�s ���zPageElement.find_parents� findParentsr� fetchParentscC�|jS)z?The `PageElement`, if any, that was parsed just after this one.N�r�r�rHrHrI�next�zPageElement.nextcCr$)z@The `PageElement`, if any, that was parsed just before this one.N�r�r�rHrHrI�previousr'zPageElement.previous�methodrcKs.d}||||dfddi|��}|r|d}|S)Nr�r�rrH)rgr*r8r�r�r�rr�rHrHrIr�%s  zPageElement._find_oner� generator�Iterator[PageElement]cKsN|durd|vr|�d�}tjdt|d�d|vr(tjtjtddd�t|d�dd lm}t ||�r6|} n t |||fi|��} |dur�|s�|s�|s�|d usR|dur^d d �|D�} t | | �St |t �r�|� d �dkrs|�d d�\} } nd} |} g} |D] } t | t�s�q{| j|ks�| j| kr�| dus�| j| kr�| �| �q{t | | �S| �||�S)z8Iterates over a generator looking for things that match.N�textzOThe 'text' argument to find()-type methods is deprecated. Use 'string' instead.r=�_class�class_)�originalZ autocorrectrr#Tcss�|] }t|t�r|VqdSrj)rzr�)r��elementrHrHrIr�as�z(PageElement._find_all.<locals>.<genexpr>rXr�)�popr@rArCr ZMESSAGE�dict� bs4.filterr$rz� SoupStrainer� ResultSetr9�count�splitr�r8rVr��find_all)rgr8r�r�rr,rr�r$Zmatcher�resultrVZ local_namer2rHrHrIr7s\ ����     ��� �  zPageElement._find_allcc�0�|j}|dur|j}|V|}|dusdSdS)z1All PageElements that were parsed after this one.Nr%�rg�ir�rHrHrIr{s��zPageElement.next_elementscC� |�|j�S)zBThis PageElement, then all PageElements that were parsed after it.N)� _self_andrr�rHrHrI�self_and_next_elements�� z"PageElement.self_and_next_elementsccr<)zVAll PageElements that are siblings of this one but were parsed later. N)r�r=rHrHrIr �s��zPageElement.next_siblingscCr?)z+This PageElement, then all of its siblings.N)r@r r�rHrHrI�self_and_next_siblings�rBz"PageElement.self_and_next_siblingsccr<)zhAll PageElements that were parsed before this one. :yield: A sequence of PageElements. Nr(r=rHrHrIr����zPageElement.previous_elementscCr?)zEThis PageElement, then all elements that were parsed earlier.N)r@rr�rHrHrI�self_and_previous_elements�� z&PageElement.self_and_previous_elementsccr<)z�All PageElements that are siblings of this one but were parsed earlier. :yield: A sequence of PageElements. N)r�r=rHrHrIr�s��zPageElement.previous_siblingscCr?)zLThis PageElement, then all of its siblings that were parsed earlier.N)r@rr�rHrHrI�self_and_previous_siblings�rFz&PageElement.self_and_previous_siblings� Iterator[Tag]ccr<)z�All elements that are parents of this PageElement. :yield: A sequence of Tags, ending with a BeautifulSoup object. Nr�r=rHrHrIr �rDzPageElement.parentscCr?)z�This element, then all of its parents. :yield: A sequence of PageElements, ending with a BeautifulSoup object. N)r@r r�rHrHrI�self_and_parents�s zPageElement.self_and_parents�other_generatorccs"�|js|V|D]}|Vq dS)zmModify a generator by yielding this element, then everything yielded by the other generator. N)r�)rgrJr>rHrHrIr@�s ��zPageElement._self_andcCst|dd�pdS)z0Check whether a PageElement has been decomposed.r�FN)r�r�rHrHrI� decomposed��zPageElement.decomposedrcCr$�z:meta private:N)rr�rHrHrI� nextGenerator�r'zPageElement.nextGeneratorr cCr$rM)r r�rHrHrI�nextSiblingGenerator�r'z PageElement.nextSiblingGeneratorrcCr$rM)rr�rHrHrI�previousGenerator�r'zPageElement.previousGeneratorrcCr$rM)rr�rHrHrI�previousSiblingGenerator�r'z$PageElement.previousSiblingGeneratorr cCr$rM)r r�rHrHrI�parentGenerator�r'zPageElement.parentGenerator)NNNNN) r�r�r�r'r�r'r�r'r�r'r:ry)r�r9r�r�r:r9)r�r�r:r �r:r{�F�r�r�r�r{r:r�r:r)r�r{r�r�r:r��r:r�)r�r9r�r{r�r�r:r9)r�r�r:r)r�r�r:r�rj)r�r�r:r�r:ry)TT)r�r{r�r{r:r')r�r+r:r�) r8r5r�r1r�r�r�r0r:r')r8r5r�r1r�r�rr�rr|r�r0r:r-)r8r5r�r1r�r0r:r') r8r5r�r1rr�rr|r�r0r:r-)r:r') r*rr8r5r�r1r�r�r�r0r:r')r)r8r5r�r1r�r�rr�r,r-rr|r�r0r:r-�r:r-)r:rH)rJr-r:r-)PrFr\r]r^r�r_r�r�r�r��propertyr�rr�r�r�r��tupler�r�r�r�ZgetTextr.r�rr�r�r�r�r�r�r�r�r�r�r�rr r rr r rrrrrrrrrrrrrr"r#r&r)r�rrrAr rCrrErrGr rIr@rKrrNrOrPrQrRrHrHrHrIr�ZsJ    � 2       �   �    0 ��  ! �  �  �� � �� �  � �� �� � �� �  �      �D                r�c@s�eZdZUdZdZded<dZded<d+d d �Zd,d-dd�Zd.dd�Z e d/dd��Z d0d1dd�Z e d2dd��Z e jd3d!d��Z d ejfd4d&d'�Ze d5d(d)��Zd*S)6r3z�A Python 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". rlr9�PREFIX�SUFFIXrx�Union[str, bytes]r:rcCs8t|t�r t�||�}nt�||t�}d|_|��|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. FN)rzr9rYrLr�r�)rZrx�urHrHrIrY s zNavigableString.__new__Fr�r�r�r{cCs t|�|�S)a>A copy of a NavigableString has the same contents and class as the original, but it is not connected to the parse tree. :param recursive: This parameter is ignored; it's only defined so that NavigableString.__deepcopy__ implements the same signature as Tag.__deepcopy__. N)�typer�rHrHrIr�s zNavigableString.__deepcopy__� Tuple[str]cCs t|�fSrj)r9r�rHrHrI�__getnewargs__%� zNavigableString.__getnewargs__cCs|S)z�Convenience property defined to match `Tag.string`. :return: This property always returns the `NavigableString` it was called on. :meta private: NrHr�rHrHrIr�(s zNavigableString.string�minimalr�r&cCs|�||�}|j||jS)z�Run the string through the provided formatter, making it ready for output as part of an HTML or XML document. :param formatter: A `Formatter` object, or a string naming one of the standard formatters. N�r�r\r])rgr�r�rHrHrI� output_ready3s zNavigableString.output_readyrycC�dS)aSince 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] :meta private: NrHr�rHrHrIr8=s zNavigableString.namer8cCstd��)zRPrevent NavigableString.name from ever being set. :meta private: z)A NavigableString cannot be given a name.N�rE)rgr8rHrHrIr8Isr�r�r4r�ccsv�||jur tj}t|�}|dur#t|t�r||urdSn||vr#dS|}|r,|��}n|}t|�dkr9|VdSdS)a�Yield all strings of certain classes, possibly stripping them. This makes it easy for NavigableString to implement methods like get_text() as conveniences, creating a consistent text-extraction API across all PageElements. :param strip: If True, all strings will be stripped before being yielded. :param types: A tuple of NavigableString subclasses. If this NavigableString isn't one of those subclasses, the sequence will be empty. By default, the subclasses considered are NavigableString and CData objects. That means no comments, processing instructions, etc. :yield: A sequence that either contains this string, or is empty. Nr)r�r��MAIN_CONTENT_STRING_TYPESr`rzr�r�)rgr�r�Zmy_typerxZ final_valuerHrHrIr�Qs$�   �   �zNavigableString._all_stringscC�|��S)a1Yield this string, but only if it is interesting. This is defined the way it is for compatibility with `Tag.strings`. See `Tag` for information on which strings are interesting in a given context. :yield: A sequence that either contains this string, or is empty. Nr�r�rHrHrI�strings�s zNavigableString.stringsN)rxr^r:rrTrU)r:ra�r:r9)rd)r�r&r:r9rX)r8r9r:ry�r�r{r�r4r:r�rW)rFr\r]r^r\r_r]rYr�rbrZr�rfr8�setterr�r�r�rkrHrHrHrIr3�s$          �2c@s6eZdZUdZdZded<dZded<d d d d �ZdS)�PreformattedStringz�A `NavigableString` not subject to the normal formatting rules. This is an abstract class used for special kinds of strings such as comments (`Comment`) and CDATA blocks (`CData`). rlr9r\r]Nr�r�r:cCs$|dur |�||�|j||jS)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. Nre)rgr�rHrHrIrf�s zPreformattedString.output_readyrj)r�r�r:r9)rFr\r]r^r\r_r]rfrHrHrHrIro�s   roc@�*eZdZUdZdZded<dZded<dS)�CDatazQA `CDATA section <https://dev.w3.org/html5/spec-LC/syntax.html#cdata-sections>`_.z <![CDATA[r9r\z]]>r]N�rFr\r]r^r\r_r]rHrHrHrIrq��  rqc@rp)�ProcessingInstructionzA SGML processing instruction.�<?r9r\�>r]NrrrHrHrHrIrt�rsrtc@rp)�XMLProcessingInstructionzIAn `XML processing instruction <https://www.w3.org/TR/REC-xml/#sec-pi>`_.rur9r\�?>r]NrrrHrHrHrIrw�rsrwc@rp)�Commentz�An `HTML comment <https://dev.w3.org/html5/spec-LC/syntax.html#comments>`_ or `XML comment <https://www.w3.org/TR/REC-xml/#sec-comments>`_.z<!--r9r\z-->r]NrrrHrHrHrIry�rsryc@rp)� DeclarationzFAn `XML declaration <https://www.w3.org/TR/REC-xml/#sec-prolog-dtd>`_.rur9r\rxr]NrrrHrHrHrIrz�rsrzc@sFeZdZUdZeddd ��Zedd d ��Zd Zded <dZ ded<dS)�DoctypezKA `document type declaration <https://www.w3.org/TR/REC-xml/#dt-doctype>`_.r8r9�pub_idrU� system_idr:cCst|�|||��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' N)r{�_string_for_name_and_ids)rZr8r|r}rHrHrI�for_name_and_ids�s zDoctype.for_name_and_idscCsL|pd}|dur|d|7}|dur|d|7}|S|dur$|d|7}|S)z�Generate a string to be used as the basis of a Doctype object. This is a separate method from for_name_and_ids() because the lxml TreeBuilder needs to call it. rlNz PUBLIC "%s"z "%s"z SYSTEM "%s"rH)rgr8r|r}rxrHrHrIr~�s   � z Doctype._string_for_name_and_idsz <!DOCTYPE r\z> r]N)r8r9r|rUr}rUr:r{)r8r9r|rUr}rUr:r9) rFr\r]r^� classmethodrr~r\r_r]rHrHrHrIr{�s    r{c@rp)� Stylesheetz�A `NavigableString` representing the contents of a `<style> HTML tag <https://dev.w3.org/html5/spec-LC/Overview.html#the-style-element>`_ (probably CSS). Used to distinguish embedded stylesheets from textual content. NrrrHrHrHrIr��rsr�c@rp)�Scriptz�A `NavigableString` representing the contents of a `<script> HTML tag <https://dev.w3.org/html5/spec-LC/Overview.html#the-script-element>`_ (probably Javascript). Used to distinguish executable code from textual content. NrrrHrHrHrIr��rsr�c@rp)�TemplateStringaA `NavigableString` representing a string found inside an `HTML <template> tag <https://html.spec.whatwg.org/multipage/scripting.html#the-template-element>`_ embedded in a larger document. Used to distinguish such strings from the main body of the document. NrrrHrHrHrIr� rsr�c@rp)�RubyTextStringz�A NavigableString representing the contents of an `<rt> HTML tag <https://dev.w3.org/html5/spec-LC/text-level-semantics.html#the-rt-element>`_. Can be used to distinguish such strings from the strings they're annotating. NrrrHrHrHrIr�rsr�c@rp)�RubyParenthesisStringz�A NavigableString representing the contents of an `<rp> HTML tag <https://dev.w3.org/html5/spec-LC/text-level-semantics.html#the-rp-element>`_. NrrrHrHrHrIr�rsr�c@s`eZdZUdZ                d�d�dd �Zd!ed"<d#ed<ded <ded <d$ed <ded<ded<ded%<d&ed'<d(ed)<ded<ded<ded<ded<ed*d"d+�Zd�d�d2d3�Zd�d4d5�Z e d�d6d7��Z e d8d+�d�d9d:��Z e d�d;d<��Zejd�d?d<��ZeehZd@ejfd�dEdF�Ze e�Zd�dKdL�Zd�dNdO�Zd�dPdQ�ZeZe dRd+�d�dTdU��Zd�dXdY�Zd�d\d]�Zd�d�d_d`�Zd�dadb�Zd�ddde�Z �d�ddidj�Z! �d�ddmdn�Z"�ddodp�Z#�ddqdr�Z$�ddtdu�Z%�ddwdx�Z&�ddydz�Z'�dd}d~�Z(d�dd��Z)�dd�d��Z*�d d�d��Z+did,ddd�f�d d�d��Z,�d d�d��Z-�d d�d��Z.�d d�d��Z/�d d�d��Z0e0Z1Z2e3dd�d�f�dd�d��Z4de3d�df�dd�d��Z5Gd�d��d�e6�Z7e7�Z8e7�Z9e7�Z:e7�Z; �d�dd�d��Z<�dd�d��Z=�dd�d��Z>�d�dd�d��Z?  ��d�dd�d��Z@de3d�f�dd�d„ZAde3d�f�dd�dĄZBe d�d+�e3d@d�f�dd�dʄ�ZCdid,df�dd�d̈́ZDeEd�d�dЃZFdid,ddd�f�dd�d҄ZGeEd�d�d+�ZHeEd�d�dЃZIe �dd�dׄ�ZJe �dd�dل�ZKe �dd�dۄ�ZL �d�dd�dބZM  Ɛd�dd�d�ZNe �dd�d��ZOe d�d+��dd�d��ZPe d�d+��dd�d��ZQe d�d+��dd�d��ZRdS( r�a� An HTML or XML tag that is part of a parse tree, along with its attributes, contents, and relationships to other parts of the tree. When Beautiful Soup parses the markup ``<b>penguin</b>``, it will create a `Tag` object representing the ``<b>`` tag. You can instantiate `Tag` objects directly, but it's not necessary unless you're adding entirely new markup to a parsed document. Most of the constructor arguments are intended for use by the `TreeBuilder` that's parsing a document. :param parser: A `BeautifulSoup` object representing the parse tree this `Tag` will be part of. :param builder: The `TreeBuilder` being used to build the tree. :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 attribute values. :param parent: The `Tag` to use as the parent of this `Tag`. May be the `BeautifulSoup` object itself. :param previous: The `PageElement` that was parsed immediately before parsing 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 dictionary of attributes whose values should be parsed as lists of strings if they ever show up on this tag. :param preserve_whitespace_tags: Names of tags whose contents should have their whitespace preserved if they are encountered inside this tag. :param interesting_string_types: When iterating over this tag's string contents in methods like `Tag.strings` or `PageElement.get_text`, these are the types of strings that are interesting enough to be considered. By default, `NavigableString` (normal strings) and `CData` (CDATA sections) are the only interesting string subtypes. :param namespaces: A dictionary mapping currently active namespace prefixes to URIs, as of the point in the parsing process when this tag was encountered. This can be used later to construct CSS selectors. N�parser�Optional[BeautifulSoup]�builder�Optional[TreeBuilder]r8rUrWrVr��(Optional[_RawOrProcessedAttributeValues]r��#Optional[Union[BeautifulSoup, Tag]]r)r'r�r�� sourceliner�� sourcepos�can_be_empty_element�cdata_list_attributes�Optional[Dict[str, Set[str]]]�preserve_whitespace_tags�Optional[Set[str]]�interesting_string_types�$Optional[Set[Type[NavigableString]]]� namespaces�Optional[Dict[str, str]]cCs�|durd|_n|j|_|durtd��||_||_|pi|_||_|r'|jr6| dus/| dur6| |_| |_ n| |_| |_ |durJ| rEt }nt }t }n|j }|j}||_|dur\|�|_n,|durl|jrl|�|j|�|_n|�|_|��D]\}}t|t�r�|�|�}||j|<qt|r�|j|_n| |_g|_|�||�d|_|dur�| |_| |_||_||_dS|j|_|�|�|�|�|_|j|_|j|_|j|jvr�|j|jh|_dS|j|_dS)Nz%No value provided for new tag's name.F) � parser_classr�r�r8rW� _namespacesrVZstore_line_numbersr�r�rvr�rqZattribute_dict_class�attribute_value_list_classr�r�Z$_replace_cdata_list_attribute_values�itemsrz�listr�r�r�r�r�r�r�r�Zset_up_substitutionsZstring_containersri)rgr�r�r8rWrVr�r�r)r�r�r�r�r�r�r�r�Zattr_dict_classr��k�vrHrHrI�__init__Rsp  �� �           z Tag.__init__zOptional[type[BeautifulSoup]]r�r9r)r�r�r�r{r�� parserClassr�Tr�r�r�r:rcCsv|��}|r9|g}|�|j�D])\}}|tjur|��q|j|dd�}|d�|�|tjur8|�t t|��q|S)z�A deepcopy of a Tag is a new Tag, unconnected to the parse tree. Its contents are a copy of the old Tag's contents. F)r�r�N) � copy_self� _event_stream� descendantsr��END_ELEMENT_EVENTr3r�r��START_ELEMENT_EVENTr)rgr�r��clone� tag_stack�eventr2Zdescendant_clonerHrHrIr��s   �zTag.__deepcopy__cCs`t|�dd|j|j|j|j|j|j|j|j|j |j |j |j d�}dD] }t ||t||��q"|S)a Create a new Tag just like this one, but with no contents and unattached to any parse tree. This is the first step in the deepcopy process, but you can call it on its own to create a copy of a Tag without copying its contents. N)r�r�r�r�r�r�r�r�)r�r�)r`r8rWrVr�r�r�r�r�r�r�r�r��setattrr�)rgr��attrrHrHrIr��s&�z Tag.copy_selfcCst|j�dko |jduS)a�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 `TreeBuilder` 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. This is usually the case for HTML documents. If the builder has no designated list of empty-element, then any tag with no contents is an empty-element tag. This is usually the case for XML documents. rTN)r�r�r�r�rHrHrI�is_empty_elementszTag.is_empty_elementr�cCr$�z: :meta private:N)r�r�rHrHrI� isSelfClosing'r'zTag.isSelfClosingcCs>t|j�dkr dS|jd}t|t�r|St|t�r|jSdS)aXConvenience property to get the single string within this `Tag`, assuming there is just one. :return: If this `Tag` has a single child that's a `NavigableString`, the return value is that string. If this element has one child `Tag`, the return value is that child's `Tag.string`, recursively. If this `Tag` has no children, or has more than one child, the return value is ``None``. If this property is unexpectedly returning ``None`` for you, it's probably because your `Tag` has more than one thing inside it. r�Nr)r�r�rzr3r�r�)rg�childrHrHrIr�,s   z Tag.stringr�rycCs0|��t|t�r |j}nt}|�||��dS)z>Replace the `Tag.contents` of this `Tag` with a single string.N)r�rzr3r�r�)rgr�� new_classrHrHrIr�Ds  Fr�r�r4r�ccs��||jur|jdur|j}n|j}|jD]4}t|t�sqt|�}t|t�r,||ur+qn |dur5||vr5q|rF|��}t|�dkrBq|Vq|VqdS)aSYield all strings of certain classes, possibly stripping them. :param strip: If True, all strings will be stripped before being yielded. :param types: A tuple of NavigableString subclasses. Any strings of a subclass not found in this list will be ignored. By default, the subclasses considered are the ones found in self.interesting_string_types. If that's not specified, only NavigableString and CData objects will be considered. That means no comments, processing instructions, etc. Nr) r�r�rir�rzr3r`r�r�)rgr�r�Z descendantZdescendant_type�strippedrHrHrIr�Qs,�     � �zTag._all_strings�positionr|� new_childrenr+cGs,g}|D]}|�|�||��|d7}q|S)a�Insert one or more new PageElements as a child of this `Tag`. This works similarly to :py:meth:`list.insert`, except you can insert multiple elements at once. :param position: The numeric position that should be occupied in this Tag's `Tag.children` by the first new `PageElement`. :param new_children: The PageElements to insert. :return The newly inserted PageElements. r�N)r��_insert)rgr�r�Zinserted� new_childrHrHrIr�|s   z Tag.insertr�c Cs�|durtd��||urtd��t|t�rt|t�st|�}ddlm}t||�r5|j|gt|j��R�St |t |j��}t |d�re|j dure|j |ura|� |�}||krZ|d8}n||kra|gS|��||_ d}|dkrud|_||_n|j|d}||_||j_|�d�|_|jdur�||j_|jddd �}tt|�}|t |j�kr�d|_|}d}|dur�|dur�|j}|j }|dur�q�|dur�|dus�|dur�||_nd|_n|j|} | |_|jdur�||j_| |_|jdur�||j_|j�||�|gS) NzCannot insert None into a tag.z Cannot insert a tag into itself.rr r�r�FT)r�r�)r�rzr9r3�bs4r!r�r�r��minr��hasattrr�r�r�r�r�r�r�r�rr�) rgr�r�r!Z current_indexZprevious_childZnew_childs_last_elementr�Zparents_next_siblingZ next_childrHrHrIr��sp       � �   �z Tag._insertcCsT|j}|dur td��|�|�}|j|d�t|jdd��D]}|�||�q|S)zqReplace this `PageElement` with its contents. :return: This object, no longer part of the tree. NzTCannot replace an element with its contents when that element is not part of a tree.r�)r�r�r�r��reversedr�r�)rgZ my_parentr�r�rHrHrI�unwrap�s�  z Tag.unwrapr�r,cCrjr�)r�r�rHrHrI�replaceWithChildren��zTag.replaceWithChildren�tagr�cCs|�t|j�|�dS)z� Appends the given `PageElement` to the contents of this `Tag`. :param tag: A PageElement. :return The newly appended PageElement. rN)r�r�r�)rgr�rHrHrIr��sz Tag.append�tags�(Union[Iterable[_InsertableElement], Tag]cCs�t|t�r t|j�}n*t|ttf�r,tjdtdd�t|t�r(t|t�s(t |�}|g}n t|t �r5t|�}g}|D] }|� |� |��q9|S)a�Appends one or more objects to the contents of this `Tag`. :param tags: If a list of `PageElement` objects is provided, they will be appended to this tag's contents, one at a time. If a single `Tag` is provided, its `Tag.contents` will be used to extend this object's `Tag.contents`. :return The list of PageElements that were appended. zIA single non-Tag item was passed into Tag.extend. Use Tag.append instead.r<r=N) rzr�r�r�r�r9r@rA� UserWarningr3rr�)rgr�Ztag_listr�r�rHrHrIr�s" � z Tag.extendr�cCs.|jdd�D] }|r|��q|��qdS)a Destroy all children of this `Tag` by calling `PageElement.extract` on them. :param decompose: If this is True, `PageElement.decompose` (a more destructive method) will be called instead of `PageElement.extract`. N)r�r�r�)rgr�r2rHrHrIr�-s   �z Tag.clearcCs�g}t|j�D]7\}}t|t�r|��|t|j�dkrq|j|d}t|t�r>t|t�r>t|t�s>t|t�s>|�|�qt |�D]#}t t|j|�}t t|j|d�}|� �t||�}|� |�qCdS)z�Smooth out the children of this `Tag` by consolidating consecutive strings. If you perform a lot of operations that modify the tree, calling this method afterwards can make pretty-printed output look more natural. r�N) r�r�rzr��smoothr�r3ror�r�rr�r�)rgZmarkedr>�a�b�nrHrHrIr�;s0  ���� �   �z Tag.smoothr2cCs,t|j�D] \}}||ur|Sqtd��)aFind the index of a child of this `Tag` (by identity, not value). Doing this by identity avoids issues when a `Tag` contains two children that have string equality. :param element: Look for this `PageElement` in this object's contents. zTag.index: element not in tagN)r�r�r�)rgr2r>r�rHrHrIr�cs �z Tag.indexrwr��Optional[_AttributeValue]cCs|j�||�S)a$Returns the value of the 'key' attribute for the tag, or the value given for 'default' if it doesn't have that attribute. :param key: The attribute to look for. :param default: Use this value if the attribute is not present on this `Tag`. N)r��get)rgrwr�rHrHrIr�ps zTag.get�Optional[AttributeValueList]rqcCsV|�||�}|dur|��}|St|t�r|}|St|t�s#tt|�}|�|g�}|S)a:The same as get(), but always returns a (possibly empty) list. :param key: The attribute to look for. :param default: Use this value if the attribute is not present on this `Tag`. :return: A list of strings, usually empty or containing only a single value. N)r�r�rzr�r9r)rgrwr�rxZ list_valuerHrHrI�get_attribute_list}s  � �  zTag.get_attribute_listcC� ||jvS)z6Does this `Tag` have an attribute with the given name?N�r��rgrwrHrHrI�has_attr�� z Tag.has_attrcCs t|���Srj)r9�__hash__r�rHrHrIr��s z Tag.__hash__r(cCs |j|S)zqtag[key] returns the value of the 'key' attribute for the Tag, and throws an exception if it's not there.Nr�r�rHrHrI� __getitem__�� zTag.__getitem__r-cC� t|j�S)z0Iterating over a Tag iterates over its contents.N)�iterr�r�rHrHrI�__iter__�r�z Tag.__iter__cCr�)z:The length of a Tag is the length of its list of contents.N)r�r�r�rHrHrI�__len__�r�z Tag.__len__r�r cCr�rj�r�)rgr�rHrHrI� __contains__�rczTag.__contains__cCrg)z-A tag is non-None even if it has no contents.TNrHr�rHrHrI�__bool__�sz Tag.__bool__rxcCs||j|<dS)zKSetting tag[key] sets the value of the 'key' attribute for the tag.Nr�r�rHrHrIr�szTag.__setitem__cCs|j�|d�dS)z;Deleting tag[key] deletes all 'key' attributes for the tag.N)r�r3r�rHrHrI� __delitem__�szTag.__delitem__r<�Optional[_StrainableElement]r1r�rrr�r0r-cKs|j||||||fi|��S)z�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.N�r:)rgr8r�r�r�rrr�rHrHrI�__call__�s  ��z Tag.__call__�subtagr�cCs�t|�dkr$|�d�r$|dd�}tjdt|d�tdd�|�|�}n|�d �s3|d ks3|�|�}n td |j |f��t t t |�S) zACalling tag.subtag is the same as calling tag.find(name="subtag")rr�N�����z�.%(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;r<r=�__r�z!'%s' object has no attribute '%s') r��endswithr@rAr4rC�find� startswithrEr�rrr�)rgr�Ztag_namer;rHrHrIrJ�s  ��   �zTag.__getattr__�othercCs�||urdSt|t�s dSt|d�r0t|d�r0t|d�r0|j|jks0|j|jks0t|�t|�kr2dSt|j�D]\}}||j|krEdSq7dS)zyReturns true iff this Tag has the same name, the same attributes, and the same contents (recursively) as `other`.TFr8r�r�N)rzr�r�r8r�r�r�r�)rgr�r>Zmy_childrHrHrI�__eq__�s, ��� � ���z Tag.__eq__cCs ||k S)zTReturns true iff this Tag is not identical to `other`, as defined in __eq__.NrH)rgr�rHrHrI�__ne__�r�z Tag.__ne__cCrj)zRenders this `Tag` as a string.N)�decoder�rHrHrI�__repr__�sz Tag.__repr__rd�xmlcharrefreplace�encodingr*� indent_levelr�r&�errors�bytescCs|�|||�}|�||�S)aRender this `Tag` and its contents as a bytestring. :param encoding: The encoding to use when converting to a bytestring. This may also affect the text of the document, specifically any encoding declarations within the document. :param indent_level: Each line of the rendering will be indented this many levels. (The ``formatter`` decides what a 'level' means, in terms of spaces or other characters output.) This is used internally in recursive calls while pretty-printing. :param formatter: Either 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 :py:meth:`str.encode` and its value should be one of the `error handling constants defined by Python's codecs module <https://docs.python.org/3/library/codecs.html#error-handlers>`_. N�r��encode)rgr�r�r�r�r_rHrHrIr� s z Tag.encoderbr!�Optional[Iterator[PageElement]]c Csng}t|t�s |�|�}|durd}d}|�|�D]�\}}|tjtjfvr3tt|�}|j||dd�} n%|tj urNtt|�}|j||dd�} |durM|d8}n tt |�}|� |�} |r_d} } nd} } |tjurx|sxtt|�� �sxd} d} |}n|tj ur�||ur�d} d} d}|dur�| s�| r�t|t �r�| � �} | r�|�| ||| | �} |tjkr�|d7}|�| �qd�|�S)aRender this `Tag` and its contents as a Unicode string. :param indent_level: Each line of the rendering will be indented this many levels. (The ``formatter`` decides what a 'level' means, in terms of spaces or other characters output.) This is used internally in recursive calls while pretty-printing. :param encoding: The encoding you intend to use when converting the string to a bytestring. decode() is *not* responsible for performing that encoding. This information is needed so that a real encoding can be substituted in if the document contains an encoding declaration (e.g. in a <meta> tag). :param formatter: Either a `Formatter` object, or a string naming one of the standard formatters. :param iterator: The iterator to use when navigating over the parse tree. This is only used by `Tag.decode_contents` and you probably won't need to use it. TrN)�openingFr�rl)rzr r�r�r�r��EMPTY_ELEMENT_EVENTr� _format_tagr�r3rf�_should_pretty_printr��_indent_stringr�r�) rgr�rbr�r!�piecesZstring_literal_tagr�r2Zpiece� indent_before� indent_afterrHrHrIr� s\     �   �� �   �   z Tag.decodec@rp)zTag._TreeTraversalEventz{An internal class representing an event in the process of traversing a parse tree. :meta private: NrrrHrHrHrI�_TreeTraversalEvent� rsr��1Iterator[Tuple[_TreeTraversalEvent, PageElement]]ccs��g}|p|j}|D]?}|r(|j|dkr(|��}tj|fV|r(|j|dkst|t�rC|jr7tj|fVq tj|fV|� |�q tj |fVq |rZ|��}tj|fV|sLdSdS)a]Yield a sequence of events that can be used to reconstruct the DOM for this element. This lets us recreate the nested structure of this element (e.g. when formatting it as a string) without using recursive method calls. This is similar in concept to the SAX API, but it's a simpler interface designed for internal use. The events are different from SAX and the arguments associated with the events are Tags and other Beautiful Soup objects. :param iterator: An alternate iterator to use when traversing the tree. r�N) �self_and_descendantsr�r3r�r�rzr�r�r�r��STRING_ELEMENT_EVENT)rgr!r�r�Znow_closed_tagrHrHrIr�� s&�  �     �zTag._event_streamr�r r�r�cCs.d}|r |r |j|}d}|rd}|||S)a�Add indentation whitespace before and/or after a string. :param s: The string to amend with whitespace. :param indent_level: The indentation level; affects how much whitespace goes before the string. :param indent_before: Whether or not to add whitespace before the string. :param indent_after: Whether or not to add whitespace (a newline) after the string. rl� N)�indent)rgr�r�r�r�r�Z space_beforeZ space_afterrHrHrIr�� s  zTag._indent_stringr�cCs|jrdSd}|s d}d}|jr|jd}d}|rt|�|�}g}|D]H\} } | dur-| } n8t| t�s7t| t�r=d�| �} nt| t�sGt| �} nt| t�rU|durU| � |�} |� | �} t| �d|� | �} |� | �q"|rtdd�|�}d} |j r~|jp}d} d|||j|| dS)Nrl�/rX� �=�<rv)r�rV� attributesrzr�r[r�r9r`rhZattribute_valueZquoted_attribute_valuer�r�Zvoid_element_close_prefixr8)rgrbr�r�Z closing_slashrVZattribute_stringr�r�rw�val�decodedr.Zvoid_element_closing_slashrHrHrIr�� s\      ��    �������zTag._format_tagr�cCs|duo |j p |j|jvS)z�Should this tag be pretty-printed? Most of them should, but some (such as <pre> in HTML documents) should not. N)r�r8)rgr�rHrHrIr� s �zTag._should_pretty_print�Optional[_Encoding]r^cCs&|dur |jd|d�S|j|d|d�S)acPretty-print this `Tag` as a string or bytestring. :param encoding: The encoding of the bytestring, or None if you want Unicode. :param formatter: A Formatter object, or a string naming one of the standard formatters. :return: A string (if no ``encoding`` is provided) or a bytestring (otherwise). Nr)r�r�)r�r�r�r�)rgr�r�rHrHrI�prettify) s z Tag.prettifycCs|j||||jd�S)a3Renders the contents of this tag as a Unicode string. :param indent_level: Each line of the rendering will be indented this many levels. (The formatter decides what a 'level' means in terms of spaces or other characters output.) 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 needed so that a real encoding can be substituted in if the document contains an encoding declaration (e.g. in a <meta> tag). :param formatter: A `Formatter` object, or a string naming one of the standard Formatters. )r!N)r�r�)rgr�rbr�rHrHrI�decode_contents; s �zTag.decode_contentscCs|�|||�}|�|�S)a%Renders the contents of this PageElement as a bytestring. :param indent_level: Each line of the rendering will be indented this many levels. (The ``formatter`` decides what a 'level' means, in terms of spaces or other characters output.) This is used internally in recursive calls while pretty-printing. :param formatter: Either a `Formatter` object, or a string naming one of the standard formatters. :param encoding: The bytestring will be in this encoding. N)rr�)rgr�r�r�r�rHrHrI�encode_contentsW s zTag.encode_contentsrr� prettyPrint� indentLevelcCs|sd}|j||d�S)zIDeprecated method for BS3 compatibility. :meta private: N)r�r�)r)rgr�rrrHrHrI�renderContentsk s zTag.renderContentsr5cKs2d}|j||||dfddi|��}|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: Additional filters on attribute values. :param recursive: If this is True, find() will perform a recursive search of this Tag's children. Otherwise, only the direct children will be considered. :param string: A filter on the `Tag.string` attribute. :param limit: Stop looking after finding this many results. :kwargs: Additional filters on attribute values. Nr�rrrr�)rgr8r�r�r�r�rr�rHrHrIr�| s zTag.find� findChildr�rc Ks2|j}|s|j}|j|||||fd|di|��S)a�Look in the children of this `PageElement` and find all `PageElement` objects 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: Additional 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. :param _stacklevel: Used internally to improve warning messages. :kwargs: Additional filters on attribute values. rr�N)r��childrenr) rgr8r�r�r�rrr�r,rHrHrIr:� s ���z Tag.find_all�findAllr:� findChildrencCsdd�|jD�S)z7Iterate over all direct children of this `PageElement`.css�|]}|VqdSrjrHr�rHrHrIr�� s�zTag.children.<locals>.<genexpr>Nr�r�rHrHrIr � rLz Tag.childrencCr?)zVIterate over this `Tag` and its children in a breadth-first sequence. N)r@r�r�rHrHrIr�� s zTag.self_and_descendantsccsr�t|j�sdStt|jdd��}|j}|jd}||ur3|dur7|j}|V|}||ur5|dus!dSdSdSdS)zUIterate over all children of this `Tag` in a breadth-first sequence. NT)r�r)r�r�rr�r�r�)rgZlast_descendantZstopNode�currentr�rHrHrIr�� s�   �zTag.descendants�selectorcKs|jj||fi|��S)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 Soup Sieve's soupsieve.select() method. N)�css� select_one)rgrr�r�rHrHrIr� szTag.select_one�ResultSet[Tag]cKs|jj|||fi|��S)aPPerform 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. N)r�select)rgrr�rr�rHrHrIr� sz Tag.selectrcCst|�S)z,Return an interface to the CSS selector API.Nrr�rHrHrIr r�zTag.cssr cCr$�z6Deprecated generator. :meta private: N)r r�rHrHrI�childGenerator �zTag.childGeneratorr�cCr$r)r�r�rHrHrI�recursiveChildGenerator rzTag.recursiveChildGeneratorr�cCs |�|�S)z�Deprecated method. This was kind of misleading because has_key() (attributes) was different from __in__ (contents). has_key() is gone in Python 3, anyway. :meta private: N)r�r�rHrHrI�has_key s z Tag.has_key)NNNNNNNNNNNNNNNN) r�r�r�r�r8rUrWrUrVrUr�r�r�r�r)r'r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)TrUrVrS)r:rU)r�r9r:ryrm)r�r|r�r+r:r�)r�r|r�r+r:r�)r:r,)r�r+r:r�)r�r�r:r�rT)r�r{r:ryrX)r2r�r:r|rj)rwr9r�r�r:r�)rwr9r�r�r:rq)rwr9r:r{)r:r|)rwr9r:r(rY)r�r r:r{)rwr9rxr(r:ry�rwr9r:ry)r8r�r�r1r�r{r�r�rr�rr|r�r0r:r-)r�r9r:r�)r�r r:r{rl) r�r*r�r�r�r&r�r9r:r�) r�r�rbr*r�r&r!r�r:r9)r!r�r:r�) r�r9r�r|r�r r�r{r�r{r:r9)rbr9r�r r�r{r:r9)r�)r�r|r:r{)Nrd)r�rr�r&r:r^)r�r�rbr*r�r&r:r9)r�r�r�r*r�r&r:r�)r�r*rr{rr�r:r�) r8r5r�r1r�r{r�r�r�r0r:r')r8r5r�r1r�r{r�r�rr�rr|r�r0r:r-)rr9r�r�r�r r:r�)Nr) rr9r�r�rr|r�r r:r)r:r)SrFr\r]r^r�r_rr�r�r�rZr�rr�r�rnr3rqrir�r�r�rkr�r�r�Zreplace_with_childrenr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rJr�r�r��__str__� __unicode__rLr�r��objectr�r�r�r�r�r�r�r�r�rrrrr�rr r:r r r r�r�rrrrrrrHrHrHrIr�!s4 2 �y         �)   W   %  (��         �    � �m� , > ����� � ��r�� _PageElementT)�boundcs:eZdZUdZded< dd�fd d � Zdd d�Z�ZS)r7z�A ResultSet is a list of `PageElement` objects, gathered as the result of matching an :py:class:`ElementFilter` against a parse tree. Basically, a list of search results. �Optional[ElementFilter]�sourcerHr;�Iterable[_PageElementT]r:rycstt|��|�||_dSrj)r~r7r�r)rgrr;r�rHrIr�5 s zResultSet.__init__rwr9cCstd|�d���)z7Raise a helpful exception to explain a common code fix.z#ResultSet object has no attribute "z|". You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?Nrhr�rHrHrIrJ; s �zResultSet.__getattr__)rH)rrr;r r:ryr)rFr\r]r^r_r�rJr�rHrHr�rIr7- s �r7)r6)r8r9r:r )c� __future__r� __license__r�r@Zbs4.cssrZbs4._deprecationrrrZ bs4.formatterr r r Z bs4._warningsr �typingr rrrrrrrrrrrrrrrrZtyping_extensionsrrr�r!Z bs4.builderr"r5r$r%r&Z bs4._typingr'r(r)r*r+r,r-r.r/r0r1r2r4r_r5r4r?r�r7rJrLrM�setrSr9rTr`rirqrtrvr�r�rr�r3rorqrtrwryrzr{r�r�r�r�r�r�rr7r6rHrHrHrI�<module>s�  L   8 ��   �"  +&'(     

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ShotaNagafuchi/api-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server