# HG changeset patch # User k0s # Date 1264392783 18000 # Node ID bb7d50d54cb6604994ee35944e6f0bfdedbd7e49 # Parent 2bf25337048fc969d55b89e16eb3364c8ed8b0c2 correct huge mistake in how i try to get the response diff -r 2bf25337048f -r bb7d50d54cb6 lxmlmiddleware/middleware.py --- a/lxmlmiddleware/middleware.py Sun Jan 24 17:37:17 2010 -0500 +++ b/lxmlmiddleware/middleware.py Sun Jan 24 23:13:03 2010 -0500 @@ -4,6 +4,7 @@ import lxml.html from lxml import etree +from webob import Request, Response class LXMLMiddleware(object): """ @@ -20,26 +21,30 @@ if not 'lxml.recomposer' in environ: environ['lxml.recomposer'] = self + request = Request(environ) # get the response - response = self.app(environ, start_response) + response = request.get_response(self.app) + response.decode_content() # get the DOM, if not already made - if not isinstance(response, etree._Element): + # TODO: check response.content_type + if not 'lxml.etree' in environ: try: - response = etree.fromstring(''.join(response)) + environ['lxml.etree'] = etree.fromstring(response.body) except etree.XMLSyntaxError: # not XML environ.pop('lxml.recomposer') - return response + return response(environ, start_response) # manipulate the DOM - response = self.manipulate(environ, response) + environ['lxml.etree'] = self.manipulate(environ, environ['lxml.etree']) # recompose the DOM if the last in the chain if environ['lxml.recomposer'] is self: - response = [ lxml.html.tostring(response) ] + response.body = lxml.html.tostring(environ['lxml.etree']) # return the response - return response + return response(environ, start_response) + def manipulate(self, environ, tree): """manipulate the DOM; should return an etree._Element""" diff -r 2bf25337048f -r bb7d50d54cb6 setup.py --- a/setup.py Sun Jan 24 17:37:17 2010 -0500 +++ b/setup.py Sun Jan 24 23:13:03 2010 -0500 @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import sys, os -version = "0.1" +version = "0.2" setup(name='lxmlmiddleware', version=version, @@ -11,7 +11,7 @@ classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers author='Jeff Hammel', author_email='k0scist@gmail.com', - url='http://k0s.org', + url='http://k0s.org/hg/lxmlmiddleware', license="", packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True,