OSDN Git Service

Add User-Agent.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 15 Sep 2006 01:09:27 +0000 (10:09 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 15 Sep 2006 01:09:27 +0000 (10:09 +0900)
src/FukuiNoNamari/board_data.py
src/FukuiNoNamari/bookmark_list.py
src/FukuiNoNamari/config.py
src/FukuiNoNamari/submit_window.py
src/FukuiNoNamari/thread_window.py

index cc177e0..97a6bda 100644 (file)
@@ -26,6 +26,7 @@ import itertools
 import cachefile
 import idxfile
 import misc
+import config
 from http_sub import HTTPRedirectHandler302, HTTPDebugHandler
 
 BOARD_DATA_INVALID_VALUE = 0
@@ -168,8 +169,10 @@ class BoardData:
         # get subject.txt
 
         opener = urllib2.build_opener(HTTPRedirectHandler302, HTTPDebugHandler)
+        request = urllib2.Request(self.bbs_type.get_subject_txt_uri())
+        request.add_header("User-agent", config.User_Agent)
         try:
-            response = opener.open(self.bbs_type.get_subject_txt_uri())
+            response = opener.open(request)
         except urllib2.HTTPError, e:
             gobject.idle_add(self.set_status, "%d %s" % (e.code, e.msg))
             print "switch to local"
index de833ff..a3d1d7a 100644 (file)
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 import re
-import urllib
+import urllib2
 import codecs
 import traceback
 import os
 import os.path
 
+import config
+from http_sub import HTTPRedirectHandler302, HTTPDebugHandler
 from bookmark_core import BookmarkFormatError, Bookmark
 from bookmark_editwindow import BookmarkEditWindow
 
@@ -86,8 +88,11 @@ class BookmarkList(object):
         encoding = "cp932"
 
         current_category = ""
+        opener = urllib2.build_opener(HTTPRedirectHandler302, HTTPDebugHandler)
+        req = urllib2.Request(self.__bbsmenu_uri)
+        req.add_header("User-agent", config.User_Agent)
         try:
-            for line in urllib.urlopen(self.__bbsmenu_uri):
+            for line in opener.open(req):
                 line = line.decode(encoding, "replace").strip()
                 if line:
                     if not current_category:
index 5bfce95..bddbad0 100644 (file)
@@ -18,6 +18,7 @@
 import os.path
 
 APPNAME = "example-1.0"
+User_Agent = "FukuiNoNamari/0.1"
 
 def get_config_dir_path():
     return os.path.expanduser("~/." + APPNAME.lower())
index 6524ab5..07b1889 100644 (file)
@@ -31,6 +31,7 @@ from BbsType import bbs_type_exception
 from HTMLParserEx import HTMLParserEx
 import datfile
 import uri_opener
+import config
 from http_sub import HTTPDebugHandler
 
 GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
@@ -152,6 +153,7 @@ class WinWrap:
 
         req = urllib2.Request(self.bbs_type.get_post_uri(), post_encoded)
         req.add_header("Referer", self.uri)
+        req.add_header("User-agent", config.User_Agent)
 
         res = opener.open(req)
         self.on_response(res)
index 6a14b33..16de1b7 100644 (file)
@@ -287,6 +287,7 @@ class WinWrap(winwrapbase.WinWrapBase):
         etag = idx_dic["etag"]
 
         req = urllib2.Request(datfile_url)
+        req.add_header("User-agent", config.User_Agent)
         if self.size > 0:
             req.add_header("Range", "bytes=" + str(self.size) + "-")
         if lastmod: