X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fbkmk_rurllib.py;h=d9908b83292ab92fcfd107710446555cd3aab712;hb=d2c2975d4cd9375460c7bbaaa3b6dbb855e84b86;hp=f0a614e3799e1ccae9750bd57fbbf5c4f99ccd90;hpb=9d989c8c9ebd7f13e9f0fdc95fa139c99ed83387;p=bookmarks_db.git diff --git a/Robots/bkmk_rurllib.py b/Robots/bkmk_rurllib.py index f0a614e..d9908b8 100644 --- a/Robots/bkmk_rurllib.py +++ b/Robots/bkmk_rurllib.py @@ -17,8 +17,8 @@ from Robots.bkmk_robot_base import robot_base, RedirectException, get_error class MyURLopener(urllib.URLopener): - # Error 302 -- relocated (temporarily) - def http_error_302(self, url, fp, errcode, errmsg, headers, data=None): + # Error 301 -- relocated (permanently) + def http_error_301(self, url, fp, errcode, errmsg, headers, data=None): if headers.has_key('location'): newurl = headers['location'] elif headers.has_key('uri'): @@ -27,10 +27,12 @@ class MyURLopener(urllib.URLopener): newurl = "Nowhere" raise RedirectException(errcode, newurl) - # Error 301 -- also relocated (permanently) - http_error_301 = http_error_302 - # Error 307 -- also relocated (temporary) - http_error_307 = http_error_302 + # Error 302 -- relocated (temporarily) + http_error_302 = http_error_301 + # Error 303 -- relocated (see other) + http_error_303 = http_error_301 + # Error 307 -- relocated (temporarily) + http_error_307 = http_error_301 # Error 401 -- authentication required def http_error_401(self, url, fp, errcode, errmsg, headers, data=None): @@ -72,32 +74,35 @@ urllib.ftpwrapper = myftpwrapper class robot_urllib(robot_base): - def urlretrieve(self, bookmark, url, accept_charset=False): + def get(self, bookmark, url, accept_charset=False): try: # Set fake referer to the base URL urllib._urlopener.addheaders[2] = ('Referer', url) if accept_charset and bookmark.charset: urllib._urlopener.addheader('Accept-Charset', bookmark.charset) - fname, headers = urllib.urlretrieve(url) - if accept_charset and bookmark.charset: - del urllib._urlopener.addheaders[-1] + try: + fname, headers = urllib.urlretrieve(url) + finally: + if accept_charset and bookmark.charset: + del urllib._urlopener.addheaders[-1] # Remove Accept-Charset infile = open(fname, 'rb') content = infile.read() infile.close() - return headers, content + return None, headers, content except IOError, msg: if (msg[0] == "http error") and (msg[1] == -1): + error = None bookmark.no_error = "The server did not return any header - it is not an error, actually" self.log(' no headers: %s' % bookmark.no_error) else: - bookmark.error = get_error(msg) - self.log(' Error: %s' % bookmark.error) + error = get_error(msg) + self.log(' Error: %s' % error) - return None, None + return error, None, None def get_ftp_welcome(self): global ftpcache_key