(args: FuncArgs, vm: &VirtualMachine)
| 871 | #[pyfunction(name = "__breakpointhook__")] |
| 872 | #[pyfunction] |
| 873 | pub fn breakpointhook(args: FuncArgs, vm: &VirtualMachine) -> PyResult { |
| 874 | let env_var = std::env::var("PYTHONBREAKPOINT") |
| 875 | .and_then(|env_var| { |
| 876 | if env_var.is_empty() { |
| 877 | Err(VarError::NotPresent) |
| 878 | } else { |
| 879 | Ok(env_var) |
| 880 | } |
| 881 | }) |
| 882 | .unwrap_or_else(|_| "pdb.set_trace".to_owned()); |
| 883 | |
| 884 | if env_var.eq("0") { |
| 885 | return Ok(vm.ctx.none()); |
| 886 | }; |
| 887 | |
| 888 | let print_unimportable_module_warn = || { |
| 889 | warn( |
| 890 | vm.ctx.exceptions.runtime_warning, |
| 891 | format!("Ignoring unimportable $PYTHONBREAKPOINT: \"{env_var}\"",), |
| 892 | 0, |
| 893 | vm, |
| 894 | ) |
| 895 | .unwrap(); |
| 896 | Ok(vm.ctx.none()) |
| 897 | }; |
| 898 | |
| 899 | let last = match env_var.rsplit_once('.') { |
| 900 | Some((_, last)) => last, |
| 901 | None if !env_var.is_empty() => env_var.as_str(), |
| 902 | _ => return print_unimportable_module_warn(), |
| 903 | }; |
| 904 | |
| 905 | let (module_path, attr_name) = if last == env_var { |
| 906 | ("builtins", env_var.as_str()) |
| 907 | } else { |
| 908 | (&env_var[..(env_var.len() - last.len() - 1)], last) |
| 909 | }; |
| 910 | |
| 911 | let module = match vm.import(&vm.ctx.new_str(module_path), 0) { |
| 912 | Ok(module) => module, |
| 913 | Err(_) => { |
| 914 | return print_unimportable_module_warn(); |
| 915 | } |
| 916 | }; |
| 917 | |
| 918 | match vm.get_attribute_opt(module, &vm.ctx.new_str(attr_name)) { |
| 919 | Ok(Some(hook)) => hook.as_ref().call(args, vm), |
| 920 | _ => print_unimportable_module_warn(), |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | #[pyfunction] |
| 925 | fn exc_info(vm: &VirtualMachine) -> (PyObjectRef, PyObjectRef, PyObjectRef) { |
nothing calls this directly
no test coverage detected