Ñò ûãtHc@sâdZddklZyeWn#ej oddklZnXddkZddkl Z l Z l Z l Z l Z lZddklZlZlZlZlZlZlZlZlZlZlZlZddd d d d d gZdZdddd„Zdd„Zd e fd„ƒYZ!d e fd„ƒYZ"d e"fd„ƒYZ#d e#fd„ƒYZ$d e fd„ƒYZ%de fd„ƒYZ&e&i'Z'de fd„ƒYZ(de fd„ƒYZ)de fd„ƒYZ*dS( sUThis module provides different kinds of serialization methods for XML event streams. iÿÿÿÿ(tchain(t ImmutableSetN(tescapetAttrstMarkupt NamespacetQNametStreamEventKind( tSTARTtENDtTEXTtXML_DECLtDOCTYPEtSTART_NStEND_NSt START_CDATAt END_CDATAtPItCOMMENTt XML_NAMESPACEtencodetget_serializertDocTypet XMLSerializertXHTMLSerializertHTMLSerializertTextSerializersrestructuredtext entxmlsutf-8cs©ˆdj oDd‰|djot|tƒ o d‰n‡‡fd†}n d„}|djo|dit|ƒƒƒSx!|D]}|i||ƒƒqˆWdS(sßEncode serializer output into a string. :param iterator: the iterator returned from serializing a stream (basically any iterator that yields unicode objects) :param method: the serialization method; determines how characters not representable in the specified encoding are treated :param encoding: how the output string should be encoded; if set to `None`, this method returns a `unicode` object :param out: a file-like object that the output should be written to instead of being returned as one big string; note that if this is a file or socket (or similar), the `encoding` must not be `None` (that is, the output must be encoded) :return: a `str` or `unicode` object (depending on the `encoding` parameter), or `None` if the `out` parameter is provided :since: version 0.4.1 :note: Changed in 0.5: added the `out` parameter treplacettexttxmlcharrefreplacecs|iˆˆƒS((R(tstring(terrorstencoding(s3/usr/lib64/python2.6/site-packages/genshi/output.pyt8scSs|S(((R((s3/usr/lib64/python2.6/site-packages/genshi/output.pyR":suN(tNonet isinstanceRtjointlisttwrite(titeratortmethodR!toutt_encodetchunk((R R!s3/usr/lib64/python2.6/site-packages/genshi/output.pyR!s    cKsJt|tƒo0htd6td6td6td6|iƒ}n||S(s®Return a serializer object for the given method. :param method: the serialization method; can be either "xml", "xhtml", "html", "text", or a custom serializer class Any additional keyword arguments are passed to the serializer, and thus depend on the `method` parameter value. :see: `XMLSerializer`, `XHTMLSerializer`, `HTMLSerializer`, `TextSerializer` :since: version 0.4.1 RtxhtmlthtmlR(R$t basestringRRRRtlower(R)tkwargs((s3/usr/lib64/python2.6/site-packages/genshi/output.pyR@s  cBsweZdZdZdZdZeZdZdZ dZ dZ e Z d Z d!Zd"Zd#ZeZd„ZeeƒZRS($sDDefines a number of commonly used DOCTYPE declarations as constants.R.s-//W3C//DTD HTML 4.01//ENs%http://www.w3.org/TR/html4/strict.dtds&-//W3C//DTD HTML 4.01 Transitional//ENs$http://www.w3.org/TR/html4/loose.dtds"-//W3C//DTD HTML 4.01 Frameset//ENs'http://www.w3.org/TR/html4/frameset.dtds -//W3C//DTD XHTML 1.0 Strict//ENs1http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtds&-//W3C//DTD XHTML 1.0 Transitional//ENs7http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtds"-//W3C//DTD XHTML 1.0 Frameset//ENs3http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtds-//W3C//DTD XHTML 1.1//ENs,http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtdtsvgs-//W3C//DTD SVG 1.1//ENs0http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtds-//W3C//DTD SVG Basic 1.1//ENs6http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtds-//W3C//DTD SVG Tiny 1.1//ENs5http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtdcCsŸh|id6|id6tid6tid6|id6|id6|id6|id6|i d 6|i d 6|i d 6|i d 6|i d 6|id6i|iƒƒS(sReturn the ``(name, pubid, sysid)`` tuple of the ``DOCTYPE`` declaration for the specified name. The following names are recognized in this version: * "html" or "html-strict" for the HTML 4.01 strict DTD * "html-transitional" for the HTML 4.01 transitional DTD * "html-frameset" for the HTML 4.01 frameset DTD * "html5" for the ``DOCTYPE`` proposed for HTML5 * "xhtml" or "xhtml-strict" for the XHTML 1.0 strict DTD * "xhtml-transitional" for the XHTML 1.0 transitional DTD * "xhtml-frameset" for the XHTML 1.0 frameset DTD * "xhtml11" for the XHTML 1.1 DTD * "svg" or "svg-full" for the SVG 1.1 DTD * "svg-basic" for the SVG Basic 1.1 DTD * "svg-tiny" for the SVG Tiny 1.1 DTD :param name: the name of the ``DOCTYPE`` :return: the ``(name, pubid, sysid)`` tuple for the requested ``DOCTYPE``, or ``None`` if the name is not recognized :since: version 0.4.1 R.s html-strictshtml-transitionals html-framesetthtml5R-s xhtml-strictsxhtml-transitionalsxhtml-framesettxhtml11R2ssvg-fulls svg-basicssvg-tiny(tHTMLt HTML_STRICTRtHTML_TRANSITIONALt HTML_FRAMESETtHTML5tXHTMLt XHTML_STRICTtXHTML_TRANSITIONALtXHTML_FRAMESETtXHTML11tSVGtSVG_FULLt SVG_BASICtSVG_TINYtgetR0(tclstname((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRCˆs        (shtmls-//W3C//DTD HTML 4.01//ENs%http://www.w3.org/TR/html4/strict.dtd(shtmls&-//W3C//DTD HTML 4.01 Transitional//ENs$http://www.w3.org/TR/html4/loose.dtd(shtmls"-//W3C//DTD HTML 4.01 Frameset//ENs'http://www.w3.org/TR/html4/frameset.dtdN(shtmlNN(shtmls -//W3C//DTD XHTML 1.0 Strict//ENs1http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd(shtmls&-//W3C//DTD XHTML 1.0 Transitional//ENs7http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd(shtmls"-//W3C//DTD XHTML 1.0 Frameset//ENs3http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd(shtmls-//W3C//DTD XHTML 1.1//ENs,http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd(ssvgs-//W3C//DTD SVG 1.1//ENs0http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd(ssvgs-//W3C//DTD SVG Basic 1.1//ENs6http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd(ssvgs-//W3C//DTD SVG Tiny 1.1//ENs5http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd(t__name__t __module__t__doc__R6R7R8R5R#R9R;R<R=R:R>R@RARBR?RCt classmethod(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRTs6 #cBs2eZdZeƒZdedd„Zd„ZRS(sProduces XML text from an event stream. >>> from genshi.builder import tag >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True)) >>> print ''.join(XMLSerializer()(elem.generate()))


