PKN82EGG-INFO/dependency_links.txt PKN8OOEGG-INFO/entry_points.txt [babel.extractors] genshi = genshi.filters.i18n:extract[i18n] [python.templating.engines] genshi = genshi.template.plugin:MarkupTemplateEnginePlugin[plugin] genshi-markup = genshi.template.plugin:MarkupTemplateEnginePlugin[plugin] genshi-text = genshi.template.plugin:TextTemplateEnginePlugin[plugin] PKN8!xEGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: Genshi Version: 0.5.1 Summary: A toolkit for generation of output for the web Home-page: http://genshi.edgewall.org/ Author: Edgewall Software Author-email: info@edgewall.org License: BSD Download-URL: http://genshi.edgewall.org/wiki/Download Description: Genshi is a Python library that provides an integrated set of components for parsing, generating, and processing HTML, XML or other textual content for output generation on the web. The major feature is a template language, which is heavily inspired by Kid. Keywords: python.templating.engines Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Text Processing :: Markup :: HTML Classifier: Topic :: Text Processing :: Markup :: XML PKN8RD//EGG-INFO/requires.txt [i18n] Babel>=0.8 [plugin] setuptools>=0.6a2PKN8EGG-INFO/SOURCES.txtCOPYING ChangeLog MANIFEST.in README.txt setup.cfg setup.py Genshi.egg-info/PKG-INFO Genshi.egg-info/SOURCES.txt Genshi.egg-info/dependency_links.txt Genshi.egg-info/entry_points.txt Genshi.egg-info/requires.txt Genshi.egg-info/top_level.txt Genshi.egg-info/zip-safe doc/2000ft.png doc/filters.txt doc/i18n.txt doc/index.txt doc/install.txt doc/logo.gif doc/logo.png doc/plugin.txt doc/streams.txt doc/templates.txt doc/text-templates.txt doc/upgrade.txt doc/xml-templates.txt doc/xpath.txt doc/common/COPYING doc/common/README.txt doc/common/doctools.py doc/common/template.html doc/common/conf/docutils.ini doc/common/conf/epydoc.ini doc/common/style/bkgnd_pattern.png doc/common/style/docutils.css doc/common/style/edgewall.css doc/common/style/epydoc.css doc/common/style/pygments.css doc/common/style/shadow.gif doc/common/style/vertbars.png examples/basic/kidrun.py examples/basic/layout.html examples/basic/layout.kid examples/basic/run.py examples/basic/test.html examples/basic/test.kid examples/bench/basic.py examples/bench/bigtable.py examples/bench/cheetah/footer.tmpl examples/bench/cheetah/header.tmpl examples/bench/cheetah/template.tmpl examples/bench/clearsilver/footer.cs examples/bench/clearsilver/header.cs examples/bench/clearsilver/template.cs examples/bench/django/templates/base.html examples/bench/django/templates/template.html examples/bench/django/templatetags/__init__.py examples/bench/django/templatetags/bench.py examples/bench/genshi/base.html examples/bench/genshi/template.html examples/bench/genshi_text/footer.txt examples/bench/genshi_text/header.txt examples/bench/genshi_text/template.txt examples/bench/kid/base.kid examples/bench/kid/template.kid examples/bench/mako/footer.html examples/bench/mako/header.html examples/bench/mako/template.html examples/bench/myghty/base.myt examples/bench/myghty/template.myt examples/bench/simpletal/base.html examples/bench/simpletal/template.html examples/turbogears/README.txt examples/turbogears/dev.cfg examples/turbogears/sample-prod.cfg examples/turbogears/setup.py examples/turbogears/start-genshitest.py examples/turbogears/genshitest/__init__.py examples/turbogears/genshitest/controllers.py examples/turbogears/genshitest/json.py examples/turbogears/genshitest/model.py examples/turbogears/genshitest/release.py examples/turbogears/genshitest/config/__init__.py examples/turbogears/genshitest/config/app.cfg examples/turbogears/genshitest/config/log.cfg examples/turbogears/genshitest/static/images/favicon.ico examples/turbogears/genshitest/static/images/tg_under_the_hood.png examples/turbogears/genshitest/templates/__init__.py examples/turbogears/genshitest/templates/login.html examples/turbogears/genshitest/templates/master.html examples/turbogears/genshitest/templates/plain.txt examples/turbogears/genshitest/templates/sitetemplate.html examples/turbogears/genshitest/templates/welcome.html examples/turbogears/genshitest/tests/__init__.py examples/turbogears/genshitest/tests/test_controllers.py examples/turbogears/genshitest/tests/test_model.py examples/tutorial/geddit/__init__.py examples/tutorial/geddit/controller.py examples/tutorial/geddit/form.py examples/tutorial/geddit/model.py examples/tutorial/geddit/lib/__init__.py examples/tutorial/geddit/lib/ajax.py examples/tutorial/geddit/lib/template.py examples/tutorial/geddit/static/jquery.js examples/tutorial/geddit/static/layout.css examples/tutorial/geddit/static/logo.gif examples/tutorial/geddit/templates/_comment.html examples/tutorial/geddit/templates/_form.html examples/tutorial/geddit/templates/comment.html examples/tutorial/geddit/templates/index.html examples/tutorial/geddit/templates/index.xml examples/tutorial/geddit/templates/info.html examples/tutorial/geddit/templates/info.xml examples/tutorial/geddit/templates/layout.html examples/tutorial/geddit/templates/submit.html examples/webpy/README.txt examples/webpy/hello.html examples/webpy/hello.py genshi/__init__.py genshi/_speedups.c genshi/builder.py genshi/core.py genshi/input.py genshi/output.py genshi/path.py genshi/util.py genshi/filters/__init__.py genshi/filters/html.py genshi/filters/i18n.py genshi/filters/transform.py genshi/filters/tests/__init__.py genshi/filters/tests/html.py genshi/filters/tests/i18n.py genshi/filters/tests/transform.py genshi/template/__init__.py genshi/template/base.py genshi/template/directives.py genshi/template/eval.py genshi/template/interpolation.py genshi/template/loader.py genshi/template/markup.py genshi/template/plugin.py genshi/template/text.py genshi/template/tests/__init__.py genshi/template/tests/base.py genshi/template/tests/directives.py genshi/template/tests/eval.py genshi/template/tests/interpolation.py genshi/template/tests/loader.py genshi/template/tests/markup.py genshi/template/tests/plugin.py genshi/template/tests/text.py genshi/template/tests/templates/__init__.py genshi/template/tests/templates/functions.html genshi/template/tests/templates/functions.txt genshi/template/tests/templates/new_syntax.txt genshi/template/tests/templates/test.html genshi/template/tests/templates/test.txt genshi/template/tests/templates/test_no_doctype.html genshi/tests/__init__.py genshi/tests/builder.py genshi/tests/core.py genshi/tests/input.py genshi/tests/output.py genshi/tests/path.py genshi/tests/util.pyPKN8VEGG-INFO/top_level.txtgenshi PKN82EGG-INFO/zip-safe PK8ә8/8/genshi/builder.py# -*- coding: utf-8 -*- # # Copyright (C) 2006-2008 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://genshi.edgewall.org/wiki/License. # # This software consists of voluntary contributions made by many # 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 Python code using a very simple syntax. The main entry point to this module is the `tag` object (which is actually an instance of the ``ElementFactory`` class). You should rarely (if ever) need to directly import and use any of the other classes in this module. Elements can be created using the `tag` object using attribute access. For example: >>> doc = tag.p('Some text and ', tag.a('a link', href='http://example.org/'), '.') >>> doc This produces an `Element` instance which can be further modified to add child nodes and attributes. This is done by "calling" the element: positional arguments are added as child nodes (alternatively, the `Element.append` method can be used for that purpose), whereas keywords arguments are added as attributes: >>> doc(tag.br) >>> print doc

