(
source: Either<ArgStrOrBytesLike, PyRef<crate::builtins::PyCode>>,
scope: ScopeArgs,
vm: &VirtualMachine,
)
| 535 | |
| 536 | #[pyfunction] |
| 537 | fn eval( |
| 538 | source: Either<ArgStrOrBytesLike, PyRef<crate::builtins::PyCode>>, |
| 539 | scope: ScopeArgs, |
| 540 | vm: &VirtualMachine, |
| 541 | ) -> PyResult { |
| 542 | let scope = scope.make_scope(vm, "eval")?; |
| 543 | |
| 544 | // source as string |
| 545 | let code = match source { |
| 546 | Either::A(either) => { |
| 547 | let source: &[u8] = &either.borrow_bytes(); |
| 548 | if source.contains(&0) { |
| 549 | return Err(vm.new_exception_msg( |
| 550 | vm.ctx.exceptions.syntax_error.to_owned(), |
| 551 | "source code string cannot contain null bytes".into(), |
| 552 | )); |
| 553 | } |
| 554 | |
| 555 | let source = core::str::from_utf8(source).map_err(|err| { |
| 556 | let msg = format!( |
| 557 | "(unicode error) 'utf-8' codec can't decode byte 0x{:x?} in position {}: invalid start byte", |
| 558 | source[err.valid_up_to()], |
| 559 | err.valid_up_to() |
| 560 | ); |
| 561 | |
| 562 | vm.new_exception_msg(vm.ctx.exceptions.syntax_error.to_owned(), msg.into()) |
| 563 | })?; |
| 564 | Ok(Either::A(vm.ctx.new_utf8_str(source.trim_start()))) |
| 565 | } |
| 566 | Either::B(code) => Ok(Either::B(code)), |
| 567 | }?; |
| 568 | run_code(vm, code, scope, crate::compiler::Mode::Eval, "eval") |
| 569 | } |
| 570 | |
| 571 | #[pyfunction] |
| 572 | fn exec( |
nothing calls this directly
no test coverage detected