[Erp5-report] r9626 - /erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Sep 4 11:16:59 CEST 2006


Author: vincent
Date: Mon Sep  4 11:16:57 2006
New Revision: 9626

URL: http://svn.erp5.org?rev=9626&view=rev
Log:
Write a robust and dirty way to get the portal status message.
Use a common function to match a string inside a minidom xml node.

Modified:
    erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py

Modified: erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py?rev=9626&r1=9625&r2=9626&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py (original)
+++ erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py Mon Sep  4 11:16:57 2006
@@ -65,13 +65,17 @@
     """
       Parses the last received page and returns the value of the portal_status_message, or None if not present.
     """
-    from xml.dom.minidom import parseString
-    document = parseString(self.getHtml().get_data())
-    for element in document.getElementsByTagName(u'td'):
-      if element.attributes.get(u'class') is not None and element.attributes.get(u'class').value == u'error': # XXX: Hardcoded class name
-        for child in element.childNodes:
-          if child.nodeType == child.TEXT_NODE:
-            return child.wholeText
+# XXX: disabled temporarily to survive html style bogus html.
+#    from xml.dom.minidom import parseString
+#    document = parseString(self.getHtml().get_data())
+#    for element in document.getElementsByTagName(u'td'):
+#      if element.attributes.get(u'class') is not None and element.attributes.get(u'class').value == u'error': # XXX: Hardcoded class name
+#        for child in element.childNodes:
+#          if child.nodeType == child.TEXT_NODE:
+#            return child.wholeText
+    for line in self.getHtml().get_data().split('\n'):
+      if 'class="error"' in line:
+        return line
     return None
 
   def selectMainForm(self):
@@ -378,6 +382,18 @@
                                          .getElementsByTagName(u'input')[0].attributes[u'name'].value)
                    , value)
 
+  def match(self, node, value, strict=False):
+    """
+      Returns True if value matches a substring of node.
+    """
+    if (node.nodeType == node.TEXT_NODE) and (strict and (value == node.wholeText) or (value in node.wholeText)):
+      return True
+    else:
+      for child in node.childNodes:
+        if self.match(child, value, strict):
+          return True
+    return False
+    
   def getListboxLine(self, column_number, value, strict=False):
     """
       Returns the position number of the first line containing given text in given column, None if not found.
@@ -385,8 +401,8 @@
     line_list = self._getListbox().getElementsByTagName(u'tr')
     for line_pos in xrange(len(line_list)):
       for child in line_list[line_pos].getElementsByTagName(u'td')[column_number].childNodes:
-        if (child.nodeType == child.TEXT_NODE) and (strict and (value == child.wholeText) or (value in child.wholeText)):
-          return line_pos          
+        if self.match(child, value, strict):
+          return line_pos
     return None
 
   def getListboxColumn(self, line_number, value, strict=False):
@@ -396,7 +412,7 @@
     column_list = self._getListbox().getElementsByTagName(u'tr')[line_number].getElementsByTagName(u'td')
     for cell_pos in xrange(len(column_list)):
       for child in column_list[cell_pos].childNodes:
-        if (child.nodeType == child.TEXT_NODE) and (strict and (value == child.wholeText) or (value in child.wholeText)):
+        if self.match(child, value, strict):
           return cell_pos
     return None
 




More information about the Erp5-report mailing list