Overview
========
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.6.1 (2022-01-14)
------------------
* Fixed tests with lxml 4.7.1 or higher.
Fixes `issue 8 <https://github.com/repoze/repoze.xmliter/issues/8>`_.
[maurits]
0.6 - 2014-09-21
----------------
* Python 3 compatibility
[Lennart Regebro]
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
Raw data
{
"_id": null,
"home_page": "http://www.repoze.org",
"name": "repoze.xmliter",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "web middleware xml serialization",
"author": "Malthe Borch",
"author_email": "repoze-dev@lists.repoze.org",
"download_url": "https://files.pythonhosted.org/packages/60/70/3a0e82929bfe771248b628986202d983f372ad6819d05ea71755b228a145/repoze.xmliter-0.6.1.tar.gz",
"platform": "",
"description": "Overview\n========\n\nThis package provides a wrapper for ``lxml`` trees which serializes to\nstring on iteration, but otherwise makes the tree available in an\nattribute.\n\nThe primary for this is WSGI middleware which may avoid\nneedless XML parsing and serialization.\n\nUsage\n-----\n\nIt's recommend to use the `lazy` decorator on your application method. This\nallows you to return an lxml tree object, which is then automatically turned\ninto an XMLSerializer.\n\n >>> from repoze.xmliter import lazy\n \n >>> @lazy\n ... def application(environ, start_response)\n ... return some_lxml_tree\n\nYou may provide a serializer function, which will be used when the\nXMLSerializer is eventually iterated over (i.e. when the response is rendered):\n\n >>> @lazy(serializer=lxml.html.tostring)\n ... def application(environ, start_response)\n ... return some_lxml_tree\n\nMiddleware can use `isinstance` to test if the result is an XML\niterable:\n\n >>> from repoze.xmliter.serializer import XMLSerializer\n >>> isinstance(result, XMLSerializer)\n\nIn this case, the middleware can simply access the `tree` attribute of\nthe result.\n\nThere are two convenience methods which can be used to parse a WSGI iterable\nof strings and build an XMLSerializer object, but avoids re-building the\nserializer if the input iterable is already an instance of XMLSerializer:\n\n >>> from repoze.xmliter.utils import getXMLSerializer\n >>> result = getXMLSerializer(result)\n\nOr, if you are parsing HTML:\n\n >>> from repoze.xmliter.utils import getHTMLSerializer\n >>> result = getHTMLSerializer(result)\n\nIf `result` is not an XMLSerializer, it will be parsed using a feed parser,\nturned into an lxml tree, and wrapped up in an XMLSerializer, which is\nreturned.\n\n\nChangelog\n---------\n\n0.6.1 (2022-01-14)\n------------------\n\n* Fixed tests with lxml 4.7.1 or higher.\n Fixes `issue 8 <https://github.com/repoze/repoze.xmliter/issues/8>`_.\n [maurits]\n\n0.6 - 2014-09-21\n----------------\n\n* Python 3 compatibility\n [Lennart Regebro]\n\n0.5 - 2012-01-25\n----------------\n\n* Add __len__ to serializer to help WSGI servers.\n [Laurence]\n\n* Serializer should iter the entire string in one go.\n [Laurence]\n\n0.4 - 2011-06-16\n----------------\n\n* Ensure trailing space is removed when replacing doctype with empty string.\n [Laurence]\n\n0.3 - 2011-06-03\n----------------\n\n* Add doctype option to replace doctype on serialization.\n [Laurence]\n\n0.2 - 2010-09-11\n----------------\n\n* Use document encoding by default. (This fixes test failure on Ubuntu 10.04.)\n [Laurence]\n\n* Defer to xsl:output settings when serializing an XSLResultTree.\n [Laurence]\n\n* Turn off pretty printing by default for HTML to avoid affecting rendering on\n the browser.\n [Laurence]\n\n0.1 - 2010-04-21\n----------------\n\n* Initial release",
"bugtrack_url": null,
"license": "BSD-derived (http://www.repoze.org/LICENSE.txt)",
"summary": "Wrapper for ``lxml`` trees which serializes to string upon iteration.",
"version": "0.6.1",
"project_urls": {
"Homepage": "http://www.repoze.org"
},
"split_keywords": [
"web",
"middleware",
"xml",
"serialization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "60703a0e82929bfe771248b628986202d983f372ad6819d05ea71755b228a145",
"md5": "b1ba94347c7c4ecdd0c3092ee25a5458",
"sha256": "3682ac26dc38ea21b73eb877d2e612b6c671275ffe3fcf6ed15317b209f97cb2"
},
"downloads": -1,
"filename": "repoze.xmliter-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "b1ba94347c7c4ecdd0c3092ee25a5458",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12457,
"upload_time": "2022-01-14T18:26:11",
"upload_time_iso_8601": "2022-01-14T18:26:11.929485Z",
"url": "https://files.pythonhosted.org/packages/60/70/3a0e82929bfe771248b628986202d983f372ad6819d05ea71755b228a145/repoze.xmliter-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-01-14 18:26:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "repoze.xmliter"
}