Catchier exceptions, minor optimizations.
This commit is contained in:
parent
e5ca44e251
commit
5a1b9d17c4
13
buku
13
buku
@ -226,8 +226,7 @@ def getPageResp(url, redir=False):
|
|||||||
urlconn.request("GET", url, None, {
|
urlconn.request("GET", url, None, {
|
||||||
"Accept-encoding": "gzip",
|
"Accept-encoding": "gzip",
|
||||||
})
|
})
|
||||||
resp = urlconn.getresponse()
|
return (urlconn, urlconn.getresponse())
|
||||||
return (urlconn, resp)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -238,11 +237,9 @@ def getTitleData(resp):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
charset = ''
|
|
||||||
charset = resp.headers.get_content_charset()
|
charset = resp.headers.get_content_charset()
|
||||||
|
|
||||||
if resp.headers.get('Content-Encoding') == 'gzip':
|
if resp.headers.get('Content-Encoding') == 'gzip':
|
||||||
print("gzip")
|
|
||||||
data = gzip.GzipFile(fileobj=io.BytesIO(resp.read())).read()
|
data = gzip.GzipFile(fileobj=io.BytesIO(resp.read())).read()
|
||||||
else:
|
else:
|
||||||
data = resp.read()
|
data = resp.read()
|
||||||
@ -260,7 +257,7 @@ def getTitleData(resp):
|
|||||||
parser.feed(data.decode(charset))
|
parser.feed(data.decode(charset))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug:
|
if debug:
|
||||||
print("Exception [getTitleData]: %s" % e)
|
print("\x1b[1mEXCEPTION\x1b[21m [getTitleData]: %s" % e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -308,7 +305,7 @@ def fetchTitle(url):
|
|||||||
printmsg(("[" + str(resp.status) + "] " + resp.reason), "ERROR")
|
printmsg(("[" + str(resp.status) + "] " + resp.reason), "ERROR")
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception [fetchTitle]: %s" % e)
|
print("\x1b[1mEXCEPTION\x1b[21m [fetchTitle]: %s" % e)
|
||||||
finally:
|
finally:
|
||||||
if urlconn is not None:
|
if urlconn is not None:
|
||||||
urlconn.close()
|
urlconn.close()
|
||||||
@ -481,7 +478,7 @@ def searchdb(cur, keywords):
|
|||||||
openurl = unquote(results[int(nav) - 1])
|
openurl = unquote(results[int(nav) - 1])
|
||||||
browser_open(openurl)
|
browser_open(openurl)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception [searchdb]: %s" % e)
|
print("\x1b[1mEXCEPTION\x1b[21m [searchdb]: %s" % e)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -691,7 +688,7 @@ def browser_open(url):
|
|||||||
try:
|
try:
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception [browser_open]: %s" % e)
|
print("\x1b[1mEXCEPTION\x1b[21m [browser_open]: %s" % e)
|
||||||
finally:
|
finally:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
os.dup2(_stderr, 2)
|
os.dup2(_stderr, 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user