| 2219 | } |
| 2220 | |
| 2221 | pub fn fsdecode(&self, s: impl Into<OsString>) -> PyStrRef { |
| 2222 | match s.into().into_string() { |
| 2223 | Ok(s) => self.ctx.new_str(s), |
| 2224 | Err(s) => { |
| 2225 | let bytes = self.ctx.new_bytes(s.into_encoded_bytes()); |
| 2226 | let errors = self.fs_encode_errors().to_owned(); |
| 2227 | let res = self.state.codec_registry.decode_text( |
| 2228 | bytes.into(), |
| 2229 | "utf-8", |
| 2230 | Some(errors), |
| 2231 | self, |
| 2232 | ); |
| 2233 | self.expect_pyresult(res, "fsdecode should be lossless and never fail") |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | pub fn fsencode<'a>(&self, s: &'a Py<PyStr>) -> PyResult<Cow<'a, OsStr>> { |
| 2239 | if cfg!(windows) || s.is_utf8() { |