Edgewall Software

Changeset 187 for trunk/markup/input.py


Ignore:
Timestamp:
Aug 15, 2006, 12:12:03 PM (17 years ago)
Author:
cmlenz
Message:

Simplifed CoalesceFilter (now a function)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/markup/input.py

    r186 r187  
    113113                    msg += ', in ' + self.filename
    114114                raise ParseError(msg, self.filename, e.lineno, e.offset)
    115         return Stream(_generate()).filter(CoalesceFilter())
     115        return Stream(_generate()).filter(_coalesce)
    116116
    117117    def __iter__(self):
     
    246246                    msg += ', in %s' % self.filename
    247247                raise ParseError(msg, self.filename, e.lineno, e.offset)
    248         return Stream(_generate()).filter(CoalesceFilter())
     248        return Stream(_generate()).filter(_coalesce)
    249249
    250250    def __iter__(self):
     
    308308    return Stream(list(HTMLParser(StringIO(text))))
    309309
    310 
    311 class CoalesceFilter(object):
     310def _coalesce(stream):
    312311    """Coalesces adjacent TEXT events into a single event."""
    313 
    314     def __call__(self, stream, ctxt=None):
    315         textbuf = []
    316         textpos = None
    317         for kind, data, pos in chain(stream, [(None, None, None)]):
    318             if kind is TEXT:
    319                 textbuf.append(data)
    320                 if textpos is None:
    321                     textpos = pos
    322             else:
    323                 if textbuf:
    324                     yield TEXT, u''.join(textbuf), textpos
    325                     del textbuf[:]
    326                     textpos = None
    327                 if kind:
    328                     yield kind, data, pos
     312    textbuf = []
     313    textpos = None
     314    for kind, data, pos in chain(stream, [(None, None, None)]):
     315        if kind is TEXT:
     316            textbuf.append(data)
     317            if textpos is None:
     318                textpos = pos
     319        else:
     320            if textbuf:
     321                yield TEXT, u''.join(textbuf), textpos
     322                del textbuf[:]
     323                textpos = None
     324            if kind:
     325                yield kind, data, pos
Note: See TracChangeset for help on using the changeset viewer.