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

Method parse_password_argument

crates/stdlib/src/ssl.rs:2008–2038  ·  view source on GitHub ↗

Parse password argument (str, bytes-like, or callable) Returns (immediate_password, callable) where: - immediate_password: Some(string) if password is str/bytes, None if callable - callable: Some(PyObjectRef) if password is callable, None otherwise

(
            password: &OptionalArg<PyObjectRef>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

2006 /// - immediate_password: Some(string) if password is str/bytes, None if callable
2007 /// - callable: Some(PyObjectRef) if password is callable, None otherwise
2008 fn parse_password_argument(
2009 password: &OptionalArg<PyObjectRef>,
2010 vm: &VirtualMachine,
2011 ) -> PyResult<(Option<String>, Option<PyObjectRef>)> {
2012 match password {
2013 OptionalArg::Present(p) => {
2014 if vm.is_none(p) {
2015 return Ok((None, None));
2016 }
2017
2018 // Try string
2019 if let Ok(pwd_str) = PyUtf8StrRef::try_from_object(vm, p.clone()) {
2020 Ok((Some(pwd_str.as_str().to_owned()), None))
2021 }
2022 // Try bytes-like
2023 else if let Ok(pwd_bytes_like) = ArgBytesLike::try_from_object(vm, p.clone())
2024 {
2025 let pwd = String::from_utf8(pwd_bytes_like.borrow_buf().to_vec())
2026 .map_err(|_| vm.new_type_error("password bytes must be valid UTF-8"))?;
2027 Ok((Some(pwd), None))
2028 }
2029 // Try callable
2030 else if p.is_callable() {
2031 Ok((None, Some(p.clone())))
2032 } else {
2033 Err(vm.new_type_error("password should be a string or callable"))
2034 }
2035 }
2036 _ => Ok((None, None)),
2037 }
2038 }
2039
2040 /// Helper: Load certificates from file into existing store
2041 fn load_certs_from_file_helper(

Callers

nothing calls this directly

Calls 9

to_vecMethod · 0.80
is_callableMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
is_noneMethod · 0.45
cloneMethod · 0.45
to_ownedMethod · 0.45
as_strMethod · 0.45
borrow_bufMethod · 0.45

Tested by

no test coverage detected