De-uglified urllib2.URLErrors and cleaned up a couple blocks in plugins/Http.py

This commit is contained in:
James Vega 2004-08-17 02:52:40 +00:00
parent 4a8e60b087
commit 0ee2ff4fbb
2 changed files with 8 additions and 9 deletions

View File

@ -74,9 +74,12 @@ class Http(callbacks.Privmsg):
if not url.startswith('http://'):
irc.error('Only HTTP urls are valid.')
return
fd = webutils.getUrlFd(url)
s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()])
irc.reply(s)
try:
fd = webutils.getUrlFd(url)
s = ', '.join(['%s: %s' % (k, v) for (k, v) in fd.headers.items()])
irc.reply(s)
finally:
fd.close()
_doctypeRe = re.compile(r'(<!DOCTYPE[^>]+>)', re.M)
def doctype(self, irc, msg, args):
@ -385,11 +388,7 @@ class Http(callbacks.Privmsg):
return
url = 'http://zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&'\
'tz=tz&ll=ll&zip=%s&Go=Go' % zipcode
try:
text = webutils.getUrl(url)
except webutils.WebError, e:
irc.error(str(e))
return
text = webutils.getUrl(url)
if 'daily usage limit' in text:
irc.error('I have exceeded the site\'s daily usage limit.')
return

View File

@ -89,7 +89,7 @@ def getUrlFd(url):
except socket.error, e:
raise WebError, strError(e)
except urllib2.URLError, e:
raise WebError, strError(e)
raise WebError, strError(e.reason[1])
except urllib2.HTTPError, e:
raise WebError, strError(e)