/usr/lib/python3/dist-packages/bs4/__pycache__
NameSizeModeActions
dammit.cpython-310.pyc1655490644editdlrm
diagnose.cpython-310.pyc82980644editdlrm
element.cpython-310.pyc648580644editdlrm
formatter.cpython-310.pyc60810644editdlrm
testing.cpython-310.pyc435140644editdlrm
__init__.cpython-310.pyc231550644editdlrm
Edit: /usr/lib/python3/dist-packages/bs4/__pycache__/element.cpython-310.pyc (64858B)
o 7aL @s"dZzddlmZWney"Zz ddlmZWYdZ[ndZ[wwddlZddlZddlZzddl Z WneyNZz dZ e dWYdZ[ndZ[wwddl m Z m Z mZdZejddkZedZed Zd d Zegd ZGd ddeZGdddeZGdddeZGdddeZGdddeZGdddeeZGdddeZ Gddde Z!Gddde Z"Gdd d e"Z#Gd!d"d"e Z$Gd#d$d$e Z%Gd%d&d&e Z&Gd'd(d(eZ'Gd)d*d*eZ(Gd+d,d,eZ)Gd-d.d.eZ*Gd/d0d0eZ+Gd1d2d2e,Z-dS)3MIT)CallableNzEThe soupsieve package is not installed. CSS selectors cannot be used.) Formatter HTMLFormatter XMLFormatterzutf-8z\S+z\s+cs&tfdd}|jfdd}|S)z>Alias one attribute name to another for backward compatibilityc t|SNgetattrselfattr-/usr/lib/python3/dist-packages/bs4/element.pyalias$ z_alias..aliascrr )setattrr rrrr(r)propertysetter)rrrrr_alias"s r) idnambcsoempalmospunycoderaw_unicode_escape undefinedunicode_escapezraw-unicode-escapeunicode-escapez string-escape string_escapec@seZdZdZdddZdS)NamespacedAttributezA namespaced string (e.g. 'xml:lang') that remembers the namespace ('xml') and the name ('lang') that were used to create it. NcCsV|sd}|s t||}n|st||}n t||d|}||_||_||_|S)N:)str__new__prefixname namespace)clsr&r'r(objrrrr%PszNamespacedAttribute.__new__NN)__name__ __module__ __qualname____doc__r%rrrrr"Ksr"c@eZdZdZdS)%AttributeValueWithCharsetSubstitutionz=A stand-in object for a character encoding specified in HTML.Nr,r-r.r/rrrrr1bsr1c@s eZdZdZddZddZdS)CharsetMetaAttributeValuezA generic stand-in for the value of a meta tag's 'charset' attribute. When Beautiful Soup parses the markup '', the value of the 'charset' attribute will be one of these objects. cCst||}||_|Sr )r$r%original_value)r)r4r*rrrr%ls z!CharsetMetaAttributeValue.__new__cCs|tvrdS|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. )PYTHON_SPECIFIC_ENCODINGSr encodingrrrencodeqsz CharsetMetaAttributeValue.encodeN)r,r-r.r/r%r9rrrrr3es r3c@s.eZdZdZedejZddZddZ dS)ContentMetaAttributeValueaA generic stand-in for the value of a meta tag's 'content' attribute. When Beautiful Soup parses the markup: The value of the 'content' attribute will be one of these objects. z((^|;)\s*charset=)([^;]*)cCs6|j|}|durtt|St||}||_|Sr ) CHARSET_REsearchr$r%r4)r)r4matchr*rrrr%s   z!ContentMetaAttributeValue.__new__cs(tvrdSfdd}|j||jS)Nr5cs|dS)N)group)r=r8rrrewritesz1ContentMetaAttributeValue.encode..rewrite)r6r;subr4)r r8rArr@rr9s z ContentMetaAttributeValue.encodeN) r,r-r.r/recompileMr;r%r9rrrrr:zs  r:c@s`eZdZdZ  d\ddZddZddZed d Ze d Z e d Z e Z d e fddZeddZdd e fddZeZeeZddZeZddZeZeZddZd]ddZd^ddZeZd d!Zd"d#Zd$d%Zd&d'Zd(d)Z didfd*d+Z!e!Z"diddfd,d-Z#e#Z$didfd.d/Z%e%Z&diddfd0d1Z'e'Z(e'Z)didfd2d3Z*e*Z+diddfd4d5Z,e,Z-e,Z.didfd6d7Z/e/Z0diddfd8d9Z1e1Z2e1Z3difd:d;Z4e4Z5didfdd?Z9ed@dAZ:dBdCZ;dDdEZedJdKZ?edLdMZ@edNdOZAedPdQZBdRdSZCdTdUZDdVdWZEdXdYZFdZd[ZGdS)_ 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. NcCs||_||_|dur||j_||_|jdur||j_||_|jdur&||j_|dur9|jdur9|jjr9|jjd}||_|durF||j_dSdS)aRSets 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)parentprevious_element next_element next_siblingprevious_siblingcontents)r rHrIrJrLrKrrrsetups"    zPageElement.setupcCs.|dur|St|ts||}||}|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. N) isinstancerformatter_for_name substitute)r s formatteroutputrrr format_strings    zPageElement.format_stringcCs<t|tr|S|jr t}nt}t|tr||dS|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)rOr_is_xmlrrrREGISTRY)r rScrrrrPs    zPageElement.formatter_for_namecCs.|jdur|jS|jdurt|ddS|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. Nis_xmlF) known_xmlrHr rWr rrrrWs   zPageElement._is_xmlrKrLFcCst)zYield all strings of certain classes, possibly stripping them. This is implemented differently in Tag and NavigableString. )NotImplementedError)r striptypesrrr _all_stringsszPageElement._all_stringsccs|dD]}|VqdS)zvYield all strings in this PageElement, stripping them first. :yield: A sequence of stripped strings. TN)r_r stringrrrstripped_strings szPageElement.stripped_stringsr5cCs|dd|j||dDS)aGet 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|]}|qSrr).0rRrrr &sz(PageElement.get_text..)r^)joinr_)r separatorr]r^rrrget_texts zPageElement.get_textcsjdur tdt|dkr|durdStfdd|Dr&tdj}j}j|dt||d D] \}}|||q;S) zReplace this PageElement with one or more PageElements, keeping the rest of the tree the same. :param args: One or more PageElements. :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.r>rc3s|]}|juVqdSr rHrcxr rr 8sz+PageElement.replace_with..z%Cannot replace a Tag with its parent. _self_index)start)rH ValueErrorlenanyindexextract enumerateinsert)r args old_parentmy_indexidx replace_withrr rrz+s   zPageElement.replace_withcCsX|j}|jdur td|j|}|j|dt|jddD]}|||q!|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.rl)rHrorrrsreversedrMru)r my_parentrxchildrrrunwrapBs   zPageElement.unwrapcCs||}|||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. )rzappend)r wrap_insidemerrrwrapTs  zPageElement.wrapcCs|jdur|dur|j|}|jj|=|}|j}|jdur)|j|ur)||j_|dur6||jur6|j|_d|_d|_d|_|jdurO|j|jurO|j|j_|jdur_|j|jur_|j|j_d|_|_|S)aDestructively 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: `self`, no longer part of the tree. N)rHrrrM_last_descendantrJrIrLrK)r rm last_childrJrrrrs_s,            zPageElement.extractTcCsZ|r |jdur |jj}n|}t|tr#|jr#|jd}t|tr#|js|s+||ur+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? NrG)rKrIrOTagrM)r is_initialized accept_selfrrrrrs   zPageElement._last_descendantc Cs|durtd||urtdt|trt|tst|}ddlm}t||r=t|jD] }||||d7}q.dSt |t |j}t |dre|j dure|j |ura| |}||kra|d8}|||_ d}|dkrud|_||_n|j|d}||_||j_|d|_|jdur||j_|d}|t |jkrd|_|}d} | dur|dur|j} |j }| durn| dur|dus| dur| |_nd|_n|j|} | |_|jdur||j_| |_|jdur||j_|j||dS) 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. NzCannot insert None into a tag.z Cannot insert a tag into itself.r) BeautifulSoupr>rHF)rorOr$NavigableStringbs4rlistrMruminrphasattrrHrrrsrLrIrKrrJ) r position new_childrsubchild current_indexprevious_childnew_childs_last_elementrHparents_next_sibling next_childrrrrusl              zPageElement.insertcCs|t|j|dS)zgAppends the given PageElement to the contents of this one. :param tag: A PageElement. N)rurprM)r tagrrrrszPageElement.appendcCs,t|tr t|j}|D]}||q dS)zmAppends the given PageElements to this one's contents. :param tags: A list of PageElements. N)rOrrrMr)r tagsrrrrextends   zPageElement.extendcsjj}|dur tdtfdd|Drtd|D]}t|tr'||}|||qdS)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.c3|]}|uVqdSr rrir rrrk z,PageElement.insert_before..z&Can't insert an element before itself.rHrorqrOrFrsrrru)r rvrH predecessorrrrr r insert_befores  zPageElement.insert_beforecs~j}|dur tdtfdd|Drtdd}|D]}t|tr)||}||d|||d7}qdS)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.c3rr rrir rrrk!rz+PageElement.insert_after..z%Can't insert an element after itself.rr>r)r rvrHoffset successorrrrr r insert_afters    zPageElement.insert_aftercK|j|j|||fi|S)aSFind 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.Tag | bs4.element.NavigableString ) _find_one find_all_nextr r'attrstextkwargsrrr find_next.szPageElement.find_nextcK|j|||||jfi|S)agFind 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_elementsr r'rrlimitrrrrr?szPageElement.find_all_nextcKr)aOFind 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.Tag | bs4.element.NavigableString )rfind_next_siblingsrrrrfind_next_siblingRzPageElement.find_next_siblingcKr)aFind 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_siblingsrrrrrd zPageElement.find_next_siblingscKr)aTLook 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.Tag | bs4.element.NavigableString )rfind_all_previousrrrr find_previousys  zPageElement.find_previouscKr)aLook 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 )rprevious_elementsrrrrrszPageElement.find_all_previouscKr)aTReturns 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.Tag | bs4.element.NavigableString )rfind_previous_siblingsrrrrfind_previous_siblingrz!PageElement.find_previous_siblingcKr)aReturns 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 )rprevious_siblingsrrrrrrz"PageElement.find_previous_siblingscKs*d}|j||dfi|}|r|d}|S)aFind 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.Tag | bs4.element.NavigableString Nr>r) find_parents)r r'rrrlrrr find_parents zPageElement.find_parentcKs|j||d||jfi|S)aFind 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.Tag | bs4.element.NavigableString N)rparents)r r'rrrrrrrszPageElement.find_parentscC|jS)zThe PageElement, if any, that was parsed just after this one. :return: A PageElement. :rtype: bs4.element.Tag | bs4.element.NavigableString rJr rrrnextzPageElement.nextcCr)zThe PageElement, if any, that was parsed just before this one. :return: A PageElement. :rtype: bs4.element.Tag | bs4.element.NavigableString rIr rrrpreviousrzPageElement.previouscKs*d}||||dfi|}|r|d}|S)Nr>rr)r methodr'rrrrrrrrrs zPageElement._find_onec  s0|durd|vr|d}|d=ttr}n t||fi|}|durh|sh|sh|shdus3dur?dd|D}t||SttrhddkrTdd\ndfdd|D}t||St|} zt|} Wn ty}Y| Sw| r|| } | r| | |rt | |kr | Sqm) z8Iterates over a generator looking for things that match.NraTcss|] }t|tr|VqdSr )rOrrcelementrrrrksz(PageElement._find_all..r#r>c3sD|]}t|tr|jks|jkrdus|jkr|VqdSr )rOrr'r&r local_namer'r&rrrk(s  ) rO SoupStrainer ResultSetr$countsplitr StopIterationr<rrp) r r'rrr generatorrstrainerresultresultsifoundrrrr sB        zPageElement._find_allcc,|j}|dur|V|j}|dusdSdS)zgAll PageElements that were parsed after this one. :yield: A sequence of PageElements. Nrr rrrrrB zPageElement.next_elementsccr)zAll PageElements that are siblings of this one but were parsed later. :yield: A sequence of PageElements. N)rKrrrrrM zPageElement.next_siblingsccr)zhAll PageElements that were parsed before this one. :yield: A sequence of PageElements. NrrrrrrYrzPageElement.previous_elementsccr)zAll PageElements that are siblings of this one but were parsed earlier. :yield: A sequence of PageElements. N)rLrrrrrdrzPageElement.previous_siblingsccr)zlAll PageElements that are parents of this PageElement. :yield: A sequence of PageElements. NrhrrrrrprzPageElement.parentscCst|ddpdS)zOCheck whether a PageElement has been decomposed. :rtype: bool _decomposedFr r rrr decomposed{szPageElement.decomposedcCrr )rr rrr nextGeneratorzPageElement.nextGeneratorcCrr )rr rrrnextSiblingGeneratorrz PageElement.nextSiblingGeneratorcCrr )rr rrrpreviousGeneratorrzPageElement.previousGeneratorcCrr )rr rrrpreviousSiblingGeneratorrz$PageElement.previousSiblingGeneratorcCrr )rr rrrparentGeneratorrzPageElement.parentGenerator)NNNNNr )TT)Hr,r-r.r/rNrUrPrrWr nextSiblingpreviousSiblingobjectdefaultr_rbrggetTextrrz replaceWithr~replace_with_childrenreplaceWithChildrenrrsr_lastRecursiveChildrurrrrrfindNextr findAllNextrfindNextSiblingrfindNextSiblingsfetchNextSiblingsr findPreviousrfindAllPrevious fetchPreviousrfindPreviousSiblingrfindPreviousSiblingsfetchPreviousSiblingsr findParentr findParents fetchParentsrrrrrrrrrrrrrrrrrrrrFs )     &R     6        rFc@sxeZdZdZdZdZdZddZddZdd Z d d Z dd dZ e ddZ e jddZ dejfddZe eZdS)rzA Python Unicode string that is part of a parse tree. When Beautiful Soup parses the markup penguin, it will create a NavigableString for the string "penguin". r5NcCs2t|tr t||}nt||t}||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. )rOr$r%DEFAULT_OUTPUT_ENCODINGrN)r)valueurrrr%s zNavigableString.__new__cCs 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 rrr__copy__s zNavigableString.__copy__cCs t|fSr )r$r rrr__getnewargs__ zNavigableString.__getnewargs__cCs |dkr|Std|jj|f)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.ra!'%s' object has no attribute '%s')AttributeError __class__r,)r rrrr __getattr__szNavigableString.__getattr__minimalcCs|||}|j||jS)zRun the string through the provided formatter. :param formatter: A Formatter object, or a string naming one of the standard formatters. rUPREFIXSUFFIX)r rSrTrrr output_readys zNavigableString.output_readycCdS)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] Nrr rrrr'szNavigableString.namecCstd)z1Prevent NavigableString.name from ever being set.z)A NavigableString cannot be given a name.r)r r'rrrr'sFccsp||jur tj}t|}|dur#t|tr||urdSn||vr#dS|}|r+|}t|dkr6|VdSdS)aYield 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)rr DEFAULT_INTERESTING_STRING_TYPESrrOr]rp)r r]r^my_typerrrrr_s"    zNavigableString._all_strings)r)r,r-r.r/rrr[r%rrrrrr'rrFrr_stringsrrrrrs     )rc@s"eZdZdZdZdZdddZdS)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). r5NcCs$|dur |||}|j||jS)aMake 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. Nr)r rSignorerrrrs zPreformattedString.output_readyr )r,r-r.r/rrrrrrrr  s r c@eZdZdZdZdZdS)CDatazA CDATA block.z Nr,r-r.r/rrrrrrr$rc@r)ProcessingInstructionzA SGML processing instruction.Nrrrrrr)src@r)XMLProcessingInstructionzAn XML processing instruction.r?>Nrrrrrr/rrc@r)CommentzAn HTML or XML comment.zNrrrrrr4rrc@r) DeclarationzAn XML declaration.rrNrrrrrr:rrc@s$eZdZdZeddZdZdZdS)DoctypezA document type declaration.cCsT|pd}|dur|d|7}|dur|d|7}t|S|dur&|d|7}t|S)aGenerate 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. r5Nz PUBLIC "%s"z "%s"z SYSTEM "%s")r)r)r'pub_id system_idrrrrfor_name_and_idsBs    zDoctype.for_name_and_idsz N)r,r-r.r/ classmethodrrrrrrrr@s  rc@r0) StylesheetzA NavigableString representing an stylesheet (probably CSS). Used to distinguish embedded stylesheets from textual content. Nr2rrrrr]rc@r0)ScriptzA NavigableString representing an executable script (probably Javascript). Used to distinguish executable code from textual content. Nr2rrrrr frr c@r0)TemplateStringzA NavigableString representing a string found inside an HTML template embedded in a larger document. Used to distinguish such strings from the main body of the document. Nr2rrrrr!orr!c@seZdZdZ      daddZedZddZedd Z e Z ed d Z e j d d Z e efZd ejfddZeeZddZdbddZddZddZdcddZdcddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Z d*d+Z!d,d-Z"d.d/Z#d0d1Z$d2d3Z%d4d5Z&ddd7d8Z'd9d:Z(d;d<Z)e*re(Z)Z'e+dd=d>fd?d@Z,de+d=fdAdBZ-dCdDZ.dedEdFZ/de+d=fdGdHZ0de+d=fdIdJZ1e+d dKfdLdMZ2didNdfdOdPZ3e3Z4didNddfdQdRZ5e5Z6e5Z7edSdTZ8edUdVZ9dcdWdXZ:dfdYdZZ;d[d\ZdS)grzRepresents an HTML or XML tag that is part of a parse tree, along with its attributes and contents. When Beautiful Soup parses the markup penguin, it will create a Tag object representing the tag. NcCsH|durd|_n|j|_|durtd||_||_||_|r"|jr0| dus*| dur0| |_| |_|dur7i}n|rM|durH|j rH| |j|}n t |}nt |}|rX|j |_ n| |_ ||_g|_|||d|_|dur|| |_| |_ ||_||_dS|||||_|j |_ |j|_|j|jvr|j|j|_dS|j|_dS)aBasic 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 . If False, this tag should be represented as . :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. :param interesting_string_types: This is a NavigableString subclass or a tuple of them. When iterating over this Tag's strings in methods like Tag.strings or Tag.get_text, these are the types of strings that are interesting enough to be considered. The default is to consider NavigableString and CData the only interesting string subtypes. Nz%No value provided for new tag's name.F) parser_classrror'r(r&store_line_numbers sourceline sourceposcdata_list_attributes$_replace_cdata_list_attribute_valuesdictrZr[rrMrNhiddencan_be_empty_elementpreserve_whitespace_tagsinteresting_string_typesset_up_substitutionsstring_containersr )r parserbuilderr'r(r&rrHrrZr$r%r*r&r+r,rrr__init__sP'          z Tag.__init__r"cCstt|d|j|j|j|j|j|j|j|j|j |j |j d }dD] }t ||t ||q|jD] }||q.|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)rZr$r%r*r&r+)r*r))rr0r'r(r&rrWr$r%r*r&r+rr rMrr)r clonerr}rrrrs  z Tag.__copy__cCst|jdko |jS)a7Is 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)rprMr*r rrris_empty_elementszTag.is_empty_elementcCs0t|jdkr dS|jd}t|tr|S|jS)aConvenience 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)rprMrOrra)r r}rrrras   z Tag.stringcCs||||dS)z2Replace this PageElement's contents with `string`.N)clearrrr`rrrra+sFccs||jur |j}|jD]4}|durt|tsq t|}t|tr'||ur&q n |dur0||vr0q |r=|}t|dkr=q |Vq dS)a|Yield 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. :yield: A sequence of strings. Nr)rr, descendantsrOrrr]rp)r r]r^ descendantdescendant_typerrrr_2s&    zTag._all_stringscCsD||}|dur |j}|jg|_d|_|}|dus dSdS)aRecursively destroys this PageElement and its children. This 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 `decomposed` property. NT)rsrJ__dict__r4rMr)r rnrrr decomposeXs  z Tag.decomposecCsX|r|jddD]}t|tr|q |q dS|jddD]}|q#dS)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)rMrOrr:rs)r r:rrrrr4ls    z Tag.clearcCsg}t|jD]7\}}t|tr||t|jdkrq|j|d}t|tr>t|tr>t|ts>t|ts>||qt |D]}|j|}|j|d}| t||}| |qCdS)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) rtrMrOrsmoothrprr rr{rsrz)r markedrabr9rrrr;}s.        z Tag.smoothcCs,t|jD] \}}||ur|Sqtd)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`. zTag.index: element not in tag)rtrMro)r rrr}rrrrrs z Tag.indexcCs|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.)rget)r keyrrrrr?szTag.getcCs |||}t|ts|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. )r?rOr)r r@rrrrrget_attribute_lists zTag.get_attribute_listcC ||jvS)zdSq0dS)zyReturns true iff this Tag has the same name, the same attributes, and the same contents (recursively) as `other`.Tr'rrMF)rr'rrprtrM)r otherrmy_childrrr__eq__s    z Tag.__eq__cCs ||k S)zTReturns true iff this Tag is not identical to `other`, as defined in __eq__.r)r r_rrr__ne__rHz Tag.__ne__r cCstr|S||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. PY3Kdecoder9r7rrr__repr__s z Tag.__repr__cCs|S)z-Renders this PageElement as a Unicode string.)rer rrr __unicode__&szTag.__unicode__cCstr|S|S)zRenders this PageElement as a generic string. :return: Under Python 2, a UTF-8 bytestring; under Python 3, a Unicode string. rcr rrr__str__*sz Tag.__str__rxmlcharrefreplacecCs||||}|||S)aRender 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. rer9)r r8 indent_levelrSerrorsrrrrr98s z Tag.encodecCs t|ts ||}||}g}|D]H\}}|dur|}n8t|ts(t|tr.d|}nt|ts8t|}nt|trF|durF| |}| |} t|d| | }| |qd} d} d} |j rj|j d} |jrs|jpqd} nd| |jf} ||} d}d}|durd|d}| r|}|d}nd}||||}|jr|}|Sg}d}|rdd|}|dur| || d| |j|| f| r| d | || r|r|d d kr| d | r| r| || | |dur| r|jr| d d|}|S) aRender 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 tag that mentions the document's encoding. :param formatter: A Formatter object, or a string naming one of the standard formatters. N =r5r#zr>z <%s%s%s%s> rG)rOrrP attributesrtuplerer$r1r9attribute_valuequoted_attribute_valuerr&r3void_element_close_prefixr'_should_pretty_printdecode_contentsr)rK)r rkeventual_encodingrSrprr@valdecodedrclosecloseTagr& pretty_printspace indent_spaceindent_contentsrMrRattribute_stringrrrrePs                         z Tag.decodecCs|duo |j p |j|jvS)zShould this tag be pretty-printed? Most of them should, but some (such as
 in HTML
        documents) should not.
        N)r+r')r
rkrrrrus
zTag._should_pretty_printcCs&|dur|jd|dS|j|d|dS)aPretty-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).
        NT)rSrj)r
