Go through dotted parts of string and call getattr on whatever is returned.
(
obj: PyObjectRef,
attr: &Py<PyStr>,
vm: &VirtualMachine,
)
| 372 | |
| 373 | // Go through dotted parts of string and call getattr on whatever is returned. |
| 374 | fn get_single_attr( |
| 375 | obj: PyObjectRef, |
| 376 | attr: &Py<PyStr>, |
| 377 | vm: &VirtualMachine, |
| 378 | ) -> PyResult<PyObjectRef> { |
| 379 | let attr_str = attr.as_bytes(); |
| 380 | let parts = attr_str.split(|&b| b == b'.').collect::<Vec<_>>(); |
| 381 | if parts.len() == 1 { |
| 382 | return obj.get_attr(attr, vm); |
| 383 | } |
| 384 | let mut obj = obj; |
| 385 | for part in parts { |
| 386 | let part = Wtf8::from_bytes(part).expect("originally valid WTF-8"); |
| 387 | obj = obj.get_attr(&vm.ctx.new_str(part), vm)?; |
| 388 | } |
| 389 | Ok(obj) |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | impl Constructor for PyAttrGetter { |