MCPcopy
hub / github.com/walter201230/Python / extract_blocks

Function extract_blocks

tools/example_runner.py:23–31  ·  view source on GitHub ↗

返回 (起始行号, 代码内容, 是否 skip) 三元组列表。

(md_path: Path)

Source from the content-addressed store, hash-verified

21
22
23def extract_blocks(md_path: Path) -> list[tuple[int, str, bool]]:
24 """返回 (起始行号, 代码内容, 是否 skip) 三元组列表。"""
25 text = md_path.read_text(encoding="utf-8")
26 blocks: list[tuple[int, str, bool]] = []
27 for m in BLOCK_RE.finditer(text):
28 skip = m.group(1) is not None
29 line_no = text[: m.start()].count("\n") + 1
30 blocks.append((line_no, m.group(2), skip))
31 return blocks
32
33
34def run_block(code: str, timeout: int = 10) -> tuple[bool, str]:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected