From: Oleg Broytman Date: Sun, 6 Jul 2014 12:02:23 +0000 (+0400) Subject: Merge bkmk_rurllib_to.py into bkmk_robot_base.py X-Git-Tag: v4.6.0~4 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=7c67f205b840eae593185f531d6d5729be3360cb;p=bookmarks_db.git Merge bkmk_rurllib_to.py into bkmk_robot_base.py --- diff --git a/Robots/bkmk_robot_base.py b/Robots/bkmk_robot_base.py index 30a26bf..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 @@ -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()) @@ -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() diff --git a/Robots/bkmk_rurllib_to.py b/Robots/bkmk_rurllib_to.py deleted file mode 100644 index 30ec08e..0000000 --- a/Robots/bkmk_rurllib_to.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Simple robot with socket's timeout - -This file is a part of Bookmarks database and Internet robot. - -""" - -__author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2000-2014 PhiloSoft Design" -__license__ = "GNU GPL" - -__all__ = ['robot_urllib_to'] - - -import socket -from .bkmk_rurllib import robot_urllib, get_error - - -class robot_urllib_to(robot_urllib): - timeout = 60 - - def __init__(self, *args, **kw): - robot_urllib.__init__(self, *args, **kw) - socket.setdefaulttimeout(int(self.timeout)) - - def check_url(self, bookmark): - try: - return robot_urllib.check_url(self, bookmark) - except socket.error, msg: - bookmark.error = get_error(msg) - self.log(bookmark.error) - return 1 diff --git a/doc/TODO b/doc/TODO index f98d076..7200899 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,4 +1,4 @@ -Robot based on urllib2: handle timeout and ftp. +Robot based on urllib2: handle ftp (welcome message). A new robot based on PycURL.