--- a/src/unicorn_ui.py Fri Nov 19 01:57:55 2010 +0900
+++ b/src/unicorn_ui.py Fri Nov 19 02:45:41 2010 +0900
@@ -10,7 +10,7 @@
"""
import sys
import os
-from redbot.droid import ResourceExpertDroid
+from redbot.droid import InspectingResourceExpertDroid
from redbot.speak import _Classifications
from xml.dom import minidom
from xml.dom.minidom import parseString
@@ -36,14 +36,14 @@
"""
self.test_uri = test_uri
try:
- self.red = ResourceExpertDroid(self.test_uri)
+ self.red = InspectingResourceExpertDroid(self.test_uri)
self.result = ""
self.done = False
self.groups = []
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
if self.red.res_complete:
- self.result = self._generate_output_xml(test_uri, self.red.messages).toprettyxml()
+ self.result = self._generate_output_xml(test_uri).toprettyxml()
else:
error_string = ""
if self.red.res_error['desc'] == nbhttp.error.ERR_CONNECT['desc']:
@@ -91,11 +91,29 @@
rootDoc.setAttribute("xml:lang", "en")
rootDoc.setAttribute("ref", self.test_uri)
doc.appendChild(rootDoc)
-
-
-
return rootDoc, doc
+ def _output_response_header(self, doc, rootDoc):
+ """
+ Generate HTTP Response Header to Outputs
+ """
+ m = doc.createElement("message")
+ m.setAttribute("type", "info")
+ m.setAttribute("group", "response_header")
+ title = doc.createElement("title")
+ title.appendChild(doc.createTextNode("HTTP Response Header"))
+ description = doc.createElement("description")
+ ul = doc.createElement("ul")
+ ul.setAttribute("class", "headers")
+ description.appendChild(ul)
+ for i in self.red.res_hdrs:
+ li = doc.createElement("li")
+ li.appendChild(doc.createTextNode(i[0] + ":" + i[1]))
+ ul.appendChild(li)
+ m.appendChild(title)
+ m.appendChild(description)
+ rootDoc.appendChild(m)
+
def _handle_category(self, category_value):
"""
Getting Classification key from values
@@ -109,6 +127,14 @@
Getting group informations from _Classifications class
This implimentation is little a bit hack :)
"""
+ #Header group
+ h_group_element = doc.createElement("group")
+ h_group_element.setAttribute("name", "response_header")
+ h_title_element = doc.createElement("title")
+ h_title_element.appendChild(doc.createTextNode("HTTP Response Header"))
+ h_group_element.appendChild(h_title_element)
+ rootDoc.appendChild(h_group_element)
+
for k in set(self.groups):
group_element = doc.createElement("group")
group_element.setAttribute("name", str(k).lower())
@@ -118,13 +144,13 @@
group_element.appendChild(title_element)
rootDoc.appendChild(group_element)
- def _generate_output_xml(self, test_uri, messages):
+ def _generate_output_xml(self, test_uri):
"""
Generate Output XML Document
@return: Output XML Document
"""
rootDoc, doc = self._get_response_document()
- for i in messages:
+ for i in self.red.messages:
m = doc.createElement("message")
m.setAttribute("type", self._convert_level(i.level))
@@ -148,6 +174,7 @@
m.appendChild(text_element[0])
rootDoc.appendChild(m)
+ self._output_response_header(doc, rootDoc)
self._add_group_elements(doc, rootDoc)
return doc