PERDYPTO
Upload 45 files
0109502 verified
Raw History Blame Contribute Delete
449 Bytes
import re
def _norm(x): return "\n".join(line.rstrip() for line in x.replace("\r\n","\n").splitlines()).strip()
def extract_code(output):
blocks=[_norm(x) for x in re.findall(r"```(?:python|py)?\s*\n?(.*?)```",output or "",re.I|re.S) if _norm(x)]
if blocks: return max(blocks,key=len)
text=_norm(output or "")
return text if any(x in text for x in ("def ","class ","import ","from ","for ","while ","if ","try:","async ")) else None