pylib/uxml/parser.py
def handle_cdata(pos, window, charpat, stopchars):
    '''
    Return (result, new_position) tuple.
    Result is cdata string if possible and None if more input is needed
    Or of course bad syntax can raise a RuntimeError
    '''
    cdata = ''
    cursor = start = pos

    try:
        while True:
            while charpat.match(window[cursor]):
                cursor += 1
            addchars = window[start:cursor]
            cdata += addchars
            #if window[pos] != openattr:
            #    raise RuntimeError('Mismatch in attribute quotes')
            if window[cursor] in stopchars:
                return cdata, cursor
            #Check for charref
            elif window[cursor] == '&':
                start = cursor = cursor + 1
                if window[cursor] == '#' and window[cursor + 1] == 'x':
                    #Numerical charref
                    start = cursor = cursor + 2
                    while True:
                        if HEXCHARENTOK.match(window[cursor]):
                            cursor += 1
                        elif window[cursor] == ';':
                            c = chr(int(window[start:cursor], 16))
                            if not CHARACTER.match(c):
                                raise RuntimeError('Character reference gives an illegal character: {0}'.format('&' + window[start:cursor] + ';'))
                            cdata += c
                            break
                        else:
                            raise RuntimeError('Illegal in character entity: {0}'.format(window[cursor]))
                else:
                    #Named charref
                    while True:
                        if NAMEDCHARENTOK.match(window[cursor]):
                            cursor += 1
                        elif window[cursor] == ';':
                            for cn, c in CHARNAMES:
                                if window[start:cursor] == cn:
                                    cdata += c
                                    #cursor += 1 #Skip ;
                                    break
                            else:
                                raise RuntimeError('Unknown named character reference: {0}'.format(repr(window[start:cursor])))
                            break
                        else:
                            raise RuntimeError('Illegal in character reference: {0} (around {1})'.format(window[cursor]), error_context(window, start, cursor))
            #print(start, cursor, cdata, window[cursor])
            cursor += 1
            start = cursor
    except IndexError:
        return None, cursor
def handle_cdata(pos, window, charpat, stopchars):
    '''
    Return (result, new_position) tuple.
    Result is cdata string if possible and None if more input is needed
    Or of course bad syntax can raise a RuntimeError
    '''
    cdata = ''
    cursor = start = pos

    try:
        while True:
            while charpat.match(window[cursor]):
                cursor += 1
            addchars = window[start:cursor]
            cdata += addchars
            #if window[pos] != openattr:
            #    raise RuntimeError('Mismatch in attribute quotes')
            if window[cursor] in stopchars:
                return cdata, cursor
            #Check for charref
            elif window[cursor] == '&':
                start = cursor = cursor + 1
                if window[cursor] == '#' and window[cursor + 1] == 'x':
                    #Numerical charref
                    start = cursor = cursor + 2
                    while True:
                        if HEXCHARENTOK.match(window[cursor]):
                            cursor += 1
                        elif window[cursor] == ';':
                            c = chr(int(window[start:cursor], 16))
                            if not CHARACTER.match(c):
                                raise RuntimeError('Character reference gives an illegal character: {0}'.format('&' + window[start:cursor] + ';'))
                            cdata += c
                            break
                        else:
                            raise RuntimeError('Illegal in character entity: {0}'.format(window[cursor]))
                else:
                    #Named charref
                    while True:
                        if NAMEDCHARENTOK.match(window[cursor]):
                            cursor += 1
                        elif window[cursor] == ';':
                            for cn, c in CHARNAMES:
                                if window[start:cursor] == cn:
                                    cdata += c
                                    #cursor += 1 #Skip ;
                                    break
                            else:
                                raise RuntimeError('Unknown named character reference: {0}'.format(repr(window[start:cursor])))
                            break
                        else:
                            raise RuntimeError('Illegal in character reference: {0} (around {1})'.format(window[cursor]), error_context(window, start, cursor))
            #print(start, cursor, cdata, window[cursor])
            cursor += 1
            start = cursor
    except IndexError:
        return None, cursor
Return (result, new_position) tuple.
    Result is cdata string if possible and None if more input is needed
    Or of course bad syntax can raise a RuntimeError