/// <summary>
/// Initialization performed on startup of the Python runtime.
/// </summary>
internal static void Initialize()
{
string exceptionsModuleName = Runtime.IsPython3 ? "builtins" : "exceptions";
exceptions_module = Runtime.PyImport_ImportModule(exceptionsModuleName);
Exceptions.ErrorCheck(exceptions_module);
warnings_module = Runtime.PyImport_ImportModule("warnings");
Exceptions.ErrorCheck(warnings_module);
Type type = typeof(Exceptions);
foreach (FieldInfo fi in type.GetFields(BindingFlags.Public | BindingFlags.Static))
{
IntPtr op = Runtime.PyObject_GetAttrString(exceptions_module, fi.Name);
if (op != IntPtr.Zero)
{
fi.SetValue(type, op);
}
else
{
fi.SetValue(type, IntPtr.Zero);
DebugUtil.Print($"Unknown exception: {fi.Name}");
}
}
Runtime.PyErr_Clear();
}