29a30,33
> import urllib
> import htmllib
> import formatter
> import signal
32a37,51
> def handler(signum, frame):
>          print 'Signal handler called with signal', signum
>          raise Error, "URL parsing timed out"
> 
> class TitleFoundOrHeadCompleteException: pass
> 
> class TitleParser(htmllib.HTMLParser):
>     def end_title(self):
>         htmllib.HTMLParser.end_title(self)
>         raise TitleFoundOrHeadCompleteException
> 
>     def end_head(self):
>         raise TitleFoundOrHeadCompleteException
> 
> 
550a570,604
>             parser = None
> 
>             # try to access the document and get the header info
>             try:
>                 # Set the signal handler and a 5-second alarm
>                 signal.signal(signal.SIGALRM, handler)
>                 signal.alarm(5)
> 
>                 parser = TitleParser(formatter.NullFormatter(formatter.NullWriter()))
>                 fh = urllib.urlopen(url)
>                 ct = fh.info().getheader('Content-type')
>                 signal.alarm(0)          # Disable the alarm
>             except:
>                 # give up if we couldn't get the header info
>                 signal.alarm(0)          # Disable the alarm
>                 ct = "Inacessible URL"
> 
>             blurb = ''
> 
>             # if we got the header info, try to get the document and auto-title
>             if (ct == 'text/html'):
>                 try:
>                     # Set the signal handler and a 5-second alarm
>                     signal.signal(signal.SIGALRM, handler)
>                     signal.alarm(5)
>                     parser.feed(urllib.urlopen(url).read())
>                     parser.close()
>                     signal.alarm(0)          # Disable the alarm
>                 except TitleFoundOrHeadCompleteException:
>                     signal.alarm(0)          # Disable the alarm
>                     blurb = parser.title
>                 except:
>                     # give up on auto-titling if we couldn't get the document
>                     signal.alarm(0)          # Disable the alarm
> 
552c606,610
<             return label+": "+url+" from "+nick
---
>             if ((blurb == '') or (blurb == None)):
>                 blurb = url
>             else:
>                 self.churn.title_item(label, blurb)
>             return label+": "+blurb+" from "+nick