Some text and a link.

If an attribute name collides with a Python keyword, simply append an underscore to the name: >>> doc(class_='intro') >>> print doc

Some text and a link.

As shown above, an `Element` can easily be directly rendered to XML text by printing it or using the Python ``str()`` function. This is basically a shortcut for converting the `Element` to a stream and serializing that stream: >>> stream = doc.generate() >>> stream #doctest: +ELLIPSIS >>> print stream

Some text and a link.

The `tag` object also allows creating "fragments", which are basically lists of nodes (elements or text) that don't have a parent element. This can be useful for creating snippets of markup that are attached to a parent element later (for example in a template). Fragments are created by calling the `tag` object, which returns an object of type `Fragment`: >>> fragment = tag('Hello, ', tag.em('world'), '!') >>> fragment >>> print fragment Hello, world! """ try: set except NameError: from sets import Set as set from genshi.core import Attrs, Markup, Namespace, QName, Stream, \ START, END, TEXT __all__ = ['Fragment', 'Element', 'ElementFactory', 'tag'] __docformat__ = 'restructuredtext en' class Fragment(object): """Represents a markup fragment, which is basically just a list of element or text nodes. """ __slots__ = ['children'] def __init__(self): """Create a new fragment.""" self.children = [] def __add__(self, other): return Fragment()(self, other) def __call__(self, *args): """Append any positional arguments as child nodes. :see: `append` """ map(self.append, args) return self def __iter__(self): return self._generate() def __repr__(self): return '<%s>' % self.__class__.__name__ def __str__(self): return str(self.generate()) def __unicode__(self): return unicode(self.generate()) def __html__(self): return Markup(self.generate()) def append(self, node): """Append an element or string as child node. :param node: the node to append; can be an `Element`, `Fragment`, or a `Stream`, or a Python string or number """ if isinstance(node, (Stream, Element, basestring, int, float, long)): # For objects of a known/primitive type, we avoid the check for # whether it is iterable for better performance self.children.append(node) elif isinstance(node, Fragment): self.children.extend(node.children) elif node is not None: try: map(self.append, iter(node)) except TypeError: self.children.append(node) def _generate(self): for child in self.children: if isinstance(child, Fragment): for event in child._generate(): yield event elif isinstance(child, Stream): for event in child: yield event else: if not isinstance(child, basestring): child = unicode(child) yield TEXT, child, (None, -1, -1) def generate(self): """Return a markup event stream for the fragment. :rtype: `Stream` """ return Stream(self._generate()) def _kwargs_to_attrs(kwargs): attrs = [] names = set() for name, value in kwargs.items(): name = name.rstrip('_').replace('_', '-') if value is not None and name not in names: attrs.append((QName(name), unicode(value))) names.add(name) return Attrs(attrs) class Element(Fragment): """Simple XML output generator based on the builder pattern. Construct XML elements by passing the tag name to the constructor: >>> print Element('strong') Attributes can be specified using keyword arguments. The values of the arguments will be converted to strings and any special XML characters escaped: >>> print Element('textarea', rows=10, cols=60)