changeset 3:ca1f58f5bad4 tip

pass a webob request and response to the manipulate method, API change, bumping version
author k0s <>
date Tue, 26 Jan 2010 22:57:00 -0500
parents bb7d50d54cb6
files lxmlmiddleware/ lxmlmiddleware/
diffstat 3 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lxmlmiddleware/
+++ b/lxmlmiddleware/
@@ -2,21 +2,21 @@ from webob import Response
 from lxml import etree
 from lxmlmiddleware.middleware import LXMLMiddleware
 from paste.httpexceptions import HTTPExceptionHandler
 def example_app(environ, start_response):
     return Response('<html><body>Hello, world!</body></html>')(environ, start_response)
 class ExampleMiddleware(LXMLMiddleware):
-    def manipulate(self, environ, tree):
+    def manipulate(self, request, response, tree):
         tree.append(etree.XML('<div><i>How are you doing?</i></div>'))        
         return tree
 class ExampleMiddleware2(LXMLMiddleware):
-    def manipulate(self, environ, tree):
+    def manipulate(self, request, response, tree):
         tree.append(etree.XML("<div><b>I'm doing find, thank you!</b></div>"))
         return tree
 def factory(global_conf, **app_conf):
     """create a webob view and wrap it in middleware"""
     return HTTPExceptionHandler(ExampleMiddleware2(ExampleMiddleware(example_app)))
--- a/lxmlmiddleware/
+++ b/lxmlmiddleware/
@@ -31,22 +31,22 @@ class LXMLMiddleware(object):
         if not 'lxml.etree' in environ:
                 environ['lxml.etree'] = etree.fromstring(response.body)
             except etree.XMLSyntaxError: # not XML
                 return response(environ, start_response)
         # manipulate the DOM
-        environ['lxml.etree'] = self.manipulate(environ, environ['lxml.etree'])
+        environ['lxml.etree'] = self.manipulate(request, response, environ['lxml.etree'])
         # recompose the DOM if the last in the chain
         if environ['lxml.recomposer'] is self:
             response.body = lxml.html.tostring(environ['lxml.etree'])
         # return the response
         return response(environ, start_response)        
-    def manipulate(self, environ, tree):
+    def manipulate(self, environ, response, tree):
         """manipulate the DOM; should return an etree._Element"""
         return tree
--- a/
+++ b/
@@ -1,12 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
-version = "0.2"
+version = "0.3"
       description="stack of middleware to deal with a response as a LXML etree",
       classifiers=[], # Get strings from
       author='Jeff Hammel',