]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_rsimple.py
Handle redirect 303
[bookmarks_db.git] / Robots / bkmk_rsimple.py
index c2733a184ce5f6352e3b201e751b65404bf32b49..9ab40a3b7f30c37ee52a9c6fe20039608f5e47c1 100644 (file)
@@ -1,9 +1,16 @@
-"""
-   Simple, strightforward robot
+"""Simple, strightforward robot
+
+This file is a part of Bookmarks database and Internet robot.
 
-   Written by Oleg Broytman. Copyright (C) 2000-2010 PhiloSoft Design.
 """
 
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__license__ = "GNU GPL"
+
+__all__ = ['robot_simple', 'get_error']
+
+
 import sys, os
 import time, urllib
 from base64 import b64encode
@@ -19,7 +26,9 @@ from parse_html import parse_html
 class RedirectException(Exception):
    reloc_dict = {
       301: "perm.",
-      302: "temp.",
+      302: "temp2.",
+      303: "temp3.",
+      307: "temp7.",
       "html": "html"
    }
    def __init__(self, errcode, newurl):
@@ -187,9 +196,9 @@ class robot_simple(Robot):
                      if icons[icon]:
                         bookmark.icon_href = icon
                         content_type, bookmark.icon = icons[icon]
-                        self.log("       cached icon: %s" % content_type)
+                        self.log("   cached icon: %s" % content_type)
                      else:
-                        self.log("       cached icon: no icon")
+                        self.log("   cached icon: no icon")
                   else:
                      try:
                         _icon = icon
@@ -198,7 +207,7 @@ class robot_simple(Robot):
                               icon_fname, headers = urllib.urlretrieve(_icon)
                            except RedirectException, e:
                               _icon = e.url
-                              self.log("       redirect to : %s" % _icon)
+                              self.log("   redirect to : %s" % _icon)
                            else:
                               break
                         else:
@@ -220,7 +229,7 @@ class robot_simple(Robot):
                            self.log("   got icon       : %s" % content_type)
                            if content_type.startswith("application/") \
                                  or content_type.startswith("text/plain"):
-                              self.log("   got non-image icon, assume x-icon")
+                              self.log("   non-image content type, assume x-icon")
                               content_type = 'image/x-icon'
                            bookmark.icon = "data:%s;base64,%s" % (content_type, b64encode(icon_data))
                            icons[icon] = (content_type, bookmark.icon)
@@ -279,7 +288,6 @@ class robot_simple(Robot):
       # Tested
       return 1
 
-
    def finish_check_url(self, bookmark, fname=None):
       # Calculate these attributes even in case of an error
       if fname and os.path.exists(fname):