File size: 616 Bytes
9776024
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import math, os, json, subprocess
from typing import Any, Dict

def calc(expression: str) -> str:
    try:

        allowed = {k: getattr(math, k) for k in dir(math) if not k.startswith('_')}
        allowed['abs'] = abs
        res = eval(expression, {'__builtins__': {}}, allowed)
        return str(res)
    except Exception as e:
        return f"Calculator error: {e}"

def read_file(path: str, max_chars: int = 4000) -> str:
    try:
        with open(path, 'r', encoding='utf-8', errors='ignore') as f:
            return f.read()[:max_chars]
    except Exception as e:
        return f"File read error: {e}"