(code, locations, sep=' | ', colmark=('-', '^'), context=5)
return s
Given a code and list of locations, convert to snippet lines.

        return will include line number, a separator (``sep``), then
        line contents.

        At most ``context`` lines are shown before each location line.

        After each location line, the column is marked using
        ``colmark``. The first character is repeated up to column, the
        second character is used only once.

        :return: list of lines of sources or column markups.
        :rtype: list
Given a code and list of locations, convert to snippet lines.
Given a code and list of locations convert to snippet lines .
def snippet(code, locations, sep=' | ', colmark=('-', '^'), context=5):
        '''Given a code and list of locations, convert to snippet lines.

        return will include line number, a separator (``sep``), then
        line contents.

        At most ``context`` lines are shown before each location line.

        After each location line, the column is marked using
        ``colmark``. The first character is repeated up to column, the
        second character is used only once.

        :return: list of lines of sources or column markups.
        :rtype: list
        '''
        if not locations:
            return []
        lines = code.split('\n')
        offset = int(len(lines) / 10) + 1
        linenofmt = '%{}d'.format(offset)
        s = []
        for loc in locations:
            line = max(0, loc.get('line', 1) - 1)
            column = max(0, loc.get('column', 1) - 1)
            start_line = max(0, line - context)
            for i, ln in enumerate(lines[start_line:line + 1], start_line):
                s.append('{}{}{}'.format(linenofmt % i, sep, ln))
            s.append('{}{}{}'.format(' ' * (offset + len(sep)),
                                     colmark[0] * column,
                                     colmark[1]))
        return s
def snippet ( code , locations , sep = ' | ' , colmark = ( '-' , '^' ) , context = 5 ) : if not locations : return [ ] lines = code . split ( '\n' ) offset = int ( len ( lines ) / 10 ) + 1 linenofmt = '%{}d' . format ( offset ) s = [ ] for loc in locations : line = max ( 0 , loc . get ( 'line' , 1 ) - 1 ) column = max ( 0 , loc . get ( 'column' , 1 ) - 1 ) start_line = max ( 0 , line - context ) for i , ln in enumerate ( lines [ start_line : line + 1 ] , start_line ) : s . append ( '{}{}{}' . format ( linenofmt % i , sep , ln ) ) s . append ( '{}{}{}' . format ( ' ' * ( offset + len ( sep ) ) , colmark [ 0 ] * column , colmark [ 1 ] ) ) return s