(&self, encoding: &str, vm: &VirtualMachine)
| 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, |
no test coverage detected