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

Method decode_text

crates/vm/src/codecs.rs:342–364  ·  view source on GitHub ↗
(
        &self,
        obj: PyObjectRef,
        encoding: &str,
        errors: Option<PyUtf8StrRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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,

Callers 5

readlineMethod · 0.80
bytes_decodeFunction · 0.80
decode_source_bytesFunction · 0.80
py_newMethod · 0.80
fsdecodeMethod · 0.80

Calls 3

_lookup_text_encodingMethod · 0.80
downcastMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected