[ python-Bugs-1063229 ] not enough information in SGMLParseError

SourceForge.net noreply at sourceforge.net
Tue Nov 9 17:56:20 CET 2004


Bugs item #1063229, was opened at 2004-11-09 11:54
Message generated for change (Settings changed) made by ezust
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1063229&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Alan Ezust (ezust)
Assigned to: Nobody/Anonymous (nobody)
>Summary: not enough information in SGMLParseError

Initial Comment:
When SGMLParser encounters a badly formed webpage, it
throws sgmllib.SGMLParseError with a cryptic message:

[bin] > python sgmlparsertest.py
Pythonlib's error message: expected name token

I think it should give the line and offset, and maybe
even the text it had problems with, in the args of the
exception. And print it out in the message. 

My extra information: error at line 1 offset 2
<head>
 ^
[bin] 

I tried to print it out by using parser.getpos() but it
returns values which do not correspond to the error.
How do I determine this at runtime?

testcase that reproduces this problem attached.


----------------------------------------------------------------------

Comment By: Alan Ezust (ezust)
Date: 2004-11-09 11:55

Message:
Logged In: YES 
user_id=935841

import sgmllib, urllib, urlparse
from sgmllib import SGMLParser


if __name__ == "__main__":
    url = "http://www.cs.uvic.ca/~gshoja/"
    parser = SGMLParser()
    data = urllib.urlopen(url).read()

    try:
        parser.feed(data)
    except sgmllib.SGMLParseError, ex:
        print "Pythonlib's error message: " + str(ex)
        line, offset = parser.getpos()
        lines = parser.rawdata.split("\n")
        print "My extra information: error at line %d offset
%d" % parser.getpos()
        print lines[line]
        print "%*s" % (offset, "^")
        parser = None 


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1063229&group_id=5470


More information about the Python-bugs-list mailing list