Ñò ûãtHc @ s› d Z d d k l Z d d k Z d d k l Z l Z l Z d d d d d d d g Z d Z d e f d „ ƒ YZ d e f d „ ƒ YZ e i Z e i Z e i Z e i Z e i Z e i Z e i Z e i Z e i Z e i Z e i Z d „ Z d e f d „ ƒ YZ d e f d „ ƒ YZ y d d k l Z Wn e j o n Xe i Z d „ Z! d e f d „ ƒ YZ" e" d ƒ Z# d e f d „ ƒ YZ$ d S( s# Core classes for markup processing.iÿÿÿÿ( t chainN( t plaintextt stripentitiest striptagst Streamt Markupt escapet unescapet Attrst Namespacet QNames restructuredtext ent StreamEventKindc B s# e Z d Z g Z h Z d „ Z RS( s# A kind of event on a markup stream.c C s | i i | t i | | ƒ ƒ S( N( t _instancest setdefaultt strt __new__( t clst val( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyR s ( t __name__t __module__t __doc__t __slots__R R ( ( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyR s c B s e Z d Z d d g Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z d d „ Z d „ Z d „ Z d „ Z d d d d „ Z d d d „ Z d d „ Z d „ Z d „ Z d „ Z RS( 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. t eventst serializert STARTt ENDt TEXTt XML_DECLt DOCTYPEt START_NSt END_NSt START_CDATAt END_CDATAt PIt COMMENTc C s | | _ | | _ d S( 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( R R ( t selfR R ( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyt __init__E s c C s t | i ƒ S( N( t iterR ( R# ( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyt __iter__Q s c C s t t | | ƒ ƒ 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 htmlHello, 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 | sanitizerHello, 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 | uppercaseHELLO, 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 ( R t _ensureR ( R# t function( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyt __or__T s ,c G s t t i | f | ƒ S( sL Apply 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` ( t reducet operatort or_( R# t filters( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyt filter‚ s s utf-8c K sb d d k l } | d j o | i p d } n | i d | | } | | 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ÿÿÿÿ( t encodet xmlt methodt encodingt outN( t genshi.outputR/ t NoneR t serialize( R# R1 R2 R3 t kwargsR/ t generator( ( s1 /usr/lib64/python2.6/site-packages/genshi/core.pyt render˜ s c C s) d d k l } | | ƒ i | | | ƒ S( s> Return a new stream that contains the events matching the given XPath expression. >>> from genshi import HTML >>> stream = HTML('