Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install repoze.xmliter

How to install repoze.xmliter

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install repoze.xmliter
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
0.1 Available View build log
Windows (64-bit)
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
0.1 Available View build log
Mac OS X (10.5+)
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
0.1 Available View build log
Linux (32-bit)
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
0.1 Available View build log
Linux (64-bit)
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
0.1 Available View build log
 
Author
License
BSD-derived (http://www.repoze.org/LICENSE.txt)
Dependencies
Lastest release
version 0.5 on Jan 26th, 2012

This package provides a wrapper for lxml trees which serializes to string on iteration, but otherwise makes the tree available in an attribute.

The primary for this is WSGI middleware which may avoid needless XML parsing and serialization.

Usage

It's recommend to use the lazy decorator on your application method. This allows you to return an lxml tree object, which is then automatically turned into an XMLSerializer.

>>> from repoze.xmliter import lazy
>>> @lazy
... def application(environ, start_response)
...     return some_lxml_tree

You may provide a serializer function, which will be used when the XMLSerializer is eventually iterated over (i.e. when the response is rendered):

>>> @lazy(serializer=lxml.html.tostring)
... def application(environ, start_response)
...     return some_lxml_tree

Middleware can use isinstance to test if the result is an XML iterable:

>>> from repoze.xmliter.serializer import XMLSerializer
>>> isinstance(result, XMLSerializer)

In this case, the middleware can simply access the tree attribute of the result.

There are two convenience methods which can be used to parse a WSGI iterable of strings and build an XMLSerializer object, but avoids re-building the serializer if the input iterable is already an instance of XMLSerializer:

>>> from repoze.xmliter.utils import getXMLSerializer
>>> result = getXMLSerializer(result)

Or, if you are parsing HTML:

>>> from repoze.xmliter.utils import getHTMLSerializer
>>> result = getHTMLSerializer(result)

If result is not an XMLSerializer, it will be parsed using a feed parser, turned into an lxml tree, and wrapped up in an XMLSerializer, which is returned.

Changelog

0.5 - 2012-01-25

  • Add __len__ to serializer to help WSGI servers. [Laurence]
  • Serializer should iter the entire string in one go. [Laurence]

0.4 - 2011-06-16

  • Ensure trailing space is removed when replacing doctype with empty string. [Laurence]

0.3 - 2011-06-03

  • Add doctype option to replace doctype on serialization. [Laurence]

0.2 - 2010-09-11

  • Use document encoding by default. (This fixes test failure on Ubuntu 10.04.) [Laurence]
  • Defer to xsl:output settings when serializing an XSLResultTree. [Laurence]
  • Turn off pretty printing by default for HTML to avoid affecting rendering on the browser. [Laurence]

0.1 - 2010-04-21

  • Initial release

Subscribe to package updates

Last updated Jan 26th, 2012

Download Stats

Last month:6

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.