Made sure Http.title doesn't read infinitely.

This commit is contained in:
Jeremy Fincher 2003-11-29 02:34:07 +00:00
parent 0b0d10fc82
commit e15d15f794

View File

@ -53,10 +53,13 @@ import callbacks
class FreshmeatException(Exception): class FreshmeatException(Exception):
pass pass
def getPage(url): def getPage(url, size=None):
"""Gets a page. Returns a string that is the page gotten.""" """Gets a page. Returns a string that is the page gotten."""
fd = urllib2.urlopen(url) fd = urllib2.urlopen(url)
text = fd.read() if size is None:
text = fd.read()
else:
text = fd.read(size)
fd.close() fd.close()
return text return text
@ -85,7 +88,7 @@ class Http(callbacks.Privmsg):
if '://' not in url: if '://' not in url:
url = 'http://%s' % url url = 'http://%s' % url
try: try:
text = getPage(url) text = getPage(url, size=4096)
m = self._titleRe.search(text) m = self._titleRe.search(text)
if m is not None: if m is not None:
irc.reply(msg, utils.htmlToText(m.group(1).strip())) irc.reply(msg, utils.htmlToText(m.group(1).strip()))