]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_rsimple.py
Get icon's URL.
[bookmarks_db.git] / Robots / bkmk_rsimple.py
index 2a18beb72edad934fa1120c1f9e9fb3035130c75..c34a12728d136307da774e5a6ac086622bf51515 100644 (file)
@@ -1,10 +1,17 @@
 """
-   Simple, strightforward robot; guaranteed to has problems with timeouts :)
+   Simple, strightforward robot
 
-   Written by BroytMann, Mar 2000 - Aug 2002. Copyright (C) 2000-2002 PhiloSoft Design
+   Written by Oleg BroytMann. Copyright (C) 2000-2007 PhiloSoft Design.
 """
 
 
+import string, os
+import time, urllib
+from urlparse import urljoin
+from m_lib.net.www.util import parse_time
+from m_lib.md5wrapper import md5wrapper
+
+
 class RedirectException(Exception):
    reloc_dict = {
       301: "perm.",
@@ -15,12 +22,6 @@ class RedirectException(Exception):
       Exception.__init__(self, "(%s) to %s" % (self.reloc_dict[errcode], newurl))
 
 
-import string, os
-import time, urllib
-from m_lib.net.www.util import parse_time
-from m_lib.md5wrapper import md5wrapper
-
-
 class MyURLopener(urllib.URLopener):
    # Error 302 -- relocated (temporarily)
    def http_error_302(self, url, fp, errcode, errmsg, headers, data=None): 
@@ -91,7 +92,9 @@ class robot_simple(Robot):
             url_host, url_path = urllib.splithost(url_rest)
             url_path, url_tag  = urllib.splittag(url_path)
 
+            if bookmark.charset: urllib._urlopener.addheader('Accept-Charset', bookmark.charset)
             fname, headers = urllib.urlretrieve("%s://%s%s" % (url_type, url_host, url_path), self.tempfname)
+            if bookmark.charset: del urllib._urlopener.addheaders[-1]
 
             size = 0
             last_modified = None
@@ -155,6 +158,11 @@ class robot_simple(Robot):
                            raise RedirectException("html", "Bad redirect to %s (%s)" % (url, refresh))
                         else:
                            raise RedirectException("html", "%s (%d sec)" % (url, timeout))
+                     icon = parser.icon
+                     if not icon:
+                        icon = "/favicon.ico"
+                     icon = urljoin("%s://%s" % (url_type, url_host), icon)
+                     if self.log: self.log("   icon           : %s" % icon)
                except KeyError:
                   pass