Beispiel #1
0
def find_error_locations(source):
    error_locations = []

    def replacement(match):
        last_offset = error_locations[-1][2] if error_locations else 0
        new_offset = last_offset + match.end() - match.start()
        error_locations.append((
            match.start() - last_offset, match.group(1), new_offset))
        return ''

    source = _code_pattern.sub(replacement, source)
    lines = Lines(source.splitlines(True))
    return source, [
        lines.position_of_byte(b) + (code,) for b, code, _ in error_locations]
Beispiel #2
0
def find_error_locations(source):
    # Strip trailing spaces, since the most comfortable triple-quoted
    # string format will have extra spaces on the last line. If this isn't
    # removed, it'll throw off the trailing newline checker.
    source = source.rstrip(" ")
    error_locations = []

    def replacement(match):
        last_offset = error_locations[-1][2] if error_locations else 0
        new_offset = last_offset + match.end() - match.start()
        error_locations.append((match.start() - last_offset, match.group(1), new_offset))
        return ""

    source = _code_pattern.sub(replacement, source)
    lines = Lines(source.splitlines(True))
    return source, [lines.position_of_byte(b) + (code,) for b, code, _ in error_locations]
Beispiel #3
0
def find_error_locations(source):
    # Strip trailing spaces, since the most comfortable triple-quoted
    # string format will have extra spaces on the last line. If this isn't
    # removed, it'll throw off the trailing newline checker.
    source = source.rstrip(' ')
    error_locations = []

    def replacement(match):
        last_offset = error_locations[-1][2] if error_locations else 0
        new_offset = last_offset + match.end() - match.start()
        error_locations.append((
            match.start() - last_offset, match.group(1), new_offset))
        return ''

    source = _code_pattern.sub(replacement, source)
    lines = Lines(source.splitlines(True))
    return source, [
        lines.position_of_byte(b) + (code,) for b, code, _ in error_locations]