# HG changeset patch # User cmlenz # Date 1174567518 0 # Node ID 5b248708bbed626635d6b1683e8a21b2ec86e159 # Parent d698a5556a550bf2fcd8a6c8c90a5661c7e48276 Try to use proper reStructuredText for docstrings throughout. diff --git a/genshi/__init__.py b/genshi/__init__.py --- a/genshi/__init__.py +++ b/genshi/__init__.py @@ -19,6 +19,7 @@ independently of where or how they are produced. """ +__docformat__ = 'restructuredtext en' try: __version__ = __import__('pkg_resources').get_distribution('Genshi').version except ImportError: diff --git a/genshi/builder.py b/genshi/builder.py --- a/genshi/builder.py +++ b/genshi/builder.py @@ -11,9 +11,12 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://genshi.edgewall.org/log/. +"""Support for programmatically generating markup streams.""" + from genshi.core import Attrs, Namespace, QName, Stream, START, END, TEXT __all__ = ['Fragment', 'Element', 'tag'] +__docformat__ = 'restructuredtext en' class Fragment(object): @@ -229,8 +232,8 @@ def __init__(self, namespace=None): """Create the factory, optionally bound to the given namespace. - @param namespace: the namespace URI for any created elements, or `None` - for no namespace + :param namespace: the namespace URI for any created elements, or `None` + for no namespace """ if namespace and not isinstance(namespace, Namespace): namespace = Namespace(namespace) diff --git a/genshi/core.py b/genshi/core.py --- a/genshi/core.py +++ b/genshi/core.py @@ -19,6 +19,7 @@ __all__ = ['Stream', 'Markup', 'escape', 'unescape', 'Attrs', 'Namespace', 'QName'] +__docformat__ = 'restructuredtext en' class StreamEventKind(str): @@ -35,14 +36,15 @@ This class is basically an iterator over the events. - Stream events are tuples of the form: + 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)`. + 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()` @@ -65,7 +67,7 @@ def __init__(self, events): """Initialize the stream with a sequence of markup events. - @param events: a sequence or iterable providing the events + :param events: a sequence or iterable providing the events """ self.events = events @@ -121,11 +123,11 @@ filters must be callables that accept the stream object as parameter, and return the filtered stream. - The call: + The call:: stream.filter(filter1, filter2) - is equivalent to: + is equivalent to:: stream | filter1 | filter2 """ @@ -134,10 +136,10 @@ def render(self, method='xml', encoding='utf-8', **kwargs): """Return a string representation of the stream. - @param method: determines how the stream is serialized; can be either + :param method: determines how the stream is serialized; can be either "xml", "xhtml", "html", "text", or a custom serializer class - @param encoding: how the output string should be encoded; if set to + :param encoding: how the output string should be encoded; if set to `None`, this method returns a `unicode` object Any additional keyword arguments are passed to the serializer, and thus @@ -156,7 +158,7 @@ """Return a new stream that contains the events matching the given XPath expression. - @param path: a string containing the XPath expression + :param path: a string containing the XPath expression """ from genshi.path import Path return Path(path).select(self, namespaces, variables) @@ -169,7 +171,7 @@ the serialized output incrementally, as opposed to returning a single string. - @param method: determines how the stream is serialized; can be either + :param method: determines how the stream is serialized; can be either "xml", "xhtml", "html", "text", or a custom serializer class @@ -231,11 +233,11 @@ >>> 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 + 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 + 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: @@ -253,8 +255,9 @@ >>> 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): + 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')]) @@ -264,7 +267,6 @@ >>> attrs | [('href', 'http://example.org/')] Attrs([('href', 'http://example.org/')]) - """ __slots__ = [] @@ -312,7 +314,7 @@ def totuple(self): """Return the attributes as a markup event. - The returned event is a TEXT event, the data is the value of all + The returned event is a `TEXT` event, the data is the value of all attributes joined together. """ return TEXT, u''.join([x[1] for x in self]), (None, -1, -1) @@ -438,7 +440,7 @@ 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: + belongs to that namespace using the ``in`` operator: >>> qname = html.body >>> qname in html @@ -496,7 +498,7 @@ """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}localname`. The namespace + the element or attribute, in the form ``{namespace}localname``. The namespace URI can be obtained through the additional `namespace` attribute, while the local name can be accessed through the `localname` attribute. diff --git a/genshi/filters.py b/genshi/filters.py --- a/genshi/filters.py +++ b/genshi/filters.py @@ -23,6 +23,7 @@ from genshi.core import END, START, TEXT __all__ = ['HTMLFormFiller', 'HTMLSanitizer'] +__docformat__ = 'restructuredtext en' class HTMLFormFiller(object): @@ -45,14 +46,15 @@ def __init__(self, name=None, id=None, data=None): """Create the filter. - @param name: The name of the form that should be populated. If this - parameter is given, only forms where the ``name`` attribute value - matches the parameter are processed. - @param id: The ID of the form that should be populated. If this - parameter is given, only forms where the ``id`` attribute value - matches the parameter are processed. - @param data: The dictionary of form values, where the keys are the names - of the form fields, and the values are the values to fill in. + :param name: The name of the form that should be populated. If this + parameter is given, only forms where the ``name`` attribute + value matches the parameter are processed. + :param id: The ID of the form that should be populated. If this + parameter is given, only forms where the ``id`` attribute + value matches the parameter are processed. + :param data: The dictionary of form values, where the keys are the names + of the form fields, and the values are the values to fill + in. """ self.name = name self.id = id @@ -63,8 +65,8 @@ def __call__(self, stream, ctxt=None): """Apply the filter to the given stream. - @param stream: the markup event stream to filter - @param ctxt: the template context (unused) + :param stream: the markup event stream to filter + :param ctxt: the template context (unused) """ in_form = in_select = in_option = in_textarea = False select_value = option_value = textarea_value = None @@ -213,10 +215,10 @@ The exact set of allowed elements and attributes can be configured. - @param safe_tags: a set of tag names that are considered safe - @param safe_attrs: a set of attribute names that are considered safe - @param safe_schemes: a set of URI schemes that are considered safe - @param uri_attrs: a set of names of attributes that contain URIs + :param safe_tags: a set of tag names that are considered safe + :param safe_attrs: a set of attribute names that are considered safe + :param safe_schemes: a set of URI schemes that are considered safe + :param uri_attrs: a set of names of attributes that contain URIs """ self.safe_tags = safe_tags self.safe_attrs = safe_attrs @@ -226,8 +228,8 @@ def __call__(self, stream, ctxt=None): """Apply the filter to the given stream. - @param stream: the markup event stream to filter - @param ctxt: the template context (unused) + :param stream: the markup event stream to filter + :param ctxt: the template context (unused) """ waiting_for = None diff --git a/genshi/input.py b/genshi/input.py --- a/genshi/input.py +++ b/genshi/input.py @@ -11,6 +11,10 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://genshi.edgewall.org/log/. +"""Support for constructing markup streams from files, strings, or other +sources. +""" + from itertools import chain from xml.parsers import expat try: @@ -27,6 +31,7 @@ START_CDATA, END_CDATA, PI, COMMENT __all__ = ['ET', 'ParseError', 'XMLParser', 'XML', 'HTMLParser', 'HTML'] +__docformat__ = 'restructuredtext en' def ET(element): """Convert a given ElementTree element to a markup stream.""" @@ -81,11 +86,12 @@ def __init__(self, source, filename=None, encoding=None): """Initialize the parser for the given XML input. - @param source: the XML text as a file-like object - @param filename: the name of the file, if appropriate - @param encoding: the encoding of the file; if not specified, the - encoding is assumed to be ASCII, UTF-8, or UTF-16, or whatever the - encoding specified in the XML declaration (if any) + :param source: the XML text as a file-like object + :param filename: the name of the file, if appropriate + :param encoding: the encoding of the file; if not specified, the + encoding is assumed to be ASCII, UTF-8, or UTF-16, or + whatever the encoding specified in the XML declaration + (if any) """ self.source = source self.filename = filename @@ -259,9 +265,9 @@ def __init__(self, source, filename=None, encoding='utf-8'): """Initialize the parser for the given HTML input. - @param source: the HTML text as a file-like object - @param filename: the name of the file, if known - @param filename: encoding of the file; ignored if the input is unicode + :param source: the HTML text as a file-like object + :param filename: the name of the file, if known + :param filename: encoding of the file; ignored if the input is unicode """ html.HTMLParser.__init__(self) self.source = source diff --git a/genshi/output.py b/genshi/output.py --- a/genshi/output.py +++ b/genshi/output.py @@ -28,6 +28,7 @@ __all__ = ['DocType', 'XMLSerializer', 'XHTMLSerializer', 'HTMLSerializer', 'TextSerializer'] +__docformat__ = 'restructuredtext en' class DocType(object): @@ -69,11 +70,11 @@ namespace_prefixes=None): """Initialize 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 - @param strip_whitespace: whether extraneous whitespace should be - stripped from the output + :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 """ self.preamble = [] if doctype: @@ -248,11 +249,11 @@ def __init__(self, doctype=None, strip_whitespace=True): """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 + :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 """ super(HTMLSerializer, self).__init__(doctype, False) self.filters = [EmptyTagFilter()] @@ -381,7 +382,7 @@ r"""Output 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 + :param prefixes: optional mapping of namespace URIs to prefixes >>> from genshi.input import XML >>> xml = XML(''' @@ -492,8 +493,9 @@ r"""Stream filter that removes all namespace information from a stream, and optionally strips out all tags not in a given namespace. - @param namespace: the URI of the namespace that should not be stripped. If - not set, only elements with no namespace are included in the output. + :param namespace: the URI of the namespace that should not be stripped. If + not set, only elements with no namespace are included in + the output. >>> from genshi.input import XML >>> xml = XML(''' @@ -549,13 +551,14 @@ def __init__(self, preserve=None, noescape=None): """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 + :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