(args: Txt2ObjArgs, vm: &VirtualMachine)
| 4771 | |
| 4772 | #[pyfunction] |
| 4773 | fn txt2obj(args: Txt2ObjArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> { |
| 4774 | let txt = args.txt.as_str(); |
| 4775 | let name = args.name.unwrap_or(false); |
| 4776 | |
| 4777 | // If name=False (default), only accept OID strings |
| 4778 | // If name=True, accept both names and OID strings |
| 4779 | let entry = if txt |
| 4780 | .chars() |
| 4781 | .next() |
| 4782 | .map(|c| c.is_ascii_digit()) |
| 4783 | .unwrap_or(false) |
| 4784 | { |
| 4785 | // Looks like an OID string (starts with digit) |
| 4786 | oid::find_by_oid_string(txt) |
| 4787 | } else if name { |
| 4788 | // name=True: allow shortname/longname lookup |
| 4789 | oid::find_by_name(txt) |
| 4790 | } else { |
| 4791 | // name=False: only OID strings allowed, not names |
| 4792 | None |
| 4793 | }; |
| 4794 | |
| 4795 | let entry = entry.ok_or_else(|| vm.new_value_error(format!("unknown object '{txt}'")))?; |
| 4796 | |
| 4797 | // Return tuple: (nid, shortname, longname, oid) |
| 4798 | Ok(vm |
| 4799 | .new_tuple(( |
| 4800 | vm.ctx.new_int(entry.nid), |
| 4801 | vm.ctx.new_str(entry.short_name), |
| 4802 | vm.ctx.new_str(entry.long_name), |
| 4803 | vm.ctx.new_str(entry.oid_string()), |
| 4804 | )) |
| 4805 | .into()) |
| 4806 | } |
| 4807 | |
| 4808 | #[pyfunction] |
| 4809 | fn nid2obj(nid: i32, vm: &VirtualMachine) -> PyResult<PyObjectRef> { |
nothing calls this directly
no test coverage detected