OSDN Git Service

Add HTTP header output.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 5 Sep 2006 05:31:58 +0000 (14:31 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 5 Sep 2006 05:31:58 +0000 (14:31 +0900)
src/FukuiNoNamari/board_data.py
src/FukuiNoNamari/http_sub.py
src/FukuiNoNamari/submit_window.py
src/FukuiNoNamari/thread_window.py

index 227c72a..c381921 100644 (file)
@@ -27,7 +27,7 @@ import itertools
 import cachefile
 import idxfile
 import misc
-from http_sub import HTTPRedirectHandler302
+from http_sub import HTTPRedirectHandler302, HTTPDebugHandler
 
 BOARD_DATA_INVALID_VALUE = 0
 REG_EXPR = re.compile("(?P<id>.*).dat<>(?P<title>.*)\((?P<res>\d*)\)")
@@ -167,13 +167,11 @@ class BoardData:
 
         # get subject.txt
 
-        opener = urllib2.build_opener(HTTPRedirectHandler302)
+        opener = urllib2.build_opener(HTTPRedirectHandler302, HTTPDebugHandler)
         try:
             response = opener.open(self.bbs_type.get_subject_txt_uri())
         except urllib2.HTTPError, e:
-            print "%d %s" % (e.code, e.msg)
             gobject.idle_add(self.set_status, "%d %s" % (e.code, e.msg))
-            print e.info()
             print "switch to local"
             self._load_subjecttxt(func)
         except urllib2.URLError, e:
@@ -183,10 +181,8 @@ class BoardData:
             self._load_subjecttxt(func)
         else:
             status = "%d %s" % (response.code, response.msg)
-            print status
             gobject.idle_add(self.set_status, status)
             info = response.info()
-            print info
 
             lastmod = 0
             if "Last-Modified" in info:
index 25f8130..5d9269a 100644 (file)
@@ -15,7 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-from urllib2 import HTTPRedirectHandler
+from urllib2 import HTTPRedirectHandler, BaseHandler
 from urllib2 import HTTPError
 
 
@@ -24,3 +24,17 @@ class HTTPRedirectHandler302(HTTPRedirectHandler):
 
     def http_error_302(self, req, fp, code, msg, hdrs):
         raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
+
+
+class HTTPDebugHandler(BaseHandler):
+
+    def http_request(self, req):
+        print req.get_method(), req.get_full_url()
+        for field in req.header_items():
+            print "%s: %s" % field
+        return req
+
+    def http_response(self, req, response):
+        print "%d %s" % (response.code, response.msg)
+        print response.info()
+        return response
index 0be215d..c2e435c 100644 (file)
@@ -32,13 +32,15 @@ from BbsType import bbs_type_exception
 from HTMLParserEx import HTMLParserEx
 import datfile
 import uri_opener
+from http_sub import HTTPDebugHandler
 
 GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "..", "data")
 GLADE_FILENAME = "submit_window.glade"
 
 cookie_jar = cookielib.CookieJar()
-opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
+opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar),
+                              HTTPDebugHandler)
 
 def open(uri):
     if not uri:
index 153d85e..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,18 +262,15 @@ 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)
+        opener = urllib2.build_opener(HTTPRedirectHandler302, HTTPDebugHandler)
         try:
             res = opener.open(req)
         except urllib2.HTTPError, e:
-            print e.info()
             gobject.idle_add(
                 self.statusbar.set_status, "%d %s" % (e.code, e.msg))
         else:
             headers = res.info()
-            print headers
             gobject.idle_add(
                 self.statusbar.set_status, "%d %s" % (res.code, res.msg))