[Checkins] SVN: z3c.etestbrowser/trunk/ fix bug that broke `open` on empty/invalid pages

Christian Theune ct at gocept.com
Wed Jun 18 05:47:03 EDT 2008


Log message for revision 87498:
  fix bug that broke `open` on empty/invalid pages
  

Changed:
  U   z3c.etestbrowser/trunk/CHANGES.txt
  U   z3c.etestbrowser/trunk/src/z3c/etestbrowser/README.txt
  A   z3c.etestbrowser/trunk/src/z3c/etestbrowser/empty.pt
  U   z3c.etestbrowser/trunk/src/z3c/etestbrowser/ftesting.zcml
  U   z3c.etestbrowser/trunk/src/z3c/etestbrowser/testing.py

-=-
Modified: z3c.etestbrowser/trunk/CHANGES.txt
===================================================================
--- z3c.etestbrowser/trunk/CHANGES.txt	2008-06-18 09:46:35 UTC (rev 87497)
+++ z3c.etestbrowser/trunk/CHANGES.txt	2008-06-18 09:47:02 UTC (rev 87498)
@@ -2,9 +2,15 @@
 CHANGES
 =======
 
-1.2 (unreleased)
+1.3 (unreleased)
 ----------------
 
+- Fixed bug with `normalized_contents` which would break the `open` function
+  of test browser if content wasn't parsable as HTML/XML.
+
+1.2 (2008-05-29)
+----------------
+
 - Added `normalized_contents` attribute that reindents and normalizes the
   etree structure of a document and allows easier to read HTML/XML examples in
   doctests.

Modified: z3c.etestbrowser/trunk/src/z3c/etestbrowser/README.txt
===================================================================
--- z3c.etestbrowser/trunk/src/z3c/etestbrowser/README.txt	2008-06-18 09:46:35 UTC (rev 87497)
+++ z3c.etestbrowser/trunk/src/z3c/etestbrowser/README.txt	2008-06-18 09:47:02 UTC (rev 87498)
@@ -64,7 +64,24 @@
   >>> browser.etree.xpath("//span")[0].text
   u'K\xfcgelblitz.'
 
+Invalid XML/HTML responses
+--------------------------
 
+Responses that contain a body with invalid XML/HTML will cause an error when
+accessing the etree or normalized_contents attribute, but will load fine for
+general TestBrowser use:
+
+  >>> browser.open("http://localhost/empty.html")
+  >>> browser.contents
+  ''
+  >>> browser.etree
+  Traceback (most recent call last):
+  XMLSyntaxError: ...
+  >>> browser.normalized_contents
+  Traceback (most recent call last):
+  XMLSyntaxError: ...
+
+
 Pretty printing
 ===============
 

Added: z3c.etestbrowser/trunk/src/z3c/etestbrowser/empty.pt
===================================================================


Property changes on: z3c.etestbrowser/trunk/src/z3c/etestbrowser/empty.pt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: z3c.etestbrowser/trunk/src/z3c/etestbrowser/ftesting.zcml
===================================================================
--- z3c.etestbrowser/trunk/src/z3c/etestbrowser/ftesting.zcml	2008-06-18 09:46:35 UTC (rev 87497)
+++ z3c.etestbrowser/trunk/src/z3c/etestbrowser/ftesting.zcml	2008-06-18 09:47:02 UTC (rev 87498)
@@ -37,4 +37,11 @@
     permission="zope.View"
     />
 
+  <browser:page
+    name="empty.html"
+    for="*"
+    template="empty.pt"
+    permission="zope.View"
+    />
+
 </configure>

Modified: z3c.etestbrowser/trunk/src/z3c/etestbrowser/testing.py
===================================================================
--- z3c.etestbrowser/trunk/src/z3c/etestbrowser/testing.py	2008-06-18 09:46:35 UTC (rev 87497)
+++ z3c.etestbrowser/trunk/src/z3c/etestbrowser/testing.py	2008-06-18 09:47:02 UTC (rev 87498)
@@ -55,9 +55,9 @@
     """
 
     xml_strict = False
-    normalized_contents = ''
 
     _etree = None
+    _normalized_contents = None
 
     @property
     def etree(self):
@@ -82,12 +82,18 @@
 
         return self._etree
 
+    @property
+    def normalized_contents(self):
+        if self._normalized_contents is None:
+            indent(self.etree)
+            self._normalized_contents = lxml.etree.tostring(self.etree,
+                                                            pretty_print=True)
+        return self._normalized_contents
+
     def _changed(self):
         super(ExtendedTestBrowser, self)._changed()
         self._etree = None
-        tree = self.etree
-        indent(tree)
-        self.normalized_contents = lxml.etree.tostring(tree, pretty_print=True)
+        self._normalized_contents = None
 
     def pretty_print(self):
         """Print a pretty (formatted) version of the HTML content.



More information about the Checkins mailing list