Changeset 196 in tracdarcs


Ignore:
Timestamp:
07/28/10 20:29:28 (19 months ago)
Author:
lele@…
Hash name:
20100728182928-7a6fb-ddd03181113a9599cee3a54b0d10d76fec88486d
Message:

Do the bad chars replacement only on SAX errors and retry once

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tracdarcs/changesparser.py

    r183 r196  
    120120                self.patches.append(patch) 
    121121 
    122     from string import maketrans 
    123     tt = maketrans(BADCHARS, "-"*len(BADCHARS)) 
    124     changes = changes.translate(tt) 
    125  
    126122    handler = SAXHandler() 
    127123    try: 
    128124        parseString(changes, handler) 
    129125    except SAXParseException, e: 
     126        # Retry, after removing badchars from the input 
     127 
    130128        lines = changes.splitlines() 
    131         line = lines[e._linenum-1] 
    132         log.critical("Cannot complete the parse of the XML output due to a SAX Error, " 
    133                      "on the changeset %d: %s", len(handler.patches), e) 
    134         log.warning("%s", line) 
    135129        if e._colnum: 
    136             log.warning('-'*(e._colnum-1)+'^'*5) 
     130            line = lines[e._linenum-1][:e._colnum+35] 
     131            pointer = '\nhere: ' + '-'*(e._colnum-1) + '^'*5 
     132        else: 
     133            line = lines[e._linenum-1][:60] 
     134            pointer = '' 
     135        log.warning("SAX couldn't parse the XML changes stream " 
     136                    "due to an error at line %d on changeset " 
     137                    "%d: %s\ntext: %s%s\n" 
     138                    "Replacing bad characters with a hyphen " 
     139                    "and retrying...", 
     140                    e._linenum, len(handler.patches), e, 
     141                    repr(line)[1:-1], pointer) 
     142 
     143        from string import maketrans 
     144        tt = maketrans(BADCHARS, "-"*len(BADCHARS)) 
     145        changes = changes.translate(tt) 
     146 
     147        handler = SAXHandler() 
     148        try: 
     149            parseString(changes, handler) 
     150        except SAXParseException, e: 
     151            log.critical("Sorry, the substitution didn't help, giving up!") 
     152        else: 
     153            log.warning("... the replacement did the trick, going on!") 
     154 
    137155    return handler.patches 
    138156 
Note: See TracChangeset for help on using the changeset viewer.