OSDN Git Service

Add HTTP header output.
[fukui-no-namari/fukui-no-namari.git] / src / FukuiNoNamari / thread_window.py
index 41728ac..ad7e392 100644 (file)
@@ -39,7 +39,7 @@ import idxfile
 import session
 import board_window
 import uri_opener
-from http_sub import HTTPRedirectHandler302
+from http_sub import HTTPRedirectHandler302, HTTPDebugHandler
 from BbsType import bbs_type_judge_uri
 from BbsType import bbs_type_exception
 import config
@@ -262,48 +262,53 @@ class WinWrap(winwrapbase.WinWrapBase):
             req.add_header("If-Modified-Since", lastmod)
         if etag:
             req.add_header("If-None-Match", etag)
-        print req.headers
-
-        opener = urllib2.build_opener(HTTPRedirectHandler302)
-        res = opener.open(req)
-        headers = res.info()
-        print headers
-
-        line = res.readline()
-        maybe_incomplete = False
-        while line:
-            if not line.endswith("\n"):
-                maybe_incomplete = True
-                print "does not end with \\n. maybe incomplete"
-                break
-            on_get_res(line)
-            line = res.readline()
-
-        res.close()
 
-        if maybe_incomplete:
-            lastmod = None
-            etag = None
+        opener = urllib2.build_opener(HTTPRedirectHandler302, HTTPDebugHandler)
+        try:
+            res = opener.open(req)
+        except urllib2.HTTPError, e:
+            gobject.idle_add(
+                self.statusbar.set_status, "%d %s" % (e.code, e.msg))
         else:
-            if "Last-Modified" in headers:
-                lastmod = headers["Last-Modified"]
-            if "ETag" in headers:
-                etag = headers["Etag"]
-
-        if self.num > 0:
-            if not self.title:
-                title = datfile.get_title_from_dat(
-                    self.bbs, self.board, self.thread)
-                if title:
-                    self.title = title
-                    gobject.idle_add(self.window.set_title, title)
-            # save idx
-            idx_dic = {"title": self.title, "lineCount": self.num,
-                   "lastModified": lastmod, "etag": etag}
-            idxfile.save_idx(self.bbs, self.board, self.thread, idx_dic)
-
-            gobject.idle_add(session.thread_idx_updated,
-                             self.bbs_type.get_thread_uri(), idx_dic)
+            headers = res.info()
+            gobject.idle_add(
+                self.statusbar.set_status, "%d %s" % (res.code, res.msg))
+
+            line = res.readline()
+            maybe_incomplete = False
+            while line:
+                if not line.endswith("\n"):
+                    maybe_incomplete = True
+                    print "does not end with \\n. maybe incomplete"
+                    break
+                on_get_res(line)
+                line = res.readline()
+
+            res.close()
+
+            if maybe_incomplete:
+                lastmod = None
+                etag = None
+            else:
+                if "Last-Modified" in headers:
+                    lastmod = headers["Last-Modified"]
+                if "ETag" in headers:
+                    etag = headers["Etag"]
+
+            if self.num > 0:
+                if not self.title:
+                    title = datfile.get_title_from_dat(
+                        self.bbs, self.board, self.thread)
+                    if title:
+                        self.title = title
+                        gobject.idle_add(self.window.set_title, title)
+                # save idx
+                idx_dic = {"title": self.title, "lineCount": self.num,
+                       "lastModified": lastmod, "etag": etag}
+                idxfile.save_idx(self.bbs, self.board, self.thread, idx_dic)
+
+                gobject.idle_add(session.thread_idx_updated,
+                                 self.bbs_type.get_thread_uri(), idx_dic)
 
     def update(self, widget=None):