]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_rsimple.py
Robots no longer have one global temporary file - there are at least two
[bookmarks_db.git] / Robots / bkmk_rsimple.py
index e01c7fece23cd612362ef862af0d486a580bfcdc..69636d9ef09044905962a3930fc8789e32b45ebc 100644 (file)
@@ -105,9 +105,6 @@ icons = {} # Icon cache; maps URL to a tuple (content type, data)
 
 class robot_simple(Robot):
    def check_url(self, bookmark):
-      if not self.tempfname:
-         self.tempfname = bookmark.tempfname
-
       try:
          self.start = int(time.time())
          bookmark.icon = None
@@ -120,7 +117,7 @@ class robot_simple(Robot):
          urllib._urlopener.addheaders[2] = ('Referer', "%s://%s%s" % (url_type, url_host, 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)
+         fname, headers = urllib.urlretrieve("%s://%s%s" % (url_type, url_host, url_path))
          if bookmark.charset: del urllib._urlopener.addheaders[-1]
 
          size = 0
@@ -152,7 +149,7 @@ class robot_simple(Robot):
          if urllib._urlopener.type == "ftp": # Pass welcome message through MD5
             md5.update(get_welcome())
 
-         md5.md5file(self.tempfname)
+         md5.md5file(fname)
          bookmark.md5 = str(md5)
 
          if headers:
@@ -215,7 +212,7 @@ class robot_simple(Robot):
                         _icon = icon
                         for i in range(8):
                            try:
-                              fname, headers = urllib.urlretrieve(_icon)
+                              icon_fname, headers = urllib.urlretrieve(_icon)
                            except RedirectException, e:
                               _icon = e.url
                               self.log("       redirect to : %s" % _icon)
@@ -233,7 +230,7 @@ class robot_simple(Robot):
                      else:
                         content_type = headers["Content-Type"]
                         if content_type.startswith("image/"):
-                           icon_file = open(fname, "rb")
+                           icon_file = open(icon_fname, "rb")
                            icon_data = icon_file.read()
                            icon_file.close()
                            bookmark.icon_href = icon
@@ -243,7 +240,7 @@ class robot_simple(Robot):
                         else:
                            self.log("   no icon        : bad content type '%s'" % content_type)
                            icons[icon] = None
-                        os.remove(fname)
+                        os.remove(icon_fname)
 
             except KeyError, key:
                self.log("   no header: %s" % key)
@@ -275,16 +272,16 @@ class robot_simple(Robot):
          self.log('   Exception: %s' % bookmark.error)
 
       finally:
-         self.finish_check_url(bookmark)
+         self.finish_check_url(bookmark, fname)
 
       # Tested
       return 1
 
 
-   def finish_check_url(self, bookmark):
+   def finish_check_url(self, bookmark, fname=None):
       # Calculate these attributes even in case of an error
-      if os.path.exists(self.tempfname):
-         size = str(os.path.getsize(self.tempfname))
+      if fname and os.path.exists(fname):
+         size = str(os.path.getsize(fname))
          if size[-1] == 'L':
             size = size[:-1]
          bookmark.size = size