コード例 #1
0
def run_for_test_string():
    print()
    lines = test_string.splitlines()

    for i in range(1,15):
        print(lines[i-1], end="")
        flevel = get_foldlevels(lnum, cur_buffer_num=1, cur_undo_sequence=-1,
                               foldnestmax=20, shiftwidth=4,
                               lines_of_module_docstrings=-1,
                               lines_of_fun_and_class_docstrings=-1,
                               test_buffer=lines)
        print("\t\t#", flevel)
コード例 #2
0
def run_for_test_string():
    """Run on the test string above."""
    print()
    lines = test_string.splitlines()
    flevels = get_foldlevels(
                           shiftwidth=4,
                           lines_of_module_docstrings=-1,
                           lines_of_fun_and_class_docstrings=-1,
                           test_buffer=lines)
    for i in range(0,14):
        print(lines[i], end="")
        print("\t\t#", flevels[i])
コード例 #3
0
def get_fold_list(filename, writefile=""):
    """Return the list of folds for the lines in the file `filename`."""
    # TODO: create a params named tuple to pass in.
    with open(filename, "r") as f:
        test_code = f.read()

    test_code = test_code.splitlines()
    flevels = get_foldlevels(
                           shiftwidth=4,
                           lines_of_module_docstrings=-1,
                           lines_of_fun_and_class_docstrings=-1,
                           test_buffer=test_code)

    if writefile:
        with open(writefile, "w") as f:
            f.writelines(str(fold) + "\n" for fold in flevels)
    return flevels
コード例 #4
0
def print_results_for_file(filename):
    """Run the get_foldlevels calculator on the file and print the results."""
    print()
    print("="*5, filename, "="*19)
    print()

    with open(filename, "r") as f:
        test_code = f.read()

    test_code = test_code.splitlines()

    for lnum in range(1,len(test_code)+1):
        flevel = get_foldlevels(lnum, cur_buffer_num=1, cur_undo_sequence=-1,
                               foldnestmax=20, shiftwidth=4,
                               lines_of_module_docstrings=-1,
                               lines_of_fun_and_class_docstrings=-1,
                               test_buffer=test_code)
        print("{:4}{:3}:".format(lnum-1, flevel), test_code[lnum-1])
コード例 #5
0
def print_results_for_file(filename):
    """Run the get_foldlevels calculator on the file and print the results."""
    print()
    print("="*5, filename, "="*19)
    print()

    with open(filename, "r") as f:
        test_code = f.read()

    test_code = test_code.splitlines()
    flevels = get_foldlevels(
                           shiftwidth=4,
                           lines_of_module_docstrings=-1,
                           lines_of_fun_and_class_docstrings=-1,
                           test_buffer=test_code)

    for lnum in range(len(test_code)):
        print("{:4}{:3}:".format(lnum, flevels[lnum]), test_code[lnum])
コード例 #6
0
def get_fold_list(filename, writefile=""):
    """Return the list of folds for the lines in the file `filename`."""
    # TODO: create a params named tuple to pass in.
    with open(filename, "r") as f:
        test_code = f.read()

    test_code = test_code.splitlines()

    fold_list = []
    for lnum in range(1,len(test_code)+1):
        flevel = get_foldlevels(lnum,
                               cur_buffer_num=1,
                               cur_undo_sequence=-1,
                               foldnestmax=20,
                               shiftwidth=4,
                               lines_of_module_docstrings=-1,
                               lines_of_fun_and_class_docstrings=-1,
                               test_buffer=test_code)
        fold_list.append(flevel)

    if writefile:
        with open(writefile, "w") as f:
            f.writelines(str(fold) + "\n" for fold in fold_list)
    return fold_list