X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fbkmk_robot_base.py;h=eb69c28bb31ed783073b318dc3722a706bb8e9ff;hb=71f7553119f3efe154d1154dd85f1ceecc46f641;hp=80079b4d9006a45793d212b898b319c004a3a5c9;hpb=c19fbf714f025012d089aa86e4fa8e3b46f3a01e;p=bookmarks_db.git diff --git a/Robots/bkmk_robot_base.py b/Robots/bkmk_robot_base.py index 80079b4..eb69c28 100644 --- a/Robots/bkmk_robot_base.py +++ b/Robots/bkmk_robot_base.py @@ -11,13 +11,15 @@ __license__ = "GNU GPL" __all__ = ['robot_base', 'get_error'] -import sys -import time, urllib from base64 import b64encode +import sys +import socket +import time +import urllib from urlparse import urljoin -from m_lib.net.www.util import parse_time from m_lib.md5wrapper import md5wrapper +from m_lib.net.www.util import parse_time from bkmk_objects import Robot from parse_html import parse_html @@ -32,13 +34,13 @@ reloc_dict = { } -def get_error(msg): - if isinstance(msg, str): - return msg +def get_error(e): + if isinstance(e, str): + return e else: s = [] - for i in msg: + for i in e: s.append("'%s'" % str(i).replace('\n', "\\n")) return "(%s)" % ' '.join(s) @@ -47,6 +49,12 @@ icons = {} # Icon cache; maps URL to a tuple (content type, data) # or None if there is no icon. class robot_base(Robot): + timeout = 60 + + def __init__(self, *args, **kw): + Robot.__init__(self, *args, **kw) + socket.setdefaulttimeout(int(self.timeout)) + def check_url(self, bookmark): try: self.start = int(time.time()) @@ -95,7 +103,7 @@ class robot_base(Robot): bookmark.last_modified = last_modified md5 = md5wrapper() - if urllib._urlopener.type == "ftp": # Pass welcome message through MD5 + if url_type == "ftp": # Pass welcome message through MD5 md5.update(self.get_ftp_welcome()) md5.update(content) @@ -203,6 +211,10 @@ class robot_base(Robot): self.log("Keyboard interrupt (^C)") return 0 + except socket.error, e: + bookmark.error = get_error(e) + self.log(bookmark.error) + except: import traceback traceback.print_exc() @@ -222,8 +234,5 @@ class robot_base(Robot): def finish_check_url(self, bookmark): start = self.start bookmark.last_tested = str(start) - now = int(time.time()) bookmark.test_time = str(now - start) - - self.cleanup()