コード例 #1
0
ファイル: lab_black.py プロジェクト: Kitsunetic/nb_black
        def transform(self, lines):
            # https://github.com/ipython/ipython/blob/1879ed27bb0ec3be5fee499ac177ad14a9ef7cfd/IPython/core/inputtransformer2.py#L382
            """Transform an escaped line found by the ``find()`` classmethod."""
            start_line, start_col = self.start_line, self.start_col

            indent = lines[start_line][:start_col]
            end_line = find_end_of_continued_line(lines, start_line)
            line = assemble_continued_line(lines, (start_line, start_col),
                                           end_line)

            if len(line) > 1 and line[:2] in ESCAPE_DOUBLES:
                escape, content = line[:2], line[2:]
            else:
                escape, content = line[:1], line[1:]

            if escape in tr:
                hidden_variables.append(line)
                call = __BF_SIGNATURE__.format(len(hidden_variables) - 1)
            else:
                call = ""

            lines_before = lines[:start_line]
            new_line = indent + call + "\n"
            lines_after = lines[end_line + 1:]

            return lines_before + [new_line] + lines_after
コード例 #2
0
ファイル: lab_black.py プロジェクト: Kitsunetic/nb_black
        def transform(self, lines):
            # https://github.com/ipython/ipython/blob/1879ed27bb0ec3be5fee499ac177ad14a9ef7cfd/IPython/core/inputtransformer2.py#L223
            """Transform a magic assignment found by the ``find()`` classmethod."""
            start_line, start_col = self.start_line, self.start_col
            lhs = lines[start_line][:start_col]
            end_line = find_end_of_continued_line(lines, start_line)
            rhs = assemble_continued_line(lines, (start_line, start_col),
                                          end_line)
            assert rhs.startswith("%"), rhs
            magic_name, _, args = rhs[1:].partition(" ")

            lines_before = lines[:start_line]
            hidden_variables.append(rhs)
            call = __BF_SIGNATURE__.format(len(hidden_variables) - 1)
            new_line = lhs + call + "\n"
            lines_after = lines[end_line + 1:]

            return lines_before + [new_line] + lines_after
コード例 #3
0
def test_continued_line():
    lines = MULTILINE_MAGIC_ASSIGN[0]
    nt.assert_equal(ipt2.find_end_of_continued_line(lines, 1), 2)

    nt.assert_equal(ipt2.assemble_continued_line(lines, (1, 5), 2),
                    "foo    bar")
コード例 #4
0
def test_continued_line():
    lines = MULTILINE_MAGIC_ASSIGN[0]
    nt.assert_equal(ipt2.find_end_of_continued_line(lines, 1), 2)

    nt.assert_equal(ipt2.assemble_continued_line(lines, (1, 5), 2), "foo    bar")
コード例 #5
0
def test_continued_line():
    lines = MULTILINE_MAGIC_ASSIGN[0]
    assert ipt2.find_end_of_continued_line(lines, 1) == 2

    assert ipt2.assemble_continued_line(lines, (1, 5), 2) == "foo    bar"