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
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
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:
_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)
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
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)
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