X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fbkmk_rurllib2.py;h=66f04600135d648b281e52952a3e53c84d44bc22;hb=cb9c36b39ed72cd1fa272130d2bcf162a89c3013;hp=d9c91491be35f384d4d35d802111e3522e74e6a7;hpb=7915c0f51c9b7556d6af1de9582f68e98f473799;p=bookmarks_db.git diff --git a/Robots/bkmk_rurllib2.py b/Robots/bkmk_rurllib2.py index d9c9149..66f0460 100644 --- a/Robots/bkmk_rurllib2.py +++ b/Robots/bkmk_rurllib2.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2014 PhiloSoft Design" +__copyright__ = "Copyright (C) 2014-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['robot_urllib2'] @@ -19,6 +19,7 @@ from Robots.bkmk_robot_base import robot_base, get_error _fw = None + class FTPHandler(urllib2.FTPHandler): def connect_ftp(self, user, passwd, host, port, dirs, timeout): global _fw @@ -39,7 +40,8 @@ urllib2.install_opener(opener) # Fake headers to pretend this is a real browser -_user_agent = "Mozilla/5.0 (X11; Linux i686; rv:30.0) Gecko/20100101 Firefox/30.0" +_user_agent = "Mozilla/5.0 (X11; Linux i686; rv:30.0)" +" Gecko/20100101 Firefox/30.0" _x_user_agent = "bookmarks_db (Python %d.%d.%d; urllib2)" % ( sys.version_info[0], sys.version_info[1], sys.version_info[2]) @@ -63,23 +65,24 @@ class robot_urllib2(robot_base): try: response = urllib2.urlopen(request) - except urllib2.HTTPError, e: + except urllib2.HTTPError as e: if e.code in (301, 302, 303, 307): return None, e.code, e.hdrs['Location'], None, None else: self.log(' HTTP Error %s: %s' % (e.code, e.msg)) - return "HTTP Error %s: %s" % (e.code, e.msg), None, None, None, None + return ("HTTP Error %s: %s" % (e.code, e.msg), + None, None, None, None) - except urllib2.URLError, e: + except urllib2.URLError as e: self.log(' URL Error: %s' % e.reason) return "URL Error: %s" % e.reason, None, None, None, None - except httplib.HTTPException, e: + except httplib.HTTPException as e: error = get_error(e) self.log(' HTTP Exception: %s' % error) return "HTTP Exception: %s" % error, None, None, None, None - except IOError, e: + except IOError as e: error = get_error(e) self.log(' I/O Error: %s' % error) return "I/O Error: %s" % error, None, None, None, None