OSDN Git Service

Not redirect when http 302 Found.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Wed, 23 Aug 2006 15:04:46 +0000 (00:04 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Wed, 23 Aug 2006 15:04:46 +0000 (00:04 +0900)
src/Hage1/http_sub.py [new file with mode: 0644]
src/Hage1/subjecttxtfile.py
src/Hage1/thread_window.py

diff --git a/src/Hage1/http_sub.py b/src/Hage1/http_sub.py
new file mode 100644 (file)
index 0000000..25f8130
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright (C) 2006 by Aiwota Programmer
+# aiwotaprog@tetteke.tk
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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 HTTPError
+
+
+class HTTPRedirectHandler302(HTTPRedirectHandler):
+    """Not process 302"""
+
+    def http_error_302(self, req, fp, code, msg, hdrs):
+        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
index 8f20faf..49b92f3 100644 (file)
 import re
 import os.path
 import codecs
-import urllib
+import urllib2
 from misc import get_board_subjecttxt_path
 from misc import get_board_idx_path
+from http_sub import HTTPRedirectHandler302
 
 REG_EXPR = re.compile("(?P<id>.*).dat<>(?P<title>.*)\((?P<res>\d*)\)")
 
@@ -52,10 +53,16 @@ def load_subjecttxt(bbs, board, func):
     analyze_subjecttxt(subjecttxt_encoded.decode("cp932", "replace"), func)
 
 def get_subjecttxt(bbs, board, uri):
-    u = urllib.urlopen(uri)
-    subjecttxt_encoded = u.read()
-    info = u.info()
 
+    # get subject.txt
+
+    opener = urllib2.build_opener(HTTPRedirectHandler302)
+    response = opener.open(uri)
+    info = response.info()
+    print info
+    subjecttxt_encoded = response.read()
+
+    # save subject.txt
     subjecttxt_path = get_board_subjecttxt_path(bbs, board)
     
     basedir = os.path.dirname(subjecttxt_path)
index 9ba6261..025f339 100644 (file)
@@ -31,6 +31,7 @@ import barehtmlparser
 import idxfile
 import session
 import board_window
+from http_sub import HTTPRedirectHandler302
 
 GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "..", "data")
@@ -116,7 +117,8 @@ class WinWrap:
             req.add_header("If-None-Match", etag)
         print req.headers
 
-        res = urllib2.urlopen(req)
+        opener = urllib2.build_opener(HTTPRedirectHandler302)
+        res = opener.open(req)
         headers = res.info()
         print headers