Changeset 3253

Show
Ignore:
Timestamp:
07/14/07 04:42:09 (1 year ago)
Author:
ed
Message:

Added the XmlException? class to dException.

Modified xmltodict so that attempting to parse a non-existent file will raise an XmlException? that will give a more intelligent error message than before. Also, attempting to parse a malformed XML file will likewise raise an XmlException? with a similarly informative message.

Trac ticket #1053.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dException.py

    r3054 r3253  
    6767        return self.err_desc + '\nSQL: ' + self.sql 
    6868 
     69class XmlException(dException): 
     70    pass 
  • trunk/dabo/lib/xmltodict.py

    r3054 r3253  
    1313import dabo 
    1414import dabo.lib.DesignerUtils as desUtil 
     15from dabo.dLocalize import _ 
    1516from dabo.lib.utils import resolvePath 
    1617app = dabo.dAppRef 
     
    166167    parser.attsToSkip = attsToSkip 
    167168    isPath = os.path.exists(xml) 
     169    errmsg = "" 
    168170    if eol not in xml and isPath: 
    169171        # argument was a file 
    170         ret = parser.ParseFromFile(xml) 
     172        try: 
     173            ret = parser.ParseFromFile(xml) 
     174        except expat.ExpatError, e: 
     175            errmsg = _("The XML in '%s' is not well-formed and cannot be parsed: %s") % (xml, e) 
    171176    else: 
    172177        # argument must have been raw xml: 
    173         ret = parser.Parse(xml) 
     178        if not xml.strip().startswith("<?xml "): 
     179            # it's a bad file name 
     180            errmsg = _("The file '%s' could not be found") % xml 
     181        else: 
     182            try: 
     183                ret = parser.Parse(xml) 
     184            except expat.ExpatError: 
     185                errmsg = _("An invalid XML string was encountered") 
     186    if errmsg: 
     187        raise dabo.dException.XmlException, errmsg 
    174188    if addCodeFile and isPath: 
    175189        # Get the associated code file, if any