r8rSrrrprettifys
zTag.prettifyc	Cst|ts
||}|du}g}|D]N}d}t|tr!||}nt|tr0||||||jo8|j	|jv}|rC|rC|sC|
}|r`|rR|sR|d|d|||r`|s`|dqd|S)aRenders 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  tag that mentions the document's
           encoding.

        :param formatter: A Formatter object, or a string naming one of
            the standard Formatters.
        Nrmr>ror5)rOrrPrrrrrer+r'r]re)	r
rkrwrSr|rRrYrpreserve_whitespacerrrrvs0






zTag.decode_contentscCs||||}||S)aRenders 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.
        )rvr9)r
rkr8rSrMrrrencode_contentss
zTag.encode_contentsrcCs|sd}|j||dS)z(Deprecated method for BS3 compatibility.N)rkr8)r)r
r8prettyPrintindentLevelrrrrenderContentss
zTag.renderContentsTcKs.d}|j||||dfi|}|r|d}|S)aLook 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.Tag | bs4.element.NavigableString
        Nr>rrS)r
r'r	recursiverrrrrrrr\s
zTag.findcKs*|j}|s|j}|j|||||fi|S)aLook 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
        )r5childrenr)r
r'rrrrrrrrrrT7szTag.find_allcCrI)zkIterate over all direct children of this PageElement.

        :yield: A sequence of PageElements.
        rJrrrrrQs
zTag.childrenccsHt|jsdS|j}|jd}||ur"|V|j}||usdSdS)zIterate over all children of this PageElement in a
        breadth-first sequence.

        :yield: A sequence of PageElements.
        Nr)rprMrrJ)r
stopNodecurrentrrrr5Zs


zTag.descendantscKs&|j||dfi|}|r|dSdS)aPerform 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 Tag.
        :rtype: bs4.element.Tag
        r>rN)select)r
selector
namespacesrrrrr
select_onejszTag.select_onecKsL|dur|j}|dur
d}tdurtdtj||||fi|}td|S)aPerform 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 Tags.
        :rtype: bs4.element.ResultSet
        NrzLCannot execute CSS selectors because the soupsieve package is not installed.)_namespaces	soupsiever\rr)r
rrrrrrrrrs
z
Tag.selectcCrzDeprecated generator.)rrrrrchildGeneratorzTag.childGeneratorcCrr)r5rrrrrecursiveChildGeneratorrzTag.recursiveChildGeneratorcCstd|||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.)rZr[rErDrrrhas_keys
zTag.has_key)NNNNNNNNNNNNNNN)Fr	)r )Nrr+)?r,r-r.r/r1rparserClassrrr3
isSelfClosingrarrrr	rFrr_rr:r4r;rrr?rArErFrGrLrMrNrOrPrRrUrrarbrfrgrhrdrr9rerurrvrrr\	findChildrTfindAllfindChildrenrr5rrrrrrrrrrxs
p


$
&




e

/







%rc@sTeZdZdZdidfddZddZddZdifd	d
ZeZddZ	dd
dZ
dS)ra&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.
    NcKs|||_t|ts||d<d}d|vr|d|d<|d=|r.|r,|}||n|}i}t|D]\}}||||<q6||_|||_	dS)aConstructor.

        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.
        classNclass_)
_normalize_search_valuer'rOr(copyupdateritemsrr)r
r'rrrnormalized_attrsr@rrrrr1s"
zSoupStrainer.__init__cCst|tst|tst|dst|ts|dur|St|tr$|dSt|drOg}|D]}t|drDt|tsDt|tsD||q-|||q-|Stt|S)Nr=utf8rL)	rOr$rrboolbytesrerr)r
r	new_valuevrrrrs"


z$SoupStrainer._normalize_search_valuecCs|jr|jSd|j|jfS)z5A human-readable representation of this SoupStrainer.z%s|%s)rr'rrrrrrhszSoupStrainer.__str__c
Cs8d}d}t|tr
|}|}t|jtr |r |js |j|jkr dSt|jto+t|t}|jrC|sC|r:|||jsC|s|||jr|rL|||}n6d}d}t|j	D]*\}}	|srt
|dre|}n
i}|D]\}
}|||
<qi||}|||	sd}nqW|r|r|}n|}|r|jr||j
|jsd}|S)aCheck 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.
        NFTr?)rOrr'r$r&r_matchesrrrrr?rra)
r
markup_namemarkup_attrsrmarkupcall_function_with_tag_datar=markup_attr_mapr
match_againstkr
attr_valuerrr
search_tagsZ





zSoupStrainer.search_tagcCsd}t|dr$t|ttfs$|D]}t|tr!||r!|}|Sq|St|tr9|jr2|js2|jr7|	|}|St|tsCt|trT|jsR|jsR|
||jrR|}|Std|j)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.
        NrLz&I don't know how to match against a %s)
rrOrr$rr<rr'rrr	Exceptionr)r
rrrrrrr<Ks0	


	
zSoupStrainer.searchc	Csfd}t|tst|tr'|D]}|||rdSq|d||r%dSdS|dur/|duSt|tr8||S|}t|trB|j}||}|durN|St	|drt|t
s|s]t}|D] }|jrg|}nt
|}||vrpq_||||||rdSq_dSd}|st|t
r||k}|st	|dr||S|st|tr|jr||jd|j|S|S)NFTrmrLr<r#)rOrrqrrerrr'rrr$setrFidaddr<r&)	r
rr
already_triedritemoriginal_markupr@r=rrrrlsb





zSoupStrainer._matchesr	)r,r-r.r/r1rrhr	searchTagr<rrrrrrs	&=!rcs*eZdZdZdfdd	ZddZZS)rzTA ResultSet is just a list that keeps track of the SoupStrainer
    that created it.rcstt||||_dS)zlConstructor.

        :param source: A SoupStrainer.
        :param result: A list of PageElements.
        N)superrr1source)r
rrrrrr1s
zResultSet.__init__cCstd|)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()?rrDrrrrszResultSet.__getattr__)r)r,r-r.r/r1r
__classcell__rrrrrs	r).__license__collections.abcrImportErrorecollectionsrCsysrZrr[
bs4.formatterrrrrversion_infordrDnonwhitespace_re
whitespace_rerrr6r$r"r1r3r:rrFrrrrrrrrrr r!rrrrrrrrsv

t			E