]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_robot_base.py
Feat(Python3): Fix lambda
[bookmarks_db.git] / Robots / bkmk_robot_base.py
index 30a26bf137138ef40b4da218efeab4be64acc399..8dd032b714e076a75f4bd38ab8db10d65ed45830 100644 (file)
@@ -5,19 +5,21 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __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())
@@ -192,7 +200,7 @@ class robot_base(Robot):
                            pass # float timeout
                         self.set_redirect(bookmark, "html", "%s (%s sec)" % (url, timeout))
 
-            except KeyError, key:
+            except KeyError as key:
                self.log("   no header: %s" % key)
 
       except EOFError:
@@ -203,6 +211,10 @@ class robot_base(Robot):
          self.log("Keyboard interrupt (^C)")
          return 0
 
+      except socket.error as e:
+         bookmark.error = get_error(e)
+         self.log(bookmark.error)
+
       except:
          import traceback
          traceback.print_exc()