changeset 3:ca1f58f5bad4 tip

pass a webob request and response to the manipulate method, API change, bumping version
author k0s <k0scist@gmail.com>
date Tue, 26 Jan 2010 22:57:00 -0500
parents bb7d50d54cb6
children
files lxmlmiddleware/example.py lxmlmiddleware/middleware.py setup.py
diffstat 3 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lxmlmiddleware/example.py
+++ b/lxmlmiddleware/example.py
@@ -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/middleware.py
+++ b/lxmlmiddleware/middleware.py
@@ -31,22 +31,22 @@ class LXMLMiddleware(object):
         if not 'lxml.etree' in environ:
             try:
                 environ['lxml.etree'] = etree.fromstring(response.body)
             except etree.XMLSyntaxError: # not XML
                 environ.pop('lxml.recomposer')
                 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/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.2"
+version = "0.3"
 
 setup(name='lxmlmiddleware',
       version=version,
       description="stack of middleware to deal with a response as a LXML etree",
       long_description="""
 """,
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Jeff Hammel',