Ñò ûãtHc @s›dZddklZddkZddklZlZlZddddd d d gZd Z d e fd„ƒYZ de fd„ƒYZ e iZe iZe iZe iZe iZe iZe iZe iZe iZe iZe iZd„Zd efd„ƒYZdefd„ƒYZyddklZWnej onXei Z d„Z!d e fd„ƒYZ"e"dƒZ#d efd„ƒYZ$dS(s#Core classes for markup processing.iÿÿÿÿ(tchainN(t plaintextt stripentitiest striptagstStreamtMarkuptescapetunescapetAttrst NamespacetQNamesrestructuredtext entStreamEventKindcBs#eZdZgZhZd„ZRS(s#A kind of event on a markup stream.cCs|ii|ti||ƒƒS(N(t _instancest setdefaulttstrt__new__(tclstval((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRs(t__name__t __module__t__doc__t __slots__R R(((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR scBs eZdZddgZedƒZedƒZedƒZedƒZedƒZ edƒZ ed ƒZ ed ƒZ ed ƒZ ed ƒZed ƒZdd„Zd„Zd„Zd„Zdddd„Zddd„Zdd„Zd„Zd„Zd„ZRS(s.Represents a stream of markup events. This class is basically an iterator over the events. Stream events are tuples of the form:: (kind, data, position) where ``kind`` is the event kind (such as `START`, `END`, `TEXT`, etc), ``data`` depends on the kind of event, and ``position`` is a ``(filename, line, offset)`` tuple that contains the location of the original element or text in the input. If the original location is unknown, ``position`` is ``(None, -1, -1)``. Also provided are ways to serialize the stream to text. The `serialize()` method will return an iterator over generated strings, while `render()` returns the complete generated text at once. Both accept various parameters that impact the way the stream is serialized. teventst serializertSTARTtENDtTEXTtXML_DECLtDOCTYPEtSTART_NStEND_NSt START_CDATAt END_CDATAtPItCOMMENTcCs||_||_dS(s:Initialize the stream with a sequence of markup events. :param events: a sequence or iterable providing the events :param serializer: the default serialization method to use for this stream :note: Changed in 0.5: added the `serializer` argument N(RR(tselfRR((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__init__Es cCs t|iƒS(N(titerR(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__iter__QscCstt||ƒƒd|iƒS(s°Override the "bitwise or" operator to apply filters or serializers to the stream, providing a syntax similar to pipes on Unix shells. Assume the following stream produced by the `HTML` function: >>> from genshi.input import HTML >>> html = HTML('''

Hello, world!

