forked from Rust-related/RustPython
Use non-env-var methods from openssl_probe
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
builtins::PyStr,
|
||||
convert::{ToPyException, ToPyObject},
|
||||
exceptions::cstring_error,
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -17,22 +18,22 @@ impl ToPyObject for std::convert::Infallible {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToCString {
|
||||
fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<std::ffi::CString>;
|
||||
}
|
||||
|
||||
impl ToCString for &str {
|
||||
fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<std::ffi::CString> {
|
||||
std::ffi::CString::new(*self).map_err(|err| err.to_pyexception(vm))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCString for PyStr {
|
||||
pub trait ToCString: AsRef<str> {
|
||||
fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<std::ffi::CString> {
|
||||
std::ffi::CString::new(self.as_ref()).map_err(|err| err.to_pyexception(vm))
|
||||
}
|
||||
fn ensure_no_nul(&self, vm: &VirtualMachine) -> PyResult<()> {
|
||||
if self.as_ref().as_bytes().contains(&b'\0') {
|
||||
Err(cstring_error(vm))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCString for &str {}
|
||||
impl ToCString for PyStr {}
|
||||
|
||||
pub(crate) fn collection_repr<'a, I>(
|
||||
class_name: Option<&str>,
|
||||
prefix: &str,
|
||||
|
||||
Reference in New Issue
Block a user