]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_robot_base.py
Feat(robots): Handle HTTP redirect 308
[bookmarks_db.git] / Robots / bkmk_robot_base.py
index b5cac691fe9f2842d12184f30de6c6b2271dbb83..1d762d94d1713f951d583f120d658f2f9f8d17dd 100644 (file)
@@ -29,10 +29,11 @@ from parse_html import parse_html
 
 
 reloc_dict = {
-  301: "perm.",
+  301: "perm1.",
   302: "temp2.",
   303: "temp3.",
   307: "temp7.",
+  308: "temp8.",
   "html": "html"
 }
 
@@ -274,8 +275,15 @@ class robot_base(Robot):
         return 1
 
     def set_redirect(self, bookmark, errcode, newurl):
-        bookmark.moved = "(%s) to %s" % (reloc_dict[errcode], newurl)
-        self.log('   Moved: %s' % bookmark.moved)
+        bookmark.moved = moved = "(%s) to %s" % (reloc_dict[errcode], newurl)
+        try:
+            moved.encode('ascii')
+        except UnicodeEncodeError:
+            try:
+                moved = moved.encode(bookmark.charset)
+            except (LookupError, TypeError, UnicodeEncodeError):
+                moved = moved.encode('utf-8')
+        self.log('   Moved: %s' % moved)
 
     def finish_check_url(self, bookmark):
         start = self.start