(source, node, *, padded=False)
return ''.join(lines)
Get source code segment of the *source* that generated *node*.

    If some location information (`lineno`, `end_lineno`, `col_offset`,
    or `end_col_offset`) is missing, return None.

    If *padded* is `True`, the first line of a multi-line statement will
    be padded with spaces to match its original position.
Get source code segment of the *source* that generated *node*.
Get source code segment of the * source * that generated * node * .
def get_source_segment(source, node, *, padded=False):
    """Get source code segment of the *source* that generated *node*.

    If some location information (`lineno`, `end_lineno`, `col_offset`,
    or `end_col_offset`) is missing, return None.

    If *padded* is `True`, the first line of a multi-line statement will
    be padded with spaces to match its original position.
    """
    try:
        if node.end_lineno is None or node.end_col_offset is None:
            return None
        lineno = node.lineno - 1
        end_lineno = node.end_lineno - 1
        col_offset = node.col_offset
        end_col_offset = node.end_col_offset
    except AttributeError:
        return None

    lines = _splitlines_no_ff(source)
    if end_lineno == lineno:
        return lines[lineno].encode()[col_offset:end_col_offset].decode()

    if padded:
        padding = _pad_whitespace(lines[lineno].encode()[:col_offset].decode())
    else:
        padding = ''

    first = padding + lines[lineno].encode()[col_offset:].decode()
    last = lines[end_lineno].encode()[:end_col_offset].decode()
    lines = lines[lineno+1:end_lineno]

    lines.insert(0, first)
    lines.append(last)
    return ''.join(lines)
def get_source_segment ( source , node , * , padded = False ) : try : if node . end_lineno is None or node . end_col_offset is None : return None lineno = node . lineno - 1 end_lineno = node . end_lineno - 1 col_offset = node . col_offset end_col_offset = node . end_col_offset except AttributeError : return None lines = _splitlines_no_ff ( source ) if end_lineno == lineno : return lines [ lineno ] . encode ( ) [ col_offset : end_col_offset ] . decode ( ) if padded : padding = _pad_whitespace ( lines [ lineno ] . encode ( ) [ : col_offset ] . decode ( ) ) else : padding = '' first = padding + lines [ lineno ] . encode ( ) [ col_offset : ] . decode ( ) last = lines [ end_lineno ] . encode ( ) [ : end_col_offset ] . decode ( ) lines = lines [ lineno + 1 : end_lineno ] lines . insert ( 0 , first ) lines . append ( last ) return '' . join ( lines )