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

Method lookup

crates/vm/src/codecs.rs:244–269  ·  view source on GitHub ↗
(&self, encoding: &str, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

242 }
243
244 pub fn lookup(&self, encoding: &str, vm: &VirtualMachine) -> PyResult<PyCodec> {
245 let encoding = normalize_encoding_name(encoding);
246 let search_path = {
247 let inner = self.inner.read();
248 if let Some(codec) = inner.search_cache.get(encoding.as_ref()) {
249 // hit cache
250 return Ok(codec.clone());
251 }
252 inner.search_path.clone()
253 };
254 let encoding: PyUtf8StrRef = vm.ctx.new_utf8_str(encoding.as_ref());
255 for func in search_path {
256 let res = func.call((encoding.clone(),), vm)?;
257 let res: Option<PyCodec> = res.try_into_value(vm)?;
258 if let Some(codec) = res {
259 let mut inner = self.inner.write();
260 // someone might have raced us to this, so use theirs
261 let codec = inner
262 .search_cache
263 .entry(encoding.as_str().to_owned())
264 .or_insert(codec);
265 return Ok(codec.clone());
266 }
267 }
268 Err(vm.new_lookup_error(format!("unknown encoding: {encoding}")))
269 }
270
271 fn _lookup_text_encoding(
272 &self,

Callers 6

_lookup_text_encodingMethod · 0.45
encodeMethod · 0.45
decodeMethod · 0.45
find_coderMethod · 0.45
lookupFunction · 0.45

Calls 12

normalize_encoding_nameFunction · 0.85
new_utf8_strMethod · 0.80
try_into_valueMethod · 0.80
ErrClass · 0.50
readMethod · 0.45
getMethod · 0.45
as_refMethod · 0.45
cloneMethod · 0.45
callMethod · 0.45
writeMethod · 0.45
to_ownedMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected