OSDN Git Service

response html parser.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 11 Sep 2006 07:02:35 +0000 (16:02 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 11 Sep 2006 08:41:11 +0000 (17:41 +0900)
src/FukuiNoNamari/submit_window.py

index b06ea91..6524ab5 100644 (file)
@@ -55,12 +55,19 @@ class ConfirmationHTMLParser(HTMLParserEx):
         self.message = ""
         self.inputs = []
         self.complete = False
         self.message = ""
         self.inputs = []
         self.complete = False
+        self.title = ""
+        self.in_head = False
+        self.in_title = False
 
     def handle_starttag(self, tag, attr):
         if tag == "br":
             self.message += "\n"
         elif tag == "input":
             self.inputs.append(dict(attr))
 
     def handle_starttag(self, tag, attr):
         if tag == "br":
             self.message += "\n"
         elif tag == "input":
             self.inputs.append(dict(attr))
+        elif tag == "title":
+            self.in_title = True
+        elif tag == "head":
+            self.in_head = True
         elif tag == "meta":
             attr_dict = dict(attr)
             if "http-equiv" in attr_dict \
         elif tag == "meta":
             attr_dict = dict(attr)
             if "http-equiv" in attr_dict \
@@ -68,13 +75,19 @@ class ConfirmationHTMLParser(HTMLParserEx):
                 self.complete = True
 
     def handle_endtag(self, tag):
                 self.complete = True
 
     def handle_endtag(self, tag):
-        pass
+        if tag == "title":
+            self.in_title = False
+        elif tag == "head":
+            self.in_head = False
 
     def handle_comment(self, comment):
 
     def handle_comment(self, comment):
-        print comment.strip()
+        pass
 
     def handle_data(self, data):
 
     def handle_data(self, data):
-        self.message += data
+        if self.in_title:
+            self.title = data
+        elif not self.in_head:
+            self.message += data.rstrip()
 
     def handle_charref(self, ref):
         data = None
 
     def handle_charref(self, ref):
         data = None
@@ -170,6 +183,8 @@ class WinWrap:
         window = gtk.Window()
         if not p.complete:
             window.set_default_size(500, 500)
         window = gtk.Window()
         if not p.complete:
             window.set_default_size(500, 500)
+        if p.title:
+            window.set_title(p.title)
         textview = gtk.TextView()
         textview.set_wrap_mode(gtk.WRAP_CHAR)
         textview.set_editable(False)
         textview = gtk.TextView()
         textview.set_wrap_mode(gtk.WRAP_CHAR)
         textview.set_editable(False)