changeset 1:2bf25337048f

worth a real version
author k0s <k0scist@gmail.com>
date Sun, 24 Jan 2010 17:37:17 -0500
parents d1067d921e97
children bb7d50d54cb6
files lxmlmiddleware/middleware.py setup.py
diffstat 2 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lxmlmiddleware/middleware.py	Sun Jan 24 12:00:39 2010 -0500
+++ b/lxmlmiddleware/middleware.py	Sun Jan 24 17:37:17 2010 -0500
@@ -2,6 +2,7 @@
 LXML middleware
 """
 
+import lxml.html
 from lxml import etree
 
 class LXMLMiddleware(object):
@@ -24,14 +25,18 @@
 
         # get the DOM, if not already made
         if not isinstance(response, etree._Element):
-            response = etree.fromstring(''.join(response))
+            try:
+                response = etree.fromstring(''.join(response))
+            except etree.XMLSyntaxError: # not XML
+                environ.pop('lxml.recomposer')
+                return response
         
         # manipulate the DOM
         response = self.manipulate(environ, response)
 
         # recompose the DOM if the last in the chain
         if environ['lxml.recomposer'] is self:
-            response = [ etree.tostring(response) ]
+            response = [ lxml.html.tostring(response) ]
 
         # return the response
         return response
--- a/setup.py	Sun Jan 24 12:00:39 2010 -0500
+++ b/setup.py	Sun Jan 24 17:37:17 2010 -0500
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.0"
+version = "0.1"
 
 setup(name='lxmlmiddleware',
       version=version,