(
&self,
obj: PyObjectRef,
encoding: &str,
errors: Option<PyUtf8StrRef>,
vm: &VirtualMachine,
)
| 340 | } |
| 341 | |
| 342 | pub fn decode_text( |
| 343 | &self, |
| 344 | obj: PyObjectRef, |
| 345 | encoding: &str, |
| 346 | errors: Option<PyUtf8StrRef>, |
| 347 | vm: &VirtualMachine, |
| 348 | ) -> PyResult<PyStrRef> { |
| 349 | let codec = self._lookup_text_encoding(encoding, "codecs.decode()", vm)?; |
| 350 | codec |
| 351 | .decode(obj, errors, vm) |
| 352 | .inspect_err(|exc| { |
| 353 | Self::add_codec_note(exc, "decoding", encoding, vm); |
| 354 | })? |
| 355 | .downcast() |
| 356 | .map_err(|obj| { |
| 357 | vm.new_type_error(format!( |
| 358 | "'{}' decoder returned '{}' instead of 'str'; use codecs.decode() to \ |
| 359 | decode to arbitrary types", |
| 360 | encoding, |
| 361 | obj.class().name(), |
| 362 | )) |
| 363 | }) |
| 364 | } |
| 365 | |
| 366 | fn add_codec_note( |
| 367 | exc: &crate::builtins::PyBaseExceptionRef, |
no test coverage detected