MCPcopy Create free account
hub / github.com/EvolvingAgentsLabs/skillos / extract_python_code

Function extract_python_code

benchmarks/benchmark_patch.py:1207–1219  ·  view source on GitHub ↗

Extract a ```python code block from the response.

(response_text: str)

Source from the content-addressed store, hash-verified

1205# ── Code Extraction ─────────────────────────────────────────────────────────
1206
1207def extract_python_code(response_text: str) -> Optional[str]:
1208 """Extract a ```python code block from the response."""
1209 # Try ```python first, then bare ```
1210 match = re.search(r'```python\s*\n(.*?)```', response_text, re.DOTALL)
1211 if not match:
1212 match = re.search(r'```\s*\n(.*?)```', response_text, re.DOTALL)
1213 if match:
1214 return match.group(1).strip()
1215 # If no code fence, assume the whole thing is code
1216 stripped = response_text.strip()
1217 if stripped.startswith(('"""', "import ", "#!/", "from ", "class ", "def ")):
1218 return stripped
1219 return None
1220
1221
1222# ── Strict-Patch Applier ────────────────────────────────────────────────────

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected