MCPcopy Index your code
hub / github.com/RustPython/RustPython / into_py_err

Method into_py_err

crates/stdlib/src/ssl/compat.rs:550–595  ·  view source on GitHub ↗

Convert to Python exception

(self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

548
549 /// Convert to Python exception
550 pub fn into_py_err(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
551 match self {
552 SslError::WantRead => create_ssl_want_read_error(vm).upcast(),
553 SslError::WantWrite => create_ssl_want_write_error(vm).upcast(),
554 SslError::Timeout(msg) => timeout_error_msg(vm, msg).upcast(),
555 SslError::Syscall(msg) => {
556 // SSLSyscallError with errno=SSL_ERROR_SYSCALL (5)
557 create_ssl_syscall_error(vm, msg).upcast()
558 }
559 SslError::Ssl(msg) => vm
560 .new_os_subtype_error(
561 PySSLError::class(&vm.ctx).to_owned(),
562 None,
563 format!("SSL error: {msg}"),
564 )
565 .upcast(),
566 SslError::ZeroReturn => create_ssl_zero_return_error(vm).upcast(),
567 SslError::Eof => create_ssl_eof_error(vm).upcast(),
568 SslError::PreauthData => {
569 // Non-TLS data received before handshake
570 Self::create_ssl_error_with_reason(
571 vm,
572 None,
573 "before TLS handshake with data",
574 "before TLS handshake with data",
575 )
576 }
577 SslError::CertVerification(cert_err) => {
578 // Use the proper cert verification error creator
579 create_ssl_cert_verification_error(vm, &cert_err).expect("unlikely to happen")
580 }
581 SslError::Io(err) => err.into_pyexception(vm),
582 SslError::SniCallbackRestart => {
583 // This should be handled at PySSLSocket level
584 unreachable!("SniCallbackRestart should not reach Python layer")
585 }
586 SslError::Py(exc) => exc,
587 SslError::AlertReceived { lib, reason } => {
588 Self::create_ssl_error_from_codes(vm, lib, reason)
589 }
590 SslError::NoCipherSuites => {
591 // OpenSSL error: lib=20 (ERR_LIB_SSL), reason=193 (SSL_R_NO_SHARED_CIPHER)
592 Self::create_ssl_error_from_codes(vm, ERR_LIB_SSL, SSL_R_NO_SHARED_CIPHER)
593 }
594 }
595 }
596}
597
598pub type SslResult<T> = Result<T, SslError>;

Callers 3

do_handshakeMethod · 0.80
readMethod · 0.80
writeMethod · 0.80

Calls 11

timeout_error_msgFunction · 0.85
create_ssl_syscall_errorFunction · 0.85
create_ssl_eof_errorFunction · 0.85
upcastMethod · 0.80
new_os_subtype_errorMethod · 0.80
to_ownedMethod · 0.45
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected