Example #1
0
def string_chunks(consume_log, *chunks):
    """Iterate the given chunks of a text with logging consumed offsets
    to test laziness of the parser.  If an argument is a list (that consists
    of a string) it's treated as offset tagging.

    """
    size = len(chunks)
    for i, chunk in enumerate(chunks):
        if type(chunk) is list:
            continue
        chunk = text(chunk)
        if size > i + 1 and type(chunks[i + 1]) is list:
            consume_log.append(chunks[i + 1][0])
        if not isinstance(chunk, binary_type):
            # In IronPython str.encode() returns str instead of bytes,
            # and bytes(str, encoding) returns bytes.
            chunk = binary_type(chunk, 'utf-8')
        yield chunk
Example #2
0
def string_chunks(consume_log, *chunks):
    """Iterate the given chunks of a text with logging consumed offsets
    to test laziness of the parser.  If an argument is a list (that consists
    of a string) it's treated as offset tagging.

    """
    size = len(chunks)
    for i, chunk in enumerate(chunks):
        if type(chunk) is list:
            continue
        chunk = text(chunk)
        if size > i + 1 and type(chunks[i + 1]) is list:
            consume_log.append(chunks[i + 1][0])
        if not isinstance(chunk, binary_type):
            # In IronPython str.encode() returns str instead of bytes,
            # and bytes(str, encoding) returns bytes.
            chunk = binary_type(chunk, 'utf-8')
        yield chunk
Example #3
0
def etree_tobyteslist(tree):
    string = tostring(tree)
    if IRON_PYTHON:
        return [binary_type(string, 'utf-8')]
    return [string]
Example #4
0
def etree_tobyteslist(tree):
    string = tostring(tree)
    if IRON_PYTHON:
        return [binary_type(string, 'utf-8')]
    return [string]