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

Method encode_text

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

Source from the content-addressed store, hash-verified

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,

Callers 4

getaddrinfoFunction · 0.80
get_addrFunction · 0.80
encode_stringFunction · 0.80
fsencodeMethod · 0.80

Calls 3

_lookup_text_encodingMethod · 0.80
downcastMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected