MCPcopy Create free account
hub / github.com/brokermr810/QuantDinger / _make_safe_import

Function _make_safe_import

backend_api_python/app/utils/safe_exec.py:155–162  ·  view source on GitHub ↗

Create a restricted __import__ that only allows whitelisted modules.

()

Source from the content-addressed store, hash-verified

153
154
155def _make_safe_import():
156 """Create a restricted __import__ that only allows whitelisted modules."""
157 def safe_import(name, *args, **kwargs):
158 ok, err = _is_safe_import_name(name)
159 if ok:
160 return _builtins_mod.__import__(name, *args, **kwargs)
161 raise ImportError(err or f"Import not allowed: {name}")
162 return safe_import
163
164
165def build_safe_builtins(extra_allowed: Optional[Set[str]] = None) -> Dict[str, Any]:

Callers 1

build_safe_builtinsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected