; Fc@sdZdklZdZdZdZdZdklZl Z dk Z dk Z dk Z dkZydk lZWnej o hZnXe id e_d Zd fd YZd eefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdfdYZdefdYZdZdZdZ d eefd!YZ!d"e!fd#YZ"d$e#fd%YZ$d&e"fd'YZ%d(e"fd)YZ&d*e!fd+YZ'd,e!fd-YZ(d.e"fd/YZ)d0e%fd1YZ*d2e&fd3YZ+d4e'fd5YZ,y dk-Z-Wn e.Z-nXe.Z-y dk/Z0WnnXy dk1Z1WnnXd6fd7YZ2e3d8jo-dk4Z4e"e4i5i6Z7e7i8GHndS(9sBeautiful Soup Elixir and Tonic "The Screen-Scraper's Friend" http://www.crummy.com/software/BeautifulSoup/ Beautiful Soup parses a (possibly invalid) XML or HTML document into a tree representation. It provides methods and Pythonic idioms that make it easy to navigate, search, and modify the tree. A well-formed XML/HTML document yields a well-formed data structure. An ill-formed XML/HTML document yields a correspondingly ill-formed data structure. If your document is only locally well-formed, you can use this library to find and process the well-formed part of it. The BeautifulSoup class Beautiful Soup works with Python 2.2 and up. It has no external dependencies, but you'll have more success at converting data to UTF-8 if you also install these three packages: * chardet, for auto-detecting character encodings http://chardet.feedparser.org/ * cjkcodecs and iconv_codec, which add more encodings to the ones supported by stock Python. http://cjkpython.i18n.org/ Beautiful Soup defines classes for two main parsing strategies: * BeautifulStoneSoup, for parsing XML, SGML, or your domain-specific language that kind of looks like XML. * BeautifulSoup, for parsing run-of-the-mill HTML code, be it valid or invalid. This class has web browser-like heuristics for obtaining a sensible parse tree in the face of common HTML errors. Beautiful Soup also defines a class (UnicodeDammit) for autodetecting the encoding of an HTML or XML document, and converting it to Unicode. Much of this code is taken from Mark Pilgrim's Universal Feed Parser. For more than you ever wanted to know about Beautiful Soup, see the documentation: http://www.crummy.com/software/BeautifulSoup/documentation.html (s generatorss*Leonard Richardson (leonardr@segfault.org)s3.0.4s*Copyright (c) 2004-2007 Leonard RichardsonsPSF(s SGMLParsersSGMLParseErrorN(sname2codepoints[a-zA-Z][-_.:a-zA-Z0-9]*sutf-8s PageElementcBsmtZdZeedZdZdZdZdZehedZ eheedZ ehedZ eheed Z e Z ehed Zeheed ZeZehed Zeheed ZeZehdZehedZeZdZdZdZdZdZdZdZedZedZRS(seContains the navigational information for some part of the page (either a tag or a piece of text)cCsk||_||_t|_t|_t|_|io |iio#|iid|_||i_ndS(sNSets up the initial relations between this element and other elements.iN(sparentsselfsprevioussNonesnextspreviousSiblings nextSiblingscontents(sselfsparentsprevious((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyssetupHs     cCs|i}|iii|}t|do|i|ijo;|iii|}|o ||jo|d}q|n|i|i ||dS(Nsparenti( sselfsparents oldParentscontentssindexsmyIndexshasattrs replaceWithsextractsinsert(sselfs replaceWithsindexs oldParentsmyIndex((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys replaceWithTs # cCs|io1y|iii|Wq;tj oq;Xn|i}|i}|i o||i _n|o|i |_ nt |_ t |_t |_|i o|i |i _ n|i o|i |i _ nt |_ |_ dS(s0Destructively rips this element out of the tree.N( sselfsparentscontentssremoves ValueErrors_lastRecursiveChilds lastChildsnexts nextElementsprevioussNonespreviousSiblings nextSibling(sselfs lastChilds nextElement((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysextractbs(          cCs=|}x,t|do|io|id}q W|SdS(s8Finds the last element beneath this object to be parsed.scontentsiN(sselfs lastChildshasattrscontents(sselfs lastChild((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys_lastRecursiveChild~s c Cs>t|tp t|tot|t ot|}nt|t|i }t |do |i t joS|i |jo5|i |}|o ||jo|d}qn|in||_ t }|djot |_||_n6|i |d}||_||i_|i|_|io||i_n|i}|t|i joet |_|}t }x,| o#|i}|i }| oPqqW|o ||_q t |_n:|i |}||_|io||i_n||_|io||i_n|i i||dS(Nsparentii(s isinstancesnewChilds basestringsunicodesNavigableStringsminspositionslensselfscontentsshasattrsparentsNonesfindsindexsextracts previousChildspreviousSiblingspreviouss nextSiblings_lastRecursiveChildsnextsnewChildsLastElementsparentsNextSiblings nextChildsinsert( sselfspositionsnewChildsparentsNextSiblingsindexsnewChildsLastElementsparents previousChilds nextChild((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysinsertsT1                    cKs |i|i||||SdS(sjReturns the first item that matches the given criteria and appears after this Tag in the document.N(sselfs_findOnes findAllNextsnamesattrsstextskwargs(sselfsnamesattrsstextskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindNextscKs |i|||||iSdS(sdReturns all items that match the given criteria and appear before after Tag in the document.N(sselfs_findAllsnamesattrsstextslimits nextGenerator(sselfsnamesattrsstextslimitskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys findAllNextscKs |i|i||||SdS(s{Returns the closest sibling to this Tag that matches the given criteria and appears after this Tag in the document.N(sselfs_findOnesfindNextSiblingssnamesattrsstextskwargs(sselfsnamesattrsstextskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindNextSiblingscKs#|i|||||i|SdS(sqReturns the siblings of this Tag that match the given criteria and appear after this Tag in the document.N(sselfs_findAllsnamesattrsstextslimitsnextSiblingGeneratorskwargs(sselfsnamesattrsstextslimitskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindNextSiblingsscKs |i|i||||SdS(skReturns the first item that matches the given criteria and appears before this Tag in the document.N(sselfs_findOnesfindAllPrevioussnamesattrsstextskwargs(sselfsnamesattrsstextskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys findPreviousscKs#|i|||||i|SdS(scReturns all items that match the given criteria and appear before this Tag in the document.N(sselfs_findAllsnamesattrsstextslimitspreviousGeneratorskwargs(sselfsnamesattrsstextslimitskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindAllPreviousscKs |i|i||||SdS(s|Returns the closest sibling to this Tag that matches the given criteria and appears before this Tag in the document.N(sselfs_findOnesfindPreviousSiblingssnamesattrsstextskwargs(sselfsnamesattrsstextskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindPreviousSiblingscKs#|i|||||i|SdS(srReturns the siblings of this Tag that match the given criteria and appear before this Tag in the document.N(sselfs_findAllsnamesattrsstextslimitspreviousSiblingGeneratorskwargs(sselfsnamesattrsstextslimitskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindPreviousSiblingsscKs8t}|i||d}|o|d}n|SdS(sOReturns the closest parent of this Tag that matches the given criteria.iiN(sNonesrsselfs findParentssnamesattrssl(sselfsnamesattrsskwargsslsr((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys findParents cKs#|i||t||i|SdS(sFReturns the parents of this Tag that match the given criteria.N(sselfs_findAllsnamesattrssNoneslimitsparentGeneratorskwargs(sselfsnamesattrsslimitskwargs((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys findParentsscKs;t}||||d|}|o|d}n|SdS(Nii(sNonesrsmethodsnamesattrsstextskwargssl(sselfsmethodsnamesattrsstextskwargsslsr((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys_findOne s c Kst|to |} nt||||} t| }|} xt o|y| i }Wntj oPnX|oJ| i|} | o0|i| |ot||joPqqqGqGW|SdS(s8Iterates over a generator looking for things that match.N(s isinstancesnames SoupStrainersstrainersattrsstextskwargss ResultSetsresultss generatorsgsTruesnextsis StopIterationssearchsfoundsappendslimitslen( sselfsnamesattrsstextslimits generatorskwargssisresultssgsfoundsstrainer((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys_findAlls&    ccs&|}x|o|i}|Vq WdS(N(sselfsisnext(sselfsi((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys nextGenerator*s  ccs&|}x|o|i}|Vq WdS(N(sselfsis nextSibling(sselfsi((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysnextSiblingGenerator0s  ccs&|}x|o|i}|Vq WdS(N(sselfsisprevious(sselfsi((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyspreviousGenerator6s  ccs&|}x|o|i}|Vq WdS(N(sselfsispreviousSibling(sselfsi((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyspreviousSiblingGenerator<s  ccs&|}x|o|i}|Vq WdS(N(sselfsisparent(sselfsi((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysparentGeneratorBs  cCs!|pd}|id|SdS(Nsutf-8s%SOUP-ENCODING%(sencodingsstrsreplace(sselfsstrsencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyssubstituteEncodingIs cCst|to|o|i|}qnjt|to*|o|i|}qt|}n0|o|it||}n t|}|SdS(sHEncodes an object to a string in some encoding, or to Unicode. .N(s isinstancesssunicodesencodingsencodesstrsselfs toEncoding(sselfsssencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys toEncodingMs ( s__name__s __module__s__doc__sNonessetups replaceWithsextracts_lastRecursiveChildsinsertsfindNexts findAllNextsfindNextSiblingsfindNextSiblingssfetchNextSiblingss findPrevioussfindAllPreviouss fetchPrevioussfindPreviousSiblingsfindPreviousSiblingssfetchPreviousSiblingss findParents findParentss fetchParentss_findOnes_findAlls nextGeneratorsnextSiblingGeneratorspreviousGeneratorspreviousSiblingGeneratorsparentGeneratorssubstituteEncodings toEncoding(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys PageElementDs:     <         sNavigableStringcBs&tZdZdZedZRS(NcCs2|djo|Sntd|ii|fdS(stext.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.sstrings!'%s' object has no attribute '%s'N(sattrsselfsAttributeErrors __class__s__name__(sselfsattr((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys __getattr__as cCs|itSdS(N(sselfs__str__sNone(sself((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys __unicode__jscCs |o|i|Sn|SdS(N(sencodingsselfsencode(sselfsencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__str__ms(s__name__s __module__s __getattr__s __unicode__sDEFAULT_OUTPUT_ENCODINGs__str__(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysNavigableString_s sCDatacBstZedZRS(NcCsdti||SdS(Ns(sNavigableStrings__str__sselfsencoding(sselfsencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__str__us(s__name__s __module__sDEFAULT_OUTPUT_ENCODINGs__str__(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysCDatasssProcessingInstructioncBstZedZRS(NcCsA|}d|jo|i||}nd|i||SdS(Ns%SOUP-ENCODING%s(sselfsoutputssubstituteEncodingsencodings toEncoding(sselfsencodingsoutput((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__str__ys (s__name__s __module__sDEFAULT_OUTPUT_ENCODINGs__str__(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysProcessingInstructionxssCommentcBstZedZRS(NcCsdti||SdS(Ns (sNavigableStrings__str__sselfsencoding(sselfsencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__str__s(s__name__s __module__sDEFAULT_OUTPUT_ENCODINGs__str__(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysCommentss DeclarationcBstZedZRS(NcCsdti||SdS(Ns(sNavigableStrings__str__sselfsencoding(sselfsencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__str__s(s__name__s __module__sDEFAULT_OUTPUT_ENCODINGs__str__(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys DeclarationssTagcBstZdZhdd<dd<dd<dd<d d sgtcCsv|i|_|i||_||_|tjo g}n||_g|_ |i ||t |_t |_dS(sBasic constructor.N(sparsers __class__sselfs parserClasssisSelfClosingTagsnames isSelfClosingsattrssNonescontentsssetupsparentsprevioussFalseshiddenscontainsSubstitutions(sselfsparsersnamesattrssparentsprevious((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__init__s       cCs|ii||SdS(sReturns the value of the 'key' attribute for the tag, or the value given for 'default' if it doesn't have that attribute.N(sselfs _getAttrMapsgetskeysdefault(sselfskeysdefault((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysgetscCs|ii|SdS(N(sselfs _getAttrMapshas_keyskey(sselfskey((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyshas_keyscCs|i|SdS(sqtag[key] returns the value of the 'key' attribute for the tag, and throws an exception if it's not there.N(sselfs _getAttrMapskey(sselfskey((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys __getitem__scCst|iSdS(s0Iterating over a tag iterates over its contents.N(sitersselfscontents(sself((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__iter__scCst|iSdS(s:The length of a tag is the length of its list of contents.N(slensselfscontents(sself((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__len__scCs||ijSdS(N(sxsselfscontents(sselfsx((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys __contains__scCstSdS(s-A tag is non-None even if it has no contents.N(sTrue(sself((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys __nonzero__scCs|i||i|]|&(?![^\s]+;))cs di|idddS(Ns&is;(sselfsXML_SPECIAL_CHARS_TO_ENTITIESsxsgroup(sx(sself(sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys,sss /sis is<%s%s%s>s iN(sselfs toEncodingsnamesencodings encodedNamesattrsskeysvalsfmtsisStringscontainsSubstitutionsssubstituteEncodingsreplacesressubsappendsclosescloseTags isSelfClosings indentTagsindentContentss prettyPrints indentLevelsspacesrenderContentsscontentsshiddensssattributeStringsjoins nextSibling(sselfsencodings prettyPrints indentLevels encodedNamesvalsattributeStrings indentTagscloseTagsspacesssattrsskeysclosesindentContentssfmtscontents((sselfsQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__str__sd        7       cCs|i|tSdS(N(sselfs__str__sencodingsTrue(sselfsencoding((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysprettifyUscCsg}x|D]}t}t|to|i|}n1t|t o |i |i|||n|o|o|i }n|oI|o|i d|dn|i ||o|i dqq q Wdi|SdS(s{Renders the contents of this tag as a string in the given encoding. If encoding is None, returns a Unicode string..s is sN(sssselfscsNonestexts isinstancesNavigableStrings__str__sencodingsTagsappends prettyPrints indentLevelsstripsjoin(sselfsencodings prettyPrints indentLevelscstextss((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysrenderContentsXs$  cKsAt}|i||||d|}|o|d}n|SdS(sLReturn only the first child of this Tag matching the given criteria.iiN( sNonesrsselfsfindAllsnamesattrss recursivestextskwargssl(sselfsnamesattrss recursivestextskwargsslsr((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindos cKs>|i}| o |i}n|i||||||SdS(sExtracts a list of Tag objects that match the given criteria. You can specify the name of the Tag and any attributes you want the Tag to have. The value of a key-value pair in the 'attrs' map can be a string, a list of strings, a regular expression object, or a callable that takes a string and returns whether or not the string matches for some custom definition of 'matches'. The same is true of the tag name.N( sselfsrecursiveChildGenerators generators recursiveschildGenerators_findAllsnamesattrsstextslimitskwargs(sselfsnamesattrss recursivestextslimitskwargss generator((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysfindAllzs   cCs |id|d|d|SdS(Nstexts recursiveslimit(sselfsfindAllstexts recursiveslimit(sselfstexts recursiveslimit((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys fetchTextscCs|id|d|SdS(Nstexts recursive(sselfsfindstexts recursive(sselfstexts recursive((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys firstTextscCs|ii|dS(s2Appends the given tag to the contents of this tag.N(sselfscontentssappendstag(sselfstag((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysappendscCsPt|d o4h|_x(|iD]\}}||i|" actually means "". [Another possible explanation is "", but since this class defines no SELF_CLOSING_TAGS, it will never use that explanation.] This class is useful for parsing XML or made-up markup languages, or when BeautifulSoup makes an assumption counter to what you were expecting.s (<[^<>]*)/>cCs|iddS(Nis />(sxsgroup(sx((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys{ss]*)>cCsd|iddS(Ns(sxsgroup(sx((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys}su [document]shtmlsxmlscCs||_||_||_||_|io t|_ntt||_t i |t |do|i }n||_ ||_y|iWntj onXt|_ dS(sWThe Soup object is initialized as the 'root tag', and the provided markup (which can be a string or a file-like object) is fed into the underlying parser. sgmllib will process most bad HTML, and the BeautifulSoup class has some tricks for dealing with some HTML that kills sgmllib, but Beautiful Soup can nonetheless choke or lose data if your data uses self-closing tags or declarations incorrectly. By default, Beautiful Soup uses regexes to sanitize input, avoiding the vast majority of these problems. If the problems don't apply to you, pass in False for markupMassage, and you'll get better performance. The default parser massage techniques fix the two most common instances of invalid HTML that choke sgmllib:
(No space between name of closing tag and tag close) (Extraneous whitespace in declaration) You can pass in a custom list of (RE object, replace method) tuples to get Beautiful Soup to scrub your input the way you want.sreadN(sparseOnlyThesesselfs fromEncodings smartQuotesTosconvertEntitiessNones buildTagMapsselfClosingTagssinstanceSelfClosingTagss SGMLParsers__init__shasattrsmarkupsreads markupMassages_feeds StopParsing(sselfsmarkupsparseOnlyTheses fromEncodings markupMassages smartQuotesTosconvertEntitiessselfClosingTags((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys__init__s$         cCs'|i}t|to"t|d o t|_qqn7t||i|gd|i }|i}|i|_|o_|i oQt |i  o|i|_ nx-|i D]\}}|i||}qWqn|iti|||ix%|ii|ijo|iqWdS(NsoriginalEncodings smartQuotesTo(sselfsmarkups isinstancesunicodeshasattrsNonesoriginalEncodings UnicodeDammits fromEncodingsinDocumentEncodings smartQuotesTosdammits markupMassagesisListsMARKUP_MASSAGEsfixsmssubsresets SGMLParsersfeedsendDatas currentTagsnames ROOT_TAG_NAMEspopTag(sselfsinDocumentEncodingsmsdammitsfixsmarkup((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys_feeds*       cCs|iddjp)|iddjp|iddjoti||Sn1|iddjoti||SntdS(sThis method routes method call requests to either the SGMLParser superclass or the Tag superclass, depending on the method name.sstart_isend_sdo_s__N(s methodNamesfinds SGMLParsers __getattr__sselfsTagsAttributeError(sselfs methodName((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys __getattr__s BcCs'|ii|p|ii|SdS(seReturns true iff the given string is the name of a self-closing tag according to this parser.N(sselfsSELF_CLOSING_TAGSshas_keysnamesinstanceSelfClosingTags(sselfsname((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysisSelfClosingTagscCsati|||id|_ti|g|_t|_ g|_ g|_ |i |dS(Ni( sTags__init__sselfs ROOT_TAG_NAMEshiddens SGMLParsersresets currentDatasNones currentTagstagStacks quoteStackspushTag(sself((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysresets      cCs|ii}t|iidjot|iidto|iid|i_ n|io|id|_n|iSdS(Niii( sselfstagStackspopstagslens currentTagscontentss isinstancesNavigableStringsstring(sselfstag((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyspopTags 3 cCsB|io|ii|n|ii||id|_dS(Ni(sselfs currentTagsappendstagstagStack(sselfstag((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyspushTags cCs|iodi|i}|i o!d|jo d}qKd}ng|_|io5t|idjo|ii p|ii| odSn||}|i |i |i |i o||i _n||_ |i ii|ndS(Nss s i(sselfs currentDatasjoinsstripsparseOnlyTheseslenstagStackstextssearchscontainerClasssossetups currentTagsprevioussnextscontentssappend(sselfscontainerClasssos currentData((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysendDatas     B   cCs||ijodSnd}t}xVtt|idddD]5}||i|ijot|i|}PqDqDW| o|d}nx#td|D]}|i }qW|SdS(sPops the tag stack up to and including the most recent instance of the given tag. If inclusivePop is false, pops the tag stack up to but *not* including the most recent instqance of the given tag.Niii( snamesselfs ROOT_TAG_NAMEsnumPopssNones mostRecentTagsrangeslenstagStacksis inclusivePopspopTag(sselfsnames inclusivePopsnumPopssis mostRecentTag((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys _popToTags   c Cs!|ii|}|tj}|ii|}t}t }xt t|idddD]}|i|}| p |i|jo| o |}Pn|tjo |i|jp'|tjo|o|ii|io|i}t}Pn|i}q\W|o|i||ndS(s We need to pop up to the previous tag of this type, unless one of this tag's nesting reset triggers comes between this tag and the previous tag of this type, OR unless this tag is a generic nesting trigger and another generic nesting trigger comes between this tag and the previous tag of this type. Examples:

FooBar

should pop to 'p', not 'b'.

FooBar

should pop to 'table', not 'p'.

Foo

Bar

should pop to 'tr', not 'p'.

FooBar

should pop to 'p', not 'b'.

    • *
    • * should pop to 'ul', not the first 'li'.
  • ** should pop to 'table', not the first 'tr' tag should implicitly close the previous tag within the same
    ** should pop to 'tr', not the first 'td' iiiN(sselfs NESTABLE_TAGSsgetsnamesnestingResetTriggerssNones isNestablesRESET_NESTING_TAGSshas_keysisResetNestingspopTosTrues inclusivesrangeslenstagStacksispsFalsesparents _popToTag( sselfsnamesps inclusivesis isNestablespopTosnestingResetTriggerssisResetNesting((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys _smartPop.s&    G  icCsl|io:ditd|}|id||fdSn|i|i| o| o|i |n|i o7t |i djo!|i ip|i i|| odSnt||||i|i}|io||i_n||_|i||p |i|o|in||ijo|ii|d|_n|SdS(NscCs|\}}d||fS(Ns %s="%s"(sxsy(s.0sxsy((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysbss<%s%s>i(sselfs quoteStacksjoinsmapsattrss handle_datasnamesendDatasisSelfClosingTags selfClosings _smartPopsparseOnlyTheseslenstagStackstexts searchTagsTags currentTagspreviousstagsnextspushTagspopTags QUOTE_TAGSsappendsliteral(sselfsnamesattrss selfClosingstag((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysunknown_starttag]s(  D    cCs|io|id|jo|id|dSn|i|i||io|id|jo)|iit|idj|_ndS(Nisi( sselfs quoteStacksnames handle_datasendDatas _popToTagspopslensliteral(sselfsname((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysunknown_endtag{s   cCs|ii|dS(N(sselfs currentDatasappendsdata(sselfsdata((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys handle_datascCs(|i|i||i|dS(sOAdds a certain piece of text to the tree as a NavigableString subclass.N(sselfsendDatas handle_datastextssubclass(sselfstextssubclass((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys_toStringSubclasss  cCs/|d djo d}n|i|tdS(sHandle a processing instruction as a ProcessingInstruction object, possibly one with a %SOUP-ENCODING% slot into which an encoding will be plugged later.isxmls,xml version='1.0' encoding='%SOUP-ENCODING%'N(stextsselfs_toStringSubclasssProcessingInstruction(sselfstext((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys handle_pis cCs|i|tdS(s#Handle comments as Comment objects.N(sselfs_toStringSubclassstextsComment(sselfstext((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyshandle_commentscCsM|i|i|igjott|}n d|}|i|dS(s$Handle character references as data.s&#%s;N( sselfsconvertEntitiess HTML_ENTITIESs XML_ENTITIESsunichrsintsrefsdatas handle_data(sselfsrefsdata((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyshandle_charrefs  cCst}|i|ijp#|i|ijo|ii|o.yt t |}Wqmt j oqmXn| od|}n|i |dS(sHandle entity references as data, possibly converting known HTML entity references to the corresponding Unicode characters.s&%s;N( sNonesdatasselfsconvertEntitiess HTML_ENTITIESs XML_ENTITIESsXML_ENTITY_LISTsgetsrefsunichrsname2codepointsKeyErrors handle_data(sselfsrefsdata((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pyshandle_entityrefs9 cCs|i|tdS(s4Handle DOCTYPEs and the like as Declaration objects.N(sselfs_toStringSubclasssdatas Declaration(sselfsdata((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys handle_declscCst}|i||d!djog|iid|}|djot|i}n|i|d|!}|d}|i |t nWyt i ||}Wn=t j o1|i|}|i||t|}nX|SdS(s`Treat a bogus SGML declaration as raw data. Treat a CDATA declaration as a CData object.i s iiN(sNonesjsselfsrawdatasisfindskslensdatas_toStringSubclasssCDatas SGMLParsersparse_declarationsSGMLParseErrorstoHandles handle_data(sselfsisksjstoHandlesdata((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysparse_declarations     ()s__name__s __module__s__doc__sXML_ENTITY_LISTsTagsXML_SPECIAL_CHARS_TO_ENTITIESsvaluessisTruesSELF_CLOSING_TAGSs NESTABLE_TAGSsRESET_NESTING_TAGSs QUOTE_TAGSsrescompilesMARKUP_MASSAGEs ROOT_TAG_NAMEs HTML_ENTITIESs XML_ENTITIESsNones__init__s_feeds __getattr__sisSelfClosingTagsresetspopTagspushTagsNavigableStringsendDatas _popToTags _smartPopsunknown_starttagsunknown_endtags handle_datas_toStringSubclasss handle_pishandle_commentshandle_charrefshandle_entityrefs handle_declsparse_declaration(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysBeautifulStoneSoup_sB 02       /       s BeautifulSoupc BstZdZdZeedddddddd d g Zhd e tag should implicitly close the previous

    tag.

    Para1

    Para2 should be transformed into:

    Para1

    Para2 Some tags can be nested arbitrarily. For instance, the occurance of a

    tag should _not_ implicitly close the previous
    tag. Alice said:
    Bob said:
    Blah should NOT be transformed into: Alice said:
    Bob said:
    Blah Some tags can be nested, but the nesting is reset by the interposition of other tags. For instance, a
    , but not close a tag in another table.
    BlahBlah should be transformed into:
    BlahBlah but, Blah
    Blah should NOT be transformed into Blah
    Blah Differing assumptions about tag nesting rules are a major source of problems with the BeautifulSoup class. If BeautifulSoup is not treating as nestable a tag your page author treats as nestable, try ICantBelieveItsBeautifulSoup, MinimalSoup, or BeautifulStoneSoup before writing your own subclass.cOs9|id o|i|dQsismetaN(sNones httpEquivs contentTypescontentTypeIndexsFalsestagNeedsEncodingSubstitutionsrangeslensattrssiskeysvalueslowersselfs CHARSET_REssearchsmatchsgetattrsoriginalEncodings fromEncodingssubsnewAttrsTruesgroups newCharsetsdeclaredHTMLEncodings_feeds StopParsingsunknown_starttagstagscontainsSubstitutions( sselfsattrsscontentTypeIndexs contentTypestagNeedsEncodingSubstitutionsis newCharsetstagsnewAttrs httpEquivskeysvaluesmatch((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys start_meta6s<    #   (s__name__s __module__s__doc__s__init__s buildTagMapsNonesSELF_CLOSING_TAGSs QUOTE_TAGSsNESTABLE_INLINE_TAGSsNESTABLE_BLOCK_TAGSsNESTABLE_LIST_TAGSsNESTABLE_TABLE_TAGSsNON_NESTABLE_BLOCK_TAGSsRESET_NESTING_TAGSs NESTABLE_TAGSsrescompiles CHARSET_REs start_meta(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys BeautifulSoups$ . $H`     s StopParsingcBstZRS(N(s__name__s __module__(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pys StopParsingbssICantBelieveItsBeautifulSoupcBshtZdZddddddddd d d d d ddddgZdgZegeieeZRS(syThe BeautifulSoup class is oriented towards skipping over common HTML errors like unclosed tags. However, sometimes it makes errors of its own. For instance, consider this fragment: FooBar This is perfectly valid (if bizarre) HTML. However, the BeautifulSoup class will implicitly close the first b tag when it encounters the second 'b'. It will think the author wrote "FooBar", and didn't close the first 'b' tag, because there's no real-world reason to bold something that's already bold. When it encounters '' it will close two more 'b' tags, for a grand total of three tags closed instead of two. This can throw off the rest of your document structure. The same is true of a number of other tags, listed below. It's much more common for someone to forget to close a 'b' tag than to actually use nested 'b' tags, and the BeautifulSoup class handles the common case. This class handles the not-co-common case: where you can't believe someone wrote what they did, but it's valid HTML and BeautifulSoup screwed up by assuming it wouldn't be.semsbigsissmallsttsabbrsacronymsstrongscitescodesdfnskbdssampsvarsbsnoscript(s__name__s __module__s__doc__s*I_CANT_BELIEVE_THEYRE_NESTABLE_INLINE_TAGSs)I_CANT_BELIEVE_THEYRE_NESTABLE_BLOCK_TAGSs buildTagMaps BeautifulSoups NESTABLE_TAGS(((sQ/mnt/gmirror/ports/www/py-beautifulsoup/work/BeautifulSoup-3.0.4/BeautifulSoup.pysICantBelieveItsBeautifulSoupes 9  s MinimalSoupcBs tZdZedZhZRS(sThe MinimalSoup class is for parsing HTML that contains pathologically bad markup. It makes no assumptions about tag nesting, but it does know which tags are self-closing, that