cCsqtƒg|_|o|iit|iƒƒn|iitd|ƒƒ|o|iit|ƒƒndS(sInitialize the XML serializer. :param doctype: a ``(name, pubid, sysid)`` tuple that represents the DOCTYPE declaration that should be included at the top of the generated output, or the name of a DOCTYPE as defined in `DocType.get` :param strip_whitespace: whether extraneous whitespace should be stripped from the output :note: Changed in 0.4.2: The `doctype` parameter can now be a string. tprefixesN(tEmptyTagFiltertfilterstappendtWhitespaceFiltert_PRESERVE_SPACEtNamespaceFlattenertDocTypeInserter(tselftdoctypetstrip_whitespacetnamespace_prefixes((s3/usr/lib64/python2.6/site-packages/genshi/output.pyt__init__¹s c cs t}}t}x|iD]}||ƒ}qWxé|D]á\}}}|tjp |tjo‡|\} } d| g} x3| D]+\} } | d| dt| ƒdg7} qW| i|tjodpdƒtdi| ƒƒVq7|tjotd|ƒVq7|t jo%|o |Vqt|d tƒVq7|t jotd |ƒVq7|t jo¡| o™|\}}}d |g} |o| id |ƒn|d jo)|odpd}| id|ƒn| idƒtdi| ƒƒVt }q7|t jo | o˜|\}}}dg} |o| idƒn|o| idƒn|o| idƒn| idƒtdi| ƒƒtd|ƒVt }q7|tjotdƒVt }q7|tjotdƒVt}q7|tjotd|ƒVq7q7WdS(Ntt>ustquotess s s s s (tFalseRLRtEMPTYRRMRR%R R RR tTrueR tfilterR#RRR(RRtstreamt have_declt have_doctypetin_cdatatfilter_tkindtdatatposttagtattribtbuftattrtvaluetversionR!t standaloneREtpubidtsysid((s3/usr/lib64/python2.6/site-packages/genshi/output.pyt__call__Ìsl     #!          !        N( RFRGRHt frozensetROR#R`RVRs(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyR®s   cBs¿eZdZeddddddddd d d d d g ƒZeddddddddddddg ƒZeedƒedƒedƒedƒgƒZd e d e d„Z d„Z RS(!sProduces XHTML text from an event stream. >>> from genshi.builder import tag >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True)) >>> print ''.join(XHTMLSerializer()(elem.generate()))


tareatbasetbasefonttbrtcoltframethrtimgtinputtisindextlinktmetatparamtselectedtcheckedtcompacttdeclaretdefertdisabledtismaptmultipletnohreftnoresizetnoshadetnowraptpres http://www.w3.org/1999/xhtml}prettextareas%http://www.w3.org/1999/xhtml}textareacCsªtt|ƒi|tƒtƒg|_|o|iit|iƒƒn|ph}d|d<|iit d|ƒƒ|o|iit |ƒƒn||_ dS(Ntshttp://www.w3.org/1999/xhtmlRJ( tsuperRRVR^RKRLRMRNRORPRQt drop_xml_decl(RRRSRTRUR’((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRV!s  c csÑ|i}|i}|i}t}}t}x|iD]}||ƒ}q5Wx|D]w\} } } | tjp | tjo| \} } d| g}x•| D]\}}||jo |}nL|djo*d| jo|dt|ƒdg7}n|djoqšn|d|dt|ƒdg7}qšW| tjo3| |jo|id ƒqx|id | ƒn|id ƒt d i |ƒƒVqR| t jot d | ƒVqR| t jo%|o | VqÉt| dtƒVqR| t jot d| ƒVqR| tjo | o˜| \}}}dg}|o|idƒn|o|idƒn|o|idƒn|idƒt d i |ƒƒtd| ƒVt}qR| tjo©| o¡| o™| \}}}d|g}|o|id|ƒn|djo)|odpd}|id|ƒn|idƒt d i |ƒƒVt}qR| tjot dƒVt}qR| tjot dƒVt}qR| tjot d| ƒVqRqRWdS(NRWuxml:langulangs lang="RYu xml:spaceRXs="s />s>RZusR[s s s s s (t_BOOLEAN_ATTRSt _EMPTY_ELEMSR’R^RLRR_RRMRR%R R RR RaR#R`R RRR(RRRbt boolean_attrst empty_elemsR’RcRdReRfRgRhRiRjRkRlRmRnRERqRrRoR!Rp((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRs.s†           #         !            N( RFRGRHRtR”R“RROR#R`RVRs(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyR s   cBsVeZdZeedƒedƒedƒedƒgƒZded„Zd„Z RS(s Produces HTML text from an event stream. >>> from genshi.builder import tag >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True)) >>> print ''.join(HTMLSerializer()(elem.generate()))


tscripts#http://www.w3.org/1999/xhtml}scripttstyles"http://www.w3.org/1999/xhtml}stylecCs—tt|ƒi|tƒtƒg|_|o#|iit|i|i ƒƒn|iit dhdd6ƒƒ|o|iit |ƒƒndS(s€Initialize the HTML serializer. :param doctype: a ``(name, pubid, sysid)`` tuple that represents the DOCTYPE declaration that should be included at the top of the generated output :param strip_whitespace: whether extraneous whitespace should be stripped from the output RJRshttp://www.w3.org/1999/xhtmlN( R‘RRVR^RKRLRMRNROt_NOESCAPE_ELEMSRPRQ(RRRSRT((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRVŒs c cs|i}|i}|i}t}t}x|iD]}||ƒ}q1Wx¸|D]°\}} } |tjp |tjoB| \} } d| g} x¸| D]°\}}||jo|o| d|g7} qFq–d|jo;|djo*d| jo| dt|ƒdg7} qFq–|djo#| d|d t|ƒdg7} q–q–W| id ƒ|tjo&| |jo| id | ƒqŠnt d i | ƒƒV| |jo t }qþqN|t jot d | ƒVt}qN|t jo%|o | Vqþt| d tƒVqN|tjot d| ƒVqN|tjo | o˜| \}}}dg} |o| idƒn|o| idƒn|o| idƒn| idƒt d i | ƒƒtd| ƒVt }qN|tjot d| ƒVqNqNWdS(NRWRXt:sxml:langulangs lang="RYtxmlnss="RZsuR[s s s (R“R”R™R^RLRR_RRMRR%R`R R RR RaR#R(RRRbR•R–tnoescape_elemsRdtnoescapeRfRgRhRiRjRkRlRmRnRERqRr((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRs sj         ! '           !  N( RFRGRHRtRR™R#R`RVRs(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyR~s cBs#eZdZed„Zd„ZRS(sýProduces plain text from an event stream. Only text events are included in the output. Unlike the other serializer, special XML characters are not escaped: >>> from genshi.builder import tag >>> elem = tag.div(tag.a('', href='foo'), tag.br) >>> print elem
<Hello!>
>>> print ''.join(TextSerializer()(elem.generate())) If text events contain literal markup (instances of the `Markup` class), that markup is by default passed through unchanged: >>> elem = tag.div(Markup('Hello & Bye!
')) >>> print elem.generate().render(TextSerializer) Hello & Bye!
You can use the ``strip_markup`` to change this behavior, so that tags and entities are stripped from the output (or in the case of entities, replaced with the equivalent character): >>> print elem.generate().render(TextSerializer, strip_markup=True) Hello & Bye! cCs ||_dS(s³Create the serializer. :param strip_markup: whether markup (tags and encoded characters) found in the text should be removed N(t strip_markup(RRRž((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRVùsccsx|i}xh|D]`}|dtjoI|d}|o)t|ƒtjo|iƒiƒ}nt|ƒVqqWdS(Nii(RžR ttypeRt striptagst stripentitiestunicode(RRRbRžteventRh((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRss  (RFRGRHR^RVRs(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRÝs RKcBs#eZdZedƒZd„ZRS(scCombines `START` and `STOP` events into `EMPTY` events for elements that have no contents. R_ccs‰d}x||D]t}|dtjo=|dtjo#t|d|df}|Vq qa|Vn|dtj o |Vn|}q WdS(Niii(NNN(R#RR R_(RRRbtprevtev((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRss  (RFRGRHRR_Rs(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRK s RPcBs#eZdZdd„Zd„ZRS(siOutput stream filter that removes namespace information from the stream, instead adding namespace attributes and prefixes as needed. :param prefixes: optional mapping of namespace URIs to prefixes >>> from genshi.input import XML >>> xml = XML(''' ... ... ''') >>> for kind, data, pos in NamespaceFlattener()(xml): ... print kind, repr(data) START (u'doc', Attrs([(u'xmlns', u'NS1'), (u'xmlns:two', u'NS2')])) TEXT u'\n ' START (u'two:item', Attrs()) END u'two:item' TEXT u'\n' END u'doc' cCs8hdti6|_|dj o|ii|ƒndS(NR(RturiRJR#tupdate(RRRJ((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRV8s c #sÉtg}|iiƒD]\}}|||gfq~ƒ‰hdgti6‰‡‡fd†}g}|i}d„}d„} | ƒi} x1|D])\} } } | tjp | tjoW| \} }| i }| i }|o[|ˆjo-ˆ|d}|od||f}q=qA|d|fƒ|d|ƒng}x¨|D] \}}|i }|i }|oh|ˆjo.| ƒ}|||ƒ|d ||fƒnˆ|d}|od||f}qÛn|i||fƒqNW| |t ||ƒf| fV|2q˜| t joX| i }| i }|o-ˆ|d}|od||f}qkn| || fVq˜| t joZ| \}}|ˆjo0ˆi||gƒd}||||ƒƒn|||ƒq˜| tjoÂ| ˆjo±ˆi| ƒ}|iƒ}|p ˆ| =n||jp||djo*ˆ|}|iƒ|p ˆ|=qsn|o1|| |ƒ}||jo|i|ƒq«q¯qÁq˜| | | fVq˜WdS( NRcs6ˆi|gƒi|ƒˆi|gƒi|ƒdS(N(t setdefaultRM(tprefixR¦(RJt namespaces(s3/usr/lib64/python2.6/site-packages/genshi/output.pyt_push_ns@scSs d|o d|pd|fS(Nuxmlns%ss:%sR((R©R¦((s3/usr/lib64/python2.6/site-packages/genshi/output.pyt _make_ns_attrFscss#d}x|d7}d|Vq dS(Niisns%d((tval((s3/usr/lib64/python2.6/site-packages/genshi/output.pyt _gen_prefixIs iÿÿÿÿu%s:%suxmlnsRsxmlns:%s(tdictRJtitemsRR¦RMtnextRR_t localnamet namespaceRR R RCRtpoptremove(RRRbt_[1]tktvR«tns_attrst _push_ns_attrR¬R®RgRhRiRjtattrsttagnamettagnsR©t new_attrsRmRntattrnametattrnsR¦turist uri_prefixes((RJRªs3/usr/lib64/python2.6/site-packages/genshi/output.pyRs=s†?                           N(RFRGRHR#RVRs(((s3/usr/lib64/python2.6/site-packages/genshi/output.pyRP$s RNcBsNeZdZddd„Zdedeidƒieidƒid„Z RS(sPA filter that removes extraneous ignorable white space from the stream. cCsP|djo g}nt|ƒ|_|djo g}nt|ƒ|_dS(sÚInitialize the filter. :param preserve: a set or sequence of tag names for which white-space should be preserved :param noescape: a set or sequence of tag names for which text content should not be escaped The `noescape` set is expected to refer to elements that cannot contain further child elements (such as ``