Download python_lora_dataset_builder/pipeline/static_checks.py from api-relay/sadASDasd: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/api-relay/sadASDasd/resolve/main/python_lora_dataset_builder/pipeline/static_checks.py
- Command line
-
hf download hf://datasets/api-relay/sadASDasd/python_lora_dataset_builder/pipeline/static_checks.py
-
curl -L -o static_checks.py https://huggingface.co/datasets/api-relay/sadASDasd/resolve/main/python_lora_dataset_builder/pipeline/static_checks.py
1.15 kB
| import ast,re | |
| from dataclasses import dataclass | |
| PATS=[re.compile(r"(?i)(api[_-]?key|secret|token|password)\s*[:=]\s*['\"][^'\"]{12,}"),re.compile(r"(?i)-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----")] | |
| class CheckResult: | |
| ast_valid:bool; compile_valid:bool; secret_found:bool; code_too_short:bool; imports:list; error:str|None=None | |
| def inspect_code(code): | |
| secret=any(p.search(code) for p in PATS) | |
| if len(code.strip())<8:return CheckResult(False,False,secret,True,[],"code_too_short") | |
| try: tree=ast.parse(code) | |
| except SyntaxError as e:return CheckResult(False,False,secret,False,[],f"SyntaxError: {e.msg} at line {e.lineno}") | |
| try: compile(code,"<candidate>","exec") | |
| except Exception as e:return CheckResult(True,False,secret,False,[],repr(e)) | |
| imports=[] | |
| for n in ast.walk(tree): | |
| if isinstance(n,ast.Import): imports += [a.name.split(".")[0] for a in n.names] | |
| elif isinstance(n,ast.ImportFrom) and n.module: imports.append(n.module.split(".")[0]) | |
| return CheckResult(True,True,secret,False,sorted(set(imports)),None) | |
| def is_basic_syntax_candidate(imports): return len(imports)==0 | |