Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
148 lines (130 loc) · 4.82 KB
/
Copy patherror.rs
File metadata and controls
148 lines (130 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SSL exception types shared between ssl (rustls) and openssl backends
pub(crate) use ssl_error::*;
#[pymodule(sub, name = "_ssl")]
pub(crate) mod ssl_error {
use crate::vm::{
Py, PyPayload, PyRef, PyResult, VirtualMachine,
builtins::{PyBaseException, PyOSError, PyStrRef},
types::Constructor,
};
#[pyattr]
pub(crate) use rustpython_host_env::ssl::{
SSL_ERROR_EOF, SSL_ERROR_INVALID_ERROR_CODE, SSL_ERROR_NONE, SSL_ERROR_SSL,
SSL_ERROR_SYSCALL, SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE,
SSL_ERROR_WANT_X509_LOOKUP, SSL_ERROR_ZERO_RETURN,
};
#[pyattr]
#[pyexception(name = "SSLError", module = "ssl", base = PyOSError)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLError(PyOSError);
#[pyexception]
impl PySSLError {
// Returns strerror attribute if available, otherwise str(args)
#[pymethod]
fn __str__(zelf: &Py<PyBaseException>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
use crate::vm::AsObject;
// Try to get strerror attribute first (OSError compatibility)
if let Ok(strerror) = zelf.as_object().get_attr("strerror", vm)
&& !vm.is_none(&strerror)
{
return strerror.str(vm);
}
// Otherwise return str(args)
let args = zelf.args();
if args.as_slice().len() == 1 {
args.as_slice()[0].str(vm)
} else {
args.as_object().str(vm)
}
}
}
#[pyattr]
#[pyexception(name = "SSLZeroReturnError", module = "ssl", base = PySSLError)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLZeroReturnError(PySSLError);
#[pyexception]
impl PySSLZeroReturnError {}
#[pyattr]
#[pyexception(name = "SSLWantReadError", module = "ssl", base = PySSLError, impl)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLWantReadError(PySSLError);
#[pyattr]
#[pyexception(name = "SSLWantWriteError", module = "ssl", base = PySSLError, impl)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLWantWriteError(PySSLError);
#[pyattr]
#[pyexception(name = "SSLSyscallError", module = "ssl", base = PySSLError, impl)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLSyscallError(PySSLError);
#[pyattr]
#[pyexception(name = "SSLEOFError", module = "ssl", base = PySSLError, impl)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLEOFError(PySSLError);
#[pyattr]
#[pyexception(name = "SSLCertVerificationError", module = "ssl", base = PySSLError, impl)]
#[derive(Debug)]
#[repr(transparent)]
pub(crate) struct PySSLCertVerificationError(PySSLError);
// Helper functions to create SSL exceptions with proper errno attribute
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
pub(crate) fn create_ssl_want_read_error(vm: &VirtualMachine) -> PyRef<PyOSError> {
vm.new_os_subtype_error(
PySSLWantReadError::class(&vm.ctx).to_owned(),
Some(SSL_ERROR_WANT_READ),
"The operation did not complete (read)",
)
}
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
pub(crate) fn create_ssl_want_write_error(vm: &VirtualMachine) -> PyRef<PyOSError> {
vm.new_os_subtype_error(
PySSLWantWriteError::class(&vm.ctx).to_owned(),
Some(SSL_ERROR_WANT_WRITE),
"The operation did not complete (write)",
)
}
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
pub(crate) fn create_ssl_eof_error(vm: &VirtualMachine) -> PyRef<PyOSError> {
vm.new_os_subtype_error(
PySSLEOFError::class(&vm.ctx).to_owned(),
Some(SSL_ERROR_EOF),
"EOF occurred in violation of protocol",
)
}
#[cfg_attr(
any(
target_arch = "wasm32",
all(feature = "ssl-openssl", not(feature = "ssl-rustls"))
),
expect(dead_code)
)]
pub(crate) fn create_ssl_zero_return_error(vm: &VirtualMachine) -> PyRef<PyOSError> {
vm.new_os_subtype_error(
PySSLZeroReturnError::class(&vm.ctx).to_owned(),
Some(SSL_ERROR_ZERO_RETURN),
"TLS/SSL connection has been closed (EOF)",
)
}
#[cfg_attr(
any(
target_arch = "wasm32",
all(feature = "ssl-openssl", not(feature = "ssl-rustls"))
),
expect(dead_code)
)]
pub(crate) fn create_ssl_syscall_error(
vm: &VirtualMachine,
msg: impl Into<String>,
) -> PyRef<PyOSError> {
vm.new_os_subtype_error(
PySSLSyscallError::class(&vm.ctx).to_owned(),
Some(SSL_ERROR_SYSCALL),
msg.into(),
)
}
}