]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_rurllib.py
Feat(robots): Handle HTTP redirect 308
[bookmarks_db.git] / Robots / bkmk_rurllib.py
index 1b3182ea04de146e44fe0ac219599a30517ca34e..067799c737271b5ceeb373eeb321bc12eaf1e7ec 100644 (file)
@@ -27,9 +27,9 @@ class RedirectException(Exception):
 class MyURLopener(urllib.URLopener):
     # Error 301 -- relocated (permanently)
     def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
-        if headers.has_key('location'):
+        if 'location' in headers:
             newurl = headers['location']
-        elif headers.has_key('uri'):
+        elif 'uri' in headers:
             newurl = headers['uri']
         else:
             newurl = "Nowhere"
@@ -41,6 +41,8 @@ class MyURLopener(urllib.URLopener):
     http_error_303 = http_error_301
     # Error 307 -- relocated (temporarily)
     http_error_307 = http_error_301
+    # Error 308 -- relocated (permanently)
+    http_error_308 = http_error_301
 
     # Error 401 -- authentication required
     def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
@@ -102,7 +104,7 @@ class robot_urllib(robot_base):
                     # Remove Accept-Charset
                     del urllib._urlopener.addheaders[-1]
 
-            infile = open(fname, 'rb')
+            infile = open(fname, 'rt')
             content = infile.read()
             infile.close()