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

Method fsencode

crates/vm/src/vm/mod.rs:2238–2255  ·  view source on GitHub ↗
(&self, s: &'a Py<PyStr>)

Source from the content-addressed store, hash-verified

2236 }
2237
2238 pub fn fsencode<'a>(&self, s: &'a Py<PyStr>) -> PyResult<Cow<'a, OsStr>> {
2239 if cfg!(windows) || s.is_utf8() {
2240 // XXX: this is sketchy on windows; it's not guaranteed that the
2241 // OsStr encoding will always be compatible with WTF-8.
2242 let s = unsafe { OsStr::from_encoded_bytes_unchecked(s.as_bytes()) };
2243 return Ok(Cow::Borrowed(s));
2244 }
2245 let errors = self.fs_encode_errors().to_owned();
2246 let bytes = self
2247 .state
2248 .codec_registry
2249 .encode_text(s.to_owned(), "utf-8", Some(errors), self)?
2250 .to_vec();
2251 // XXX: this is sketchy on windows; it's not guaranteed that the
2252 // OsStr encoding will always be compatible with WTF-8.
2253 let s = unsafe { OsString::from_encoded_bytes_unchecked(bytes) };
2254 Ok(Cow::Owned(s))
2255 }
2256}
2257
2258impl AsRef<Context> for VirtualMachine {

Callers 15

whichFunction · 0.80
normcaseFunction · 0.80
expanduserFunction · 0.80
replFunction · 0.80
_execute_childMethod · 0.80
_sanitize_paramsFunction · 0.80
gettempprefixbFunction · 0.80
gettempdirbFunction · 0.80
expanduserFunction · 0.80
replFunction · 0.80
_arp_getnodeFunction · 0.80
__bytes__Method · 0.80

Calls 9

BorrowedClass · 0.85
OwnedClass · 0.85
fs_encode_errorsMethod · 0.80
to_vecMethod · 0.80
encode_textMethod · 0.80
SomeClass · 0.50
is_utf8Method · 0.45
as_bytesMethod · 0.45
to_ownedMethod · 0.45