(
&self,
obj: PyStrRef,
encoding: &str,
errors: Option<PyUtf8StrRef>,
vm: &VirtualMachine,
)
| 316 | } |
| 317 | |
| 318 | pub fn encode_text( |
| 319 | &self, |
| 320 | obj: PyStrRef, |
| 321 | encoding: &str, |
| 322 | errors: Option<PyUtf8StrRef>, |
| 323 | vm: &VirtualMachine, |
| 324 | ) -> PyResult<PyBytesRef> { |
| 325 | let codec = self._lookup_text_encoding(encoding, "codecs.encode()", vm)?; |
| 326 | codec |
| 327 | .encode(obj.into(), errors, vm) |
| 328 | .inspect_err(|exc| { |
| 329 | Self::add_codec_note(exc, "encoding", encoding, vm); |
| 330 | })? |
| 331 | .downcast() |
| 332 | .map_err(|obj| { |
| 333 | vm.new_type_error(format!( |
| 334 | "'{}' encoder returned '{}' instead of 'bytes'; use codecs.encode() to \ |
| 335 | encode to arbitrary types", |
| 336 | encoding, |
| 337 | obj.class().name(), |
| 338 | )) |
| 339 | }) |
| 340 | } |
| 341 | |
| 342 | pub fn decode_text( |
| 343 | &self, |
no test coverage detected