summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e25d752)
raw | patch | inline | side by side (parent: e25d752)
author | Thomas Jansen <mithi@mithi.net> | |
Sun, 4 Oct 2009 08:55:56 +0000 (10:55 +0200) | ||
committer | Thomas Jansen <mithi@mithi.net> | |
Sun, 4 Oct 2009 08:55:56 +0000 (10:55 +0200) |
Should fix bug #2286. Added exception handling for both calls of the SAX
XML parser. Also removed trailing newlines from the result to keep us from
scrolling down further than the last line.
XML parser. Also removed trailing newlines from the result to keep us from
scrolling down further than the last line.
lyrics/03-leoslyrics.py | patch | blob | history |
index b55f0ec67087d2a0d06131a7943fc31148620c34..2a40f37a8bab6833a60d248652efa4d5eabf0a1f 100755 (executable)
--- a/lyrics/03-leoslyrics.py
+++ b/lyrics/03-leoslyrics.py
# Load lyrics from leoslyrics.com
#
-from sys import argv, exit
+from sys import argv, exit, stderr
from urllib import urlencode, urlopen
from xml.sax import make_parser, SAXException
from xml.sax.handler import ContentHandler
handler = SearchContentHandler()
parser = make_parser()
parser.setContentHandler(handler)
- parser.parse(f)
+ try:
+ parser.parse(f)
+ except SAXException:
+ stderr.write("Failed to parse the search result!\n")
+ exit(1)
return handler.hid
class LyricsContentHandler(ContentHandler):
handler = LyricsContentHandler()
parser = make_parser()
parser.setContentHandler(handler)
- parser.parse(f)
+ try:
+ parser.parse(f)
+ except SAXException:
+ stderr.write("Failed to parse the lyrics!\n")
+ exit(1)
return handler.text
hid = search(argv[1], argv[2])
if hid is None:
exit(69)
-print lyrics(hid).encode('utf-8')
+print lyrics(hid).encode('utf-8').rstrip()