''') >>> print html

Hello, world!

A filter such as the HTML sanitizer can be applied to that stream using the pipe notation as follows: >>> from genshi.filters import HTMLSanitizer >>> sanitizer = HTMLSanitizer() >>> print html | sanitizer

Hello, world!

Filters can be any function that accepts and produces a stream (where a stream is anything that iterates over events): >>> def uppercase(stream): ... for kind, data, pos in stream: ... if kind is TEXT: ... data = data.upper() ... yield kind, data, pos >>> print html | sanitizer | uppercase

HELLO, WORLD!

Serializers can also be used with this notation: >>> from genshi.output import TextSerializer >>> output = TextSerializer() >>> print html | sanitizer | uppercase | output HELLO, WORLD! Commonly, serializers should be used at the end of the "pipeline"; using them somewhere in the middle may produce unexpected results. :param function: the callable object that should be applied as a filter :return: the filtered stream :rtype: `Stream` R(Rt_ensureR(R#tfunction((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__or__Ts,cGstti|f|ƒS(sLApply filters to the stream. This method returns a new stream with the given filters applied. The filters must be callables that accept the stream object as parameter, and return the filtered stream. The call:: stream.filter(filter1, filter2) is equivalent to:: stream | filter1 | filter2 :param filters: one or more callable objects that should be applied as filters :return: the filtered stream :rtype: `Stream` (treducetoperatortor_(R#tfilters((s1/usr/lib64/python2.6/site-packages/genshi/core.pytfilter‚ssutf-8c Ksbddkl}|djo|ipd}n|id||}||d|d|d|ƒS(sàReturn a string representation of the stream. Any additional keyword arguments are passed to the serializer, and thus depend on the `method` parameter value. :param method: determines how the stream is serialized; can be either "xml", "xhtml", "html", "text", or a custom serializer class; if `None`, the default serialization method of the stream is used :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 :rtype: `basestring` :see: XMLSerializer, XHTMLSerializer, HTMLSerializer, TextSerializer :note: Changed in 0.5: added the `out` parameter iÿÿÿÿ(tencodetxmltmethodtencodingtoutN(t genshi.outputR/tNoneRt serialize(R#R1R2R3tkwargsR/t generator((s1/usr/lib64/python2.6/site-packages/genshi/core.pytrender˜s  cCs)ddkl}||ƒi|||ƒS(s>Return a new stream that contains the events matching the given XPath expression. >>> from genshi import HTML >>> stream = HTML('foobar') >>> print stream.select('elem') foobar >>> print stream.select('elem/text()') foobar Note that the outermost element of the stream becomes the *context node* for the XPath test. That means that the expression "doc" would not match anything in the example above, because it only tests against child elements of the outermost element: >>> print stream.select('doc') You can use the "." expression to match the context node itself (although that usually makes little sense): >>> print stream.select('.') foobar :param path: a string containing the XPath expression :param namespaces: mapping of namespace prefixes used in the path :param variables: mapping of variable names to values :return: the selected substream :rtype: `Stream` :raises PathSyntaxError: if the given path expression is invalid or not supported iÿÿÿÿ(tPath(t genshi.pathR:tselect(R#tpatht namespacest variablesR:((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR<µs!R0cKsJddkl}|djo|ipd}n|||t|ƒƒS(s²Generate strings corresponding to a specific serialization of the stream. Unlike the `render()` method, this method is a generator that returns the serialized output incrementally, as opposed to returning a single string. Any additional keyword arguments are passed to the serializer, and thus depend on the `method` parameter value. :param method: determines how the stream is serialized; can be either "xml", "xhtml", "html", "text", or a custom serializer class; if `None`, the default serialization method of the stream is used :return: an iterator over the serialization results (`Markup` or `unicode` objects, depending on the serialization method) :rtype: ``iterator`` :see: XMLSerializer, XHTMLSerializer, HTMLSerializer, TextSerializer iÿÿÿÿ(tget_serializerR0N(R4R@R5RR'(R#R1R7R@((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR6Ùs cCs |iƒS(N(R9(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__str__òscCs|iddƒS(NR2(R9R5(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt __unicode__õscCs|S(N((R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__html__øsN(RRRRR RRRRRRRRR R!R"R5R$R&R)R.R9R<R6RARBRC(((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR#s.              . $   ccs¹t|ƒ}|iƒ}t|ƒtj pt|ƒdjo\xTt|g|ƒD]@}t|dƒo|iƒ}ntt |ƒdf}|VqQWdS|Vx|D] }|Vq¦WdS(s@Ensure that every item on the stream is actually a markup event.ittotupleiÿÿÿÿN(Niÿÿÿÿiÿÿÿÿ( R%tnextttypettupletlenRthasattrRDRtunicodeR5(tstreamtevent((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR's  & cBsVeZdZgZd„Zd„Zd„Zd„Zd„Zdd„Z d„Z RS( s?Immutable sequence type that stores the attributes of an element. Ordering of the attributes is preserved, while access by name is also supported. >>> attrs = Attrs([('href', '#'), ('title', 'Foo')]) >>> attrs Attrs([('href', '#'), ('title', 'Foo')]) >>> 'href' in attrs True >>> 'tabindex' in attrs False >>> attrs.get('title') 'Foo' Instances may not be manipulated directly. Instead, the operators ``|`` and ``-`` can be used to produce new instances that have specific attributes added, replaced or removed. To remove an attribute, use the ``-`` operator. The right hand side can be either a string or a set/sequence of strings, identifying the name(s) of the attribute(s) to remove: >>> attrs - 'title' Attrs([('href', '#')]) >>> attrs - ('title', 'href') Attrs() The original instance is not modified, but the operator can of course be used with an assignment: >>> attrs Attrs([('href', '#'), ('title', 'Foo')]) >>> attrs -= 'title' >>> attrs Attrs([('href', '#')]) To add a new attribute, use the ``|`` operator, where the right hand value is a sequence of ``(name, value)`` tuples (which includes `Attrs` instances): >>> attrs | [('title', 'Bar')] Attrs([('href', '#'), ('title', 'Bar')]) If the attributes already contain an attribute with a given name, the value of that attribute is replaced: >>> attrs | [('href', 'http://example.org/')] Attrs([('href', 'http://example.org/')]) cCs-x&|D]\}}||jotSqWdS(s²Return whether the list includes an attribute with the specified name. :return: `True` if the list includes the attribute :rtype: `bool` N(tTrue(R#tnametattrt_((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt __contains__Us  cCstti|||ƒƒS(s­Return a slice of the attributes list. >>> attrs = Attrs([('href', '#'), ('title', 'Foo')]) >>> attrs[1:] Attrs([('title', 'Foo')]) (RRGt __getslice__(R#titj((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRR`sc Cs½tg}|D]*\}}||jo|||fqq~ƒ}tg}|D]%\}}|||i||ƒfqR~g} |D]*\}}||jo| ||fqˆqˆ~ ƒS(sÚReturn a new instance that contains the attributes in `attrs` in addition to any already existing attributes. :return: a new instance with the merged attributes :rtype: `Attrs` (tdictRtget( R#tattrst_[1]tantavtreplt_[2]tsntsvt_[3]((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR)isD9cCs>|pdSddig}|D]}|t|ƒq ~ƒS(NsAttrs()s Attrs([%s])s, (tjointrepr(R#RXtitem((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__repr__tscCs_t|tƒo |f}ntg}|D]*\}}||jo|||fq+q+~ƒS(söReturn a new instance with all attributes with a name in `names` are removed. :param names: the names of the attributes to remove :return: a new instance with the attribute removed :rtype: `Attrs` (t isinstancet basestringR(R#tnamesRXRNR((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__sub__ys cCs-x&|D]\}}||jo|SqW|S(s Return the value of the attribute with the specified name, or the value of the `default` parameter if no such attribute is found. :param name: the name of the attribute :param default: the value to return when the attribute does not exist :return: the attribute value, or the `default` value if that attribute does not exist :rtype: `object` ((R#RNtdefaultROtvalue((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRV…s    cCs5tdig}|D]}||dq~ƒdfS(s\Return the attributes as a markup event. The returned event is a `TEXT` event, the data is the value of all attributes joined together. >>> Attrs([('href', '#'), ('title', 'Foo')]).totuple() ('TEXT', u'#Foo', (None, -1, -1)) :return: a `TEXT` event :rtype: `tuple` uiiÿÿÿÿN(Niÿÿÿÿiÿÿÿÿ(RR`R5(R#RXtx((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRD”s N( RRRRRQRRR)RcRgR5RVRD(((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRs3  cBsŒeZdZgZd„Zd„Zd„Zd„Zd„Zd„Z e d„Z e d„Z e e ƒZ d „Zed „Zd „ZRS( seMarks a string as being safe for inclusion in HTML/XML output without needing to be escaped. cCs tt|ƒtt|ƒƒƒS(N(RRJR(R#tother((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__add__©scCs ttt|ƒƒt|ƒƒS(N(RRJR(R#Rk((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__radd__¬scCst|tƒo.tt|iƒtt|iƒƒƒƒ}n<t|ttfƒottt|ƒƒ}n t|ƒ}t t i ||ƒƒS(N( RdRUtziptkeystmapRtvaluestlistRGRRJt__mod__(R#targs((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRs¯s . cCstt|ƒ|ƒS(N(RRJ(R#tnum((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__mul__¸scCst|t|ƒƒS(N(RRJ(R#Ru((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__rmul__»scCsd|iit|ƒfS(Ns<%s %r>(t __class__RRJ(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRc¾sc Cs@tt|ƒig}|D]}|t|d|ƒq~ƒƒS(sAReturn a `Markup` object which is the concatenation of the strings in the given sequence, where this `Markup` object is the separator between the joined elements. Any element in the sequence that is not a `Markup` instance is automatically escaped. :param seq: the sequence of strings to join :param escape_quotes: whether double quote characters in the elements should be escaped :return: the joined `Markup` object :rtype: `Markup` :see: `escape` tquotes(RRJR`R(R#tseqt escape_quotesRXRb((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR`ÁscCsŸ|p|ƒSt|ƒ|jo|St|dƒot|iƒƒSt|ƒiddƒiddƒiddƒ}|o|idd ƒ}n||ƒS( sæCreate a Markup instance from a string and escape special characters it may contain (<, >, & and "). >>> escape('"1 < 2"') If the `quotes` parameter is set to `False`, the " character is left as is. Escaping quotes is generally only required for strings that are to be used in attribute values. >>> escape('"1 < 2"', quotes=False) :param text: the text to escape :param quotes: if ``True``, double quote characters are escaped in addition to the other special characters :return: the escaped `Markup` string :rtype: `Markup` RCt&s&ts>t"s"(RFRIRRCRJtreplace(RttextRy((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRÓs  cCsF|pdSt|ƒiddƒiddƒiddƒidd ƒS( sùReverse-escapes &, <, >, and " and returns a `unicode` object. >>> Markup('1 < 2').unescape() u'1 < 2' :return: the unescaped string :rtype: `unicode` :see: `genshi.core.unescape` us"Rs>R~s<R}s&R|(RJR€(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRös   cCstt|d|ƒƒS(sÑReturn a copy of the text with any character or numeric entities replaced by the equivalent UTF-8 characters. If the `keepxmlentities` parameter is provided and evaluates to `True`, the core XML entities (``&``, ``'``, ``>``, ``<`` and ``"``) are not stripped. :return: a `Markup` instance with entities removed :rtype: `Markup` :see: `genshi.util.stripentities` tkeepxmlentities(RR(R#R‚((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRs cCstt|ƒƒS(sÅReturn a copy of the text with all XML/HTML tags removed. :return: a `Markup` instance with all tags removed :rtype: `Markup` :see: `genshi.util.striptags` (RR(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRs(RRRRRlRmRsRvRwRcRMR`Rt classmethodRtFalseRR(((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR£s       !   (RcCst|tƒp|S|iƒS(spReverse-escapes &, <, >, and " and returns a `unicode` object. >>> unescape(Markup('1 < 2')) u'1 < 2' If the provided `text` object is not a `Markup` instance, it is returned unchanged. >>> unescape('1 < 2') '1 < 2' :param text: the text to unescape :return: the unescsaped string :rtype: `unicode` (RdRR(R((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR&scBs€eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z e Z d „Z d „Zd „ZRS( süUtility class creating and testing elements with a namespace. Internally, namespace URIs are encoded in the `QName` of any element or attribute, the namespace URI being enclosed in curly braces. This class helps create and test these strings. A `Namespace` object is instantiated with the namespace URI. >>> html = Namespace('http://www.w3.org/1999/xhtml') >>> html >>> html.uri u'http://www.w3.org/1999/xhtml' The `Namespace` object can than be used to generate `QName` objects with that namespace: >>> html.body QName(u'http://www.w3.org/1999/xhtml}body') >>> html.body.localname u'body' >>> html.body.namespace u'http://www.w3.org/1999/xhtml' The same works using item access notation, which is useful for element or attribute names that are not valid Python identifiers: >>> html['body'] QName(u'http://www.w3.org/1999/xhtml}body') A `Namespace` object can also be used to test whether a specific `QName` belongs to that namespace using the ``in`` operator: >>> qname = html.body >>> qname in html True >>> qname in Namespace('http://www.w3.org/2002/06/xhtml2') False cCs%t|ƒ|jo|Sti|ƒS(N(RFtobjectR(Rturi((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRcscCs |ifS(N(R†(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__getnewargs__hscCs|iS(N(R†(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt __getstate__kscCs ||_dS(N(R†(R#R†((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt __setstate__nscCst|ƒ|_dS(N(RJR†(R#R†((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR$qscCs|i|ijS(N(t namespaceR†(R#tqname((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRQtscCs ||j S(N((R#Rk((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__ne__wscCs.t|tƒo|i|ijS|i|jS(N(RdR R†(R#Rk((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt__eq__zscCst|id|ƒS(Nu}(R R†(R#RN((s1/usr/lib64/python2.6/site-packages/genshi/core.pyt __getitem__scCs d|iS(Ns(R†(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRcƒscCs|iidƒS(Nsutf-8(R†R/(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRA†scCs|iS(N(R†(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRB‰s(RRRRR‡RˆR‰R$RQRŒRRŽt __getattr__RcRARB(((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR ;s'           s$http://www.w3.org/XML/1998/namespacecBs5eZdZddgZd„Zd„Zd„ZRS(sÄA qualified element or attribute name. The unicode value of instances of this class contains the qualified name of the element or attribute, in the form ``{namespace-uri}local-name``. The namespace URI can be obtained through the additional `namespace` attribute, while the local name can be accessed through the `localname` attribute. >>> qname = QName('foo') >>> qname QName(u'foo') >>> qname.localname u'foo' >>> qname.namespace >>> qname = QName('http://www.w3.org/1999/xhtml}body') >>> qname QName(u'http://www.w3.org/1999/xhtml}body') >>> qname.localname u'body' >>> qname.namespace u'http://www.w3.org/1999/xhtml' RŠt localnamecCsªt|ƒ|jo|S|idƒiddƒ}t|ƒdjo5ti|d|ƒ}tt|ƒ\|_|_n,ti||ƒ}dt|ƒ|_|_|S(säCreate the `QName` instance. :param qname: the qualified name as a string of the form ``{namespace-uri}local-name``, where the leading curly brace is optional u{u}iu{%sN( RFtlstriptsplitRHRJRRpRŠRR5(RR‹tpartsR#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRªscCs|idƒfS(Nt{(R‘(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR‡½scCsdti|idƒƒS(Ns QName(%s)R”(RJRcR‘(R#((s1/usr/lib64/python2.6/site-packages/genshi/core.pyRcÀs(RRRRRR‡Rc(((s1/usr/lib64/python2.6/site-packages/genshi/core.pyR ‘s    (%Rt itertoolsRR+t genshi.utilRRRt__all__t __docformat__RR R…RRRRRRRRRR R!R"R'RGRRJRtgenshi._speedupst ImportErrorRRR t XML_NAMESPACER (((s1/usr/lib64/python2.6/site-packages/genshi/core.pyts>   Ù            „